方法:PXE + DHCP+TFTP+ Kickstart+ HTTP
执行 PXE + KickStart安装需要准备内容:
• DHCP 服务器用来给客户机分配IP;
• TFTP 服务器用来存放PXE的相关文件,比如:系统引导文件;
• HTTP 服务器用来存放系统安装文件,镜像;
• KickStart所生成的ks.cfg配置文件;
• 带有一个 PXE 支持网卡的将安装的主机。
安装所需软件包:httpd tftp-server dhcp xinetd system-config-kickstart
实战:给公司搭建一台无人执守安装服务器,要求通过此服务器安装好系统后,直接自动化配置好web服务器。并启动httpd服务。后期,一但需要重新安装新的web服务器时,直接使用你搭建的“无人执守安装服务器”就可以安装成功。
1)服务端安装httpd、dhcp、tftp-server、xinetd、kickstart服务:
[[email protected]_S ~]# yum -y install httpd tftp-server xinetd dhcp system-config-kickstart
2)将RHEL6.5镜像挂载到http根目录下:
[[email protected]_S ~]# umount /mnt/ [[email protected]_S ~]# mkdir /var/www/html/mnt [[email protected]_S ~]# mount /dev/sr0 /var/www/html/mnt/ mount: block device /dev/sr0 is write-protected, mounting read-only [[email protected]_S ~]# df -h Filesystem SizeUsed Avail Use% Mounted on /dev/sda2 9.9G3.8G 5.6G 41% / tmpfs 491M 0491M 0% /dev/shm /dev/sda1 194M30M 155M 16% /boot /dev/sr0 3.6G3.6G 0 100% /var/www/html/mnt
3)注释APACHE欢迎页:
[[email protected]_S ~]# vim /etc/httpd/conf.d/welcome.conf #<LocationMatch "^/+$"> #将此4行注释掉 # Options -Indexes # ErrorDocument 403 /error/noindex.html #</LocationMatch> [[email protected]_S html]# service httpd restart Stopping httpd: [ OK ] Starting httpd:[ OK ]
4)通过浏览器可以正常访问到挂载的镜像:
5)修改tftp配置文件(在xinetd服务下管理),并启用服务:
[[email protected]_S ~]# vim /etc/xinetd.d/tftp service tftp { socket_type = dgram protocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /var/lib/tftpboot #tftp默认的运行目录 disable = no #将yes改为no,启用服务 per_source = 11 cps = 100 2 flags = IPv4 } [[email protected]_S ~]# service xinetd start Starting xinetd:[ OK ] [[email protected]_S ~]# lsof -i:69 #tftp端口69正在运行 COMMAND PID USERFD TYPE DEVICE SIZE/OFF NODE NAME xinetd 2675 root5u IPv4 180530t0 UDP *:tftp
6)配置DHCP服务,并启用服务:
[[email protected]_S ~]# vim /etc/dhcp/dhcpd.conf subnet 10.0.0.0 netmask 255.255.255.0 { #作用域(子网及掩码) range 10.0.0.100 10.0.0.200; #分配地址池 option domain-name-servers 10.0.0.1; #DNS option domain-name "linl_S"; #域名 option routers 10.0.0.1; #网关 option broadcast-address 10.0.0.255; #广播地址 default-lease-time 600; #默认租约时间 max-lease-time 7200; #最大租约时间 next-server 10.0.0.15; #指向tftp服务器地址 filename "pxelinux.0"; #文件名 } [[email protected]_S ~]# dhcpd #查看配置是否正确,错误会有相应提示 Internet Systems Consortium DHCP Server 4.1.1-P1 Copyright 2004-2010 Internet Systems Consortium. All rights reserved. #正确 For info, please visit https://www.isc.org/software/dhcp/ Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file Wrote 0 leases to leases file. Listening on LPF/eth0/00:0c:29:a9:c1:ae/10.0.0.0/24 Sending onLPF/eth0/00:0c:29:a9:c1:ae/10.0.0.0/24 Sending on Socket/fallback/fallback-net [[email protected]_S ~]# service dhcpd start Starting dhcpd: [ OK ]
7)配置PXE启动所需的相关文件,即tftp需要共享出去的文件(将文件拷贝到tftp默认工作目录下):
[[email protected]_S ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ #注,只有安装了system-config-kickstart软件包,才会有/usr/share/syslinux/目录及目录中的文件。 [[email protected]_S ~]# cp /var/www/html/mnt/images/pxeboot/{initrd.img,vmlinuz} /var/lib/tftpboot/ #镜像光盘中的引导文件和内核拷贝过来 [[email protected]_S ~]# cp /var/www/html/mnt/isolinux/*.msg /var/lib/tftpboot/ #镜像光盘中的显示信息的.msg文件拷贝过来 [[email protected]_S ~]# mkdir /var/lib/tftpboot/pxelinux.cfg [[email protected]_S ~]# cp /var/www/html/mnt/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default #镜像光盘中isolinux.cfg拷贝到pxelinux.cfg目录下,重命名为default
8)修改default文件:
[[email protected]_S ~]# vim /var/lib/tftpboot/pxelinux.cfg/default default linux #默认改为linux #prompt 1 timeout 600 label linux menu label ^Install or upgrade an existing system menu default kernel vmlinuz append initrd=initrd.img ks=http://10.0.0.15/ks.cfg #添加ks访问位置,安装程序通过此路径访问kickstart文件
9)启动kickstart,并配置参数(可采用Xmanager远程):
10)复制ks.cfg文件到网站根目录下
[[email protected]_S ~]# cp /root/ks.cfg /var/www/html/ 注:ks.cfg就是无人值守安装时要用的Kickstart文件。 要对应:/var/lib/tftpboot/pxelinux.cfg/default文件中设置过ks=http://192.168.1.63/ks.cfg
11)启动PXE客户端:
时间: 2024-09-30 20:07:55