環境:
IP: 172.16.0.11 centos 7.2
一. tftp
安裝tftp服務端和客戶端 [root@localhost ~]# yum -y install tftp tftp-server 啟動tftp [root@localhost ~]# systemctl start tftp.socket [root@localhost ~]# systemctl enable tftp.socket [root@localhost ~]# ss -unl | grep :69 UNCONN 0 0 :::69 :::* 在tftp工作目錄下準備一個文件,進行測試 [root@localhost ~]# ls /var/lib/tftpboot/ [root@localhost ~]# cp /etc/grub2.cfg /var/lib/tftpboot/ 先切換到本地/tmp目錄, 因為tftp不支持lcd命令 [root@localhost ~]# cd /tmp 下載grub2.cfg文件 [root@localhost tmp]# tftp 172.16.0.11 tftp> get grub2.cfg tftp> quit 查看本地目錄: [root@localhost tmp]# ls fstab grub2.cfg nginx.conf 刪除測試文件 [root@localhost tmp]# rm /var/lib/tftpboot/grub2.cfg
二. dhcp
[root@localhost tmp]# cd /etc/dhcp [root@localhost dhcp]# vim dhcpd.conf 注釋掉host配置項 #host hostname { #名稱標識 和客戶端hostname可以不同 # hardware ethernet 00:0c:29:f9:98:20; #客戶端mac # fixed-address 172.16.100.10; #給上面的mac固定ip地址 #} option domain-name "magedu.com"; #搜索后綴 option routers 172.16.0.254; #網關, 配置成實際的網關 option domain-name-servers 202.106.0.20; #dns地址 subnet 172.16.0.0 netmask 255.255.0.0 { #子網 range 172.16.100.101 172.16.100.130; #地址池 filename "pxelinux.0"; next-server 172.16.0.11; } [root@localhost dhcp]# systemctl restart dhcpd.service [root@localhost dhcp]# ss -unl | grep :67 UNCONN 0 0 *:67 *:*
三. yum 倉庫
使用光盤做yum倉庫, 最好拷貝到某個目錄,而不是直接掛載光盤, 此處直接掛載 [root@localhost dhcp]# mkdir -pv /var/www/html/centos/7/x86_64 [root@localhost dhcp]# mount -r /dev/cdrom /var/www/html/centos/7/x86_64 [root@localhost dhcp]# ls /var/www/html/centos/7/x86_64/ CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7 EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL [root@localhost dhcp]# systemctl start httpd.service
四. kickstart
制作kickstart文件
[root@localhost ~]# ksvalidator centos7.cfg [root@localhost dhcp]# mkdir /var/www/html/kickstarts [root@localhost dhcp]# vim /var/www/html/kickstarts/centos7.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts # old format: keyboard us # new format: keyboard --vckeymap=us --xlayouts='us' # Root password rootpw --iscrypted $1$hgfvQffN$tXNj5mQldgQt4ziW1QhNF0 # Use network installation url --url="http://172.16.0.11/centos/7/x86_64" # System language lang en_US # Firewall configuration firewall --disabled # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical # Run the Setup Agent on first boot firstboot --enable # SELinux configuration selinux --disabled # Do not configure the X Window System skipx # System services services --disabled="chronyd" ignoredisk --only-use=sda # Network information network --bootproto=dhcp --device=eno16777984 # Reboot after installation reboot # System timezone timezone Asia/Shanghai --ntpservers=3.centos.pool.ntp.org,0.centos.pool.ntp.org,2.centos.pool.ntp.org,1.centos.pool.ntp.org # System bootloader configuration bootloader --location=mbr --boot-drive=sda # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part /boot --asprimary --fstype="xfs" --size=1000 part swap --fstype="swap" --size=8000 part / --fstype="xfs" --grow --size=1 %packages @^minimal @core %end
五. pxeliunx
配置yum倉庫, 使用公網yum倉庫亦可 [root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra baseurl=file:///var/www/html/centos/7/x86_64/ gpgcheck=0 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 [root@localhost Packages]# yum -y install syslinux [root@localhost Packages]# rpm -ql syslinux | grep "pxelinux.0" /usr/share/syslinux/gpxelinux.0 /usr/share/syslinux/pxelinux.0 拷貝pxelinux到tftp工作目錄 [root@localhost Packages]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ 拷貝內核和initrd文件 [root@localhost ~]# cp /var/www/html/centos/7/x86_64/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/ 準備字符界面需要的文件 [root@localhost ~]# cp /usr/share/syslinux/{chain.c32,menu.c32,memdisk,mboot.c32} /var/lib/tftpboot/ 準備引導界面目錄 [root@localhost tftpboot]# cd [root@localhost ~]# cd /var/lib/tftpboot/ [root@localhost tftpboot]# ls chain.c32 initrd.img mboot.c32 memdisk menu.c32 pxelinux.0 vmlinuz [root@localhost tftpboot]# mkdir pxelinux.cfg [root@localhost tftpboot]# cd pxelinux.cfg/ [root@localhost pxelinux.cfg]# vim default default menu.c32 prompt 5 timeout 30 MENU TITLE CentOS 7 PXE Menu LABEL linux MENU LABEL Install CentOS 7 x86_64 KERNEL vmlinuz APPEND initrd=initrd.img inst.repo=http://172.16.0.11/centos/7/x86_64 LABEL linux_autoinst MENU LABEL Install CentOS 7 x86_64 auto KERNEL vmlinuz APPEND initrd=initrd.img inst.repo=http://172.16.0.11/centos/7/x86_64 ks=http://172.16.0 .11/kickstarts/centos7.cfg 啟動httpd服務(之前啟動過,此處應不需要重啟) [root@localhost pxelinux.cfg]# systemctl start httpd.service
六. 驗證
創建虛擬機并啟動
注意: 此處網關設置得不太合理, 并不是pxe服務器作為網關,導致無法上網, 簽名配置文件中已改成正確的網關
問題: yum -y install syslinux時,報Error downloading packages:
syslinux-4.05-13.el7.x86_64: [Errno 256] No more mirrors to try.
解決方法:
[root@localhost Packages]# rm -fr /var/cache/yum/* [root@localhost Packages]# yum clean all
原創文章,作者:hansj,如若轉載,請注明出處:http://www.www58058.com/77410