实验环境:
虚拟机:VMWare
Ubuntu:18.04(需要安装桌面),作为服务端
服务端系统:ubuntu-18.04.5-desktop-amd64.iso
服务端 I P :192.168.138.10
客户端系统:ubuntu-18.04-server-amd64.iso
配置PXE服务端准备:
sudo apt-get update #首先升级
sudo apt-get install net-tools #安装工具包
sudo apt-get install vim #安装vim
sudo apt-get install openssh-server #安装ssh工具
①首先,打开“/etc/ssh/sshd_config”设置允许root用户登陆
vim /etc/ssh/sshd_config
②看是否有“PermitRootLogin yes”,没有添加即可,完成后保存退出
1.安装DHCP,TFTP,HTTP服务
sudo apt-get install -y isc-dhcp-server tftpd-hpa apache2 system-config-kickstart
#或分开执行命令
sudo apt-get install isc-dhcp-server -y
sudo apt-get install tftpd-hpa -y
sudo apt-get install apache2 -y
sudo apt-get install system-config-kickstart -y
#安装完之后,重启一下进入桌面 打开终端执行system-config-kickstart
#如果提示E: 无法定位软件包 isc-dhcp-Server,tftpd-hpa,apache2,再次执行命令sudo apt-get update
2.配置静态IP
vim /etc/network/interfaces
auto lo
iface lo inet loopback
auto ens33
iface ens33 inet static
address 192.168.138.10
netmask 255.255.255.0
gateway 192.168.138.1
systemctl restart networking #重启网络
3.设置dns
vim /etc/systemd/resolved.conf
把DNS取消注释,添加DNS,保存退出,重启即可.
4.配置DHCP服务(主要是两个文件)
①在isc-dhcp-server中指定dhcp的网络接口名字
sudo vim /etc/default/isc-dhcp-server
INTERFACESv4="ens33" # 指定的网络接口名字
INTERFACESv6="ens33"
②在dhcpd.conf中指定
sudo vim /etc/dhcp/dhcpd.conf #编辑文件设置这样
ddns-update-style none;
subnet 192.168.138.0 netmask 255.255.255.0 {
range dynamic-bootp 192.168.138.20 192.168.138.240;
option domain-name-servers 114.114.114.114;
option routers 192.168.138.1;
option subnet-mask 255.255.255.0;
default-lease-time 21600;
max-lease-time 43200;
next-server 192.168.138.10;
filename "pxelinux.0";
}
systemctl restart isc-dhcp-server #重启dhcp服务
systemctl enable isc-dhcp-server #设置为开机自启动
systemctl status isc-dhcp-server #查看dhcp服务的状态
5.配置TFTP服务
vim /etc/default/tftpd-hpa #使用默认配置即可
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"
systemctl restart tftpd-hpa #重启tftp服务
systemctl enable tftpd-hpa #tftp服务设置为开机自启动
systemctl status tftpd-hpa #查看tftp服务
6.配置apache2 #也是安装完就可以了,http根目录是 /var/www/html/
systemctl restart apache2 #重启http服务
systemctl enable apache2 #http服务设置为开机自启动务
systemctl status apache2 #查看http服务
7.拷贝及修改所需文件
#新建ubuntu文件夹
mkdir /var/www/html/ubuntu
#删除apache默认页
rm -fr /var/www/html/index.html
#挂载本地上传镜像/目录下的18.04到mnt文件夹下
mount -o loop /ubuntu-18.04-server-amd64.iso /mnt
#自动开机挂载 进入vim /etc/fstab最后一行加入
/ubuntu-18.04-server-amd64.iso /mnt iso9660 loop,defaults 0 0
#复制mnt 挂载内容到 /var/www/html/ubuntu/文件夹下
cp -r /mnt/* /var/www/html/ubuntu/
#复制netboot/*文件夹所有内容到/var/lib/tftpboot/文件夹下
cp -r /var/www/html/ubuntu/install/netboot/* /var/lib/tftpboot/
#复制ubuntu-server.seed文件到/var/www/html/ 文件夹下
cp /var/www/html/ubuntu/preseed/ubuntu-server.seed /var/www/html/
#编辑ubuntu-server.seed文件最后添加一行
vim /var/www/html/ubuntu-server.seed
live-installer/net-image=http://192.168.138.10/ubuntu/install/filesystem.squashfs
8.配置ks文件
打开终端执行system-config-kickstart 配置ks文件
cp ks.cfg /var/www/html/
vim /var/www/html/ks.cfg #添加安装的软件包
skipx #下面添加需要安装的软件包
%packages
openssh-server
net-tools
vim
9.编辑txt.cfg
vim /var/lib/tftpboot/ubuntu-installer/amd64/boot-screens/txt.cfg
default install
label install
menu label ^Install
menu default
kernel ubuntu-installer/amd64/linux
append ks=http://192.168.138.10/ks.cfg vga=788 initrd=ubuntu-installer/amd64/initrd.gz live-installer/net-image=http://192.168.138.10/ubuntu/install/filesystem.squashfs clock-setup/ntp=false ip=dhcp ksdevice=bootif -- quit
label cli
menu label ^Command-line install
kernel ubuntu-installer/amd64/linux
append tasks=standard pkgsel/language-pack-patterns= pkgsel/install-language-support=false vga=788 initrd=ubuntu-installer/amd64/initrd.gz --- quiet
10.编辑文件default
vim /var/lib/tftpboot/pxelinux.cfg/default
# D-I config version 2.0
# search path for the c32 support libraries (libcom32, libutil etc.)
path ubuntu-installer/amd64/boot-screens/
include ubuntu-installer/amd64/boot-screens/menu.cfg
default ubuntu-installer/amd64/boot-screens/vesamenu.c32
prompt 0
timeout 10 #默认是0(手动),改为10(1秒后自动选择install选项)
接下来就可以pxe安装系统了。
附属ks.cfg
#Generated by Kickstart Configurator
#platform=AMD64 or Intel EM64T
#System language
lang en_US
#Language modules to install
langsupport en_US
#System keyboard
keyboard us
#System mouse
mouse
#System timezone
timezone --utc Asia/Shanghai
#Root password
rootpw --disabled
#Initial user
user admin1 --fullname "admin1" --iscrypted --password $1$usC0yzGL$v6CHlqvuQaCXppPTaAW090
#Reboot after installation
reboot
#Use text mode install
text
#Install OS instead of upgrade
install
#Use Web installation
url --url http://192.168.138.10/ubuntu
#System bootloader configuration
bootloader --location=mbr
#Clear the Master Boot Record
zerombr yes
#Partition clearing information
clearpart --all --initlabel --drives=sda
#Disk partitioning information
ignoredisk --only-use=sda
bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
part /boot --fstype ext4 --size 200 --asprimary
part swap --size 2048 --asprimary
part pv.01 --size 1 --grow --asprimary
volgroup rootvg pv.01
logvol / --fstype ext4 --vgname=rootvg --size=1 --grow --name=rootlv
#part /boot --fstype ext4 --size 200 --asprimary --ondisk sda
#part swap --size 2048 --ondisk sda
#part / --fstype ext4 --size 1 --grow --asprimary --ondisk sda
#System authorization infomation
auth --useshadow --enablemd5
#Network information
network --bootproto=dhcp --device=eth0
#Firewall configuration
firewall --disabled
#Do not configure the X Window System
skipx
%packages
openssh-server
net-tools
vim