PXE网络安装CentOS 7.1,安装环境:
先安装一台桌面版CentOS(使用CentOS-7-x86_64-DVD-1503-01.iso安装),作为启动服务器,ip为192.168.72.32。
#安装http、tftp、dhcp服务 yum install httpd tftp-server dhcp #安装syslinux,安装后才有文件 /usr/share/syslinux/pxelinux.0 yum install syslinux #安装system-config-kickstart配置启动文件, yum install system-config-kickstart
#DHCP配置 cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
DHCP配置文件修改
# cat /etc/dhcp/dhcpd.conf # dhcpd.conf # # Sample configuration file for ISC dhcpd # # option definitions common to all supported networks... #domain-name 修改为对应名称 option domain-name "localhost"; option domain-name-servers 223.5.5.5, 223.6.6.6; default-lease-time 600; max-lease-time 7200; # Use this to enble / disable dynamic dns updates globally. #ddns-update-style none; # If this DHCP server is the official DHCP server for the local # network, the authoritative directive should be uncommented. #authoritative; # Use this to send dhcp log messages to a different log file (you also # have to hack syslog.conf to complete the redirection). log-facility local7; # No service will be given on this subnet, but declaring it helps the # DHCP server to understand the network topology. subnet 192.168.72.0 netmask 255.255.255.0 { range 192.168.72.243 192.168.72.250; option routers 192.168.72.1; next-server 192.168.72.32; #TFTP服务器IP filename "pxelinux.0"; }
#tftp配置,disable = no
# cat /etc/xinetd.d/tftp # default: off # description: The tftp server serves files using the trivial file transfer \ # protocol. The tftp protocol is often used to boot diskless \ # workstations, download configuration files to network-aware printers, \ # and to start the installation process for some operating systems. service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot disable = no #修改 per_source = 11 cps = 100 2 flags = IPv4 }
httpd配置
cd /etc/httpd/conf.d/ #移除并备份conf文件,目的不显示测试页面 mv autoindex.conf autoindex.conf.bak mv userdir.conf userdir.conf.bak mv welcome.conf welcome.conf.bak #http目录文件准备 mkdir /var/www/html/centos mount ~/CentOS-7-x86_64-DVD-1503-01.iso /var/www/html/centos
/var/www/html/ks.cfg 文件配置
# cat /var/www/html/ks.cfg #platform=x86, AMD64, or Intel EM64T #version=DEVEL # Install OS instead of upgrade install # Keyboard layouts keyboard 'us'# Reboot after installation reboot # Root password rootpw --iscrypted $1$BhbE2ZLC$D/XPM6Jscst055R3X0nLp. # System timezone timezone Asia/Shanghai --isUtc # Use network installation url --url="http://192.168.72.32/centos" #最后面不需要加 / # System language lang en_US # Firewall configuration firewall --disabled # Network information network --bootproto=dhcp --device=ens0 --onboot=yes --noipv6 --hostname=pxe_one # System authorization information auth --useshadow --passalgo=sha512 # Use graphical install graphical firstboot --disable # SELinux configuration selinux --disabled # System bootloader configuration # 新硬盘需要创建mbr bootloader --location=mbr # Clear the Master Boot Record zerombr # Partition clearing information clearpart --all --initlabel # Disk partitioning information part / --asprimary --fstype="xfs" --size=20480 part /boot --asprimary --fstype="xfs" --size=512 part swap --asprimary --fstype="swap" --size=2048 part /data --asprimary --fstype="xfs" --grow --size=1 %packages @core #@chinese-support #iptraf #vim #openssh-server #ntp #wget %end
http根目录结构
# tree -aL 2 /var/www/html/ /var/www/html/ ├── centos │ ├── CentOS_BuildTag │ ├── .discinfo │ ├── EFI │ ├── EULA │ ├── GPL │ ├── images │ ├── isolinux │ ├── LiveOS │ ├── Packages │ ├── repodata │ ├── RPM-GPG-KEY-CentOS-7 │ ├── RPM-GPG-KEY-CentOS-Testing-7 │ ├── TRANS.TBL │ └── .treeinfo └── ks.cfg 7 directories, 9 files
tftp目录文件准备
#tftp目录文件准备 cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ mkdir /var/lib/tftpboot/pxelinux.cfg cp /var/www/html/centos/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default cp /var/www/html/centos/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/ cp /var/www/html/centos/isolinux/{vesamenu.c32,boot.msg,splash.png} /var/lib/tftpboot/ # tree /var/lib/tftpboot/ /var/lib/tftpboot/ ├── boot.msg ├── initrd.img ├── pxelinux.0 ├── pxelinux.cfg │ └── default ├── splash.png ├── vesamenu.c32 └── vmlinuz 1 directory, 7 files
/var/lib/tftpboot/pxelinux.cfg/default 文件
# cat /var/lib/tftpboot/pxelinux.cfg/default default vesamenu.c32 timeout 60 display boot.msg # Clear the screen when exiting the menu, instead of leaving the menu displayed. # For vesamenu, this means the graphical background is still displayed without # the menu itself for as long as the screen remains in graphics mode. menu clear menu background splash.png menu title CentOS 7 menu vshift 8 menu rows 18 menu margin 8 #menu hidden menu helpmsgrow 15 menu tabmsgrow 13 # Border Area menu color border * #00000000 #00000000 none # Selected item menu color sel 0 #ffffffff #00000000 none # Title bar menu color title 0 #ff7ba3d0 #00000000 none # Press [Tab] message menu color tabmsg 0 #ff3a6496 #00000000 none # Unselected menu item menu color unsel 0 #84b8ffff #00000000 none # Selected hotkey menu color hotsel 0 #84b8ffff #00000000 none # Unselected hotkey menu color hotkey 0 #ffffffff #00000000 none # Help text menu color help 0 #ffffffff #00000000 none # A scrollbar of some type? Not sure. menu color scrollbar 0 #ffffffff #ff355594 none # Timeout msg menu color timeout 0 #ffffffff #00000000 none menu color timeout_msg 0 #ffffffff #00000000 none # Command prompt text menu color cmdmark 0 #84b8ffff #00000000 none menu color cmdline 0 #ffffffff #00000000 none # Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message. menu tabmsg Press Tab for full configuration options on menu items. menu separator # insert an empty line menu separator # insert an empty line label linux menu label ^Install CentOS 7 menu default kernel vmlinuz # append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet append initrd=initrd.img inst.ks=http://192.168.72.32/ks.cfg quiet label check menu label Test this ^media & install CentOS 7 kernel vmlinuz append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet menu separator # insert an empty line # utilities submenu menu begin ^Troubleshooting menu title Troubleshooting label vesa menu indent count 5 menu label Install CentOS 7 in ^basic graphics mode text help Try this option out if you're having trouble installing CentOS 7. endtext kernel vmlinuz append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 xdriver=vesa nomodeset quiet label rescue menu indent count 5 menu label ^Rescue a CentOS system text help If the system will not boot, this lets you access files and edit config files to try to get it booting again. endtext kernel vmlinuz append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rescue quiet label memtest menu label Run a ^memory test text help If your system is having issues, a problem with your system's memory may be the cause. Use this utility to see if the memory is working correctly. endtext kernel memtest menu separator # insert an empty line label local menu label Boot from ^local drive localboot 0xffff menu separator # insert an empty line menu separator # insert an empty line label returntomain menu label Return to ^main menu menu exit menu end
启动服务器
#启动服务器 iptables -F systemctl start httpd.service systemctl status httpd.service systemctl enable httpd.service systemctl start dhcpd.service systemctl status dhcpd.service systemctl enable dhcpd.service systemctl start xinetd.service systemctl status xinetd.service systemctl enable xinetd.service systemctl start tftp.socket systemctl status tftp.socket systemctl enable tftp.socket systemctl start tftp.service systemctl status tftp.service systemctl enable tftp.service
查看服务端口是否正常
#查看服务端口是否正常 tcp-80、udp-67、udp-69 ss -tilnp ss -uilnp #或 netstat -nat netstat -nau #查看dhcp地址分配情况 /var/lib/dhcpd/dhcpd.leases