Linux—图解PXE实现全自动安装系统

1、安装背景:

在实际工作中,我们经常会遇到这样的情况:想要安装Linux但是计算机没有光驱,或者是有大批量的计算机需要同时安装Linux,如果通过光驱的方式一个个安装,不仅效率低,也不利于维护。这是时候你就需要PXE的强大功能了。本文就简单的图解一下PXE的安装流程。

2、本博文中PXE自动安装硬件架构如下图,DHCP、TFTP、HTTP都在172.16.5.2这台服务器上。

3、自动安装原理:

1.客户机从自己的PXE网卡启动,向本网络中的DHCP服务器索取IP

2.DHCP服务器返回分给客户机IP

3.客户机向本网络中的TFTP服务器索取文件

4.客户机取得bootstrap文件后之执行引导文件完成引导

5.然后读取配置文件,通过TFTP服务器加载内核和文件系统

6.进入安装画面, 此时可以通过选择HTTP、FTP、NFS(这里以http为例)方式进行安装

从这里我们不难得到实现PXE网络安装必需的4个要素

1.客户机的网卡必须为PXE网卡

2.网络中必须要有DHCP和TFTP服务器,当然这两个服务器可以是同一台物理主机

3.所安装的操作系统必须支持网络安装。

4.必须要有FTP,HTTP,NFS至少一个服务器,当然也可以和DHCP和TFTP服务器同为一台物理主机

4、PXE配置流程图:

5、具体实现如下:

1、安装dhcp、自定义作用域

yum install dhcp -y[root@localhost ~]# rpm -ql dhcp/etc/dhcp/etc/dhcp/dhcpd.confsubnet 172.16.0.0 netmask 255.255.0.0 {range 172.16.5.10 172.16.5.20;option routers 172.16.0.1;next-server 172.16.5.2;filename “pxelinux.0”;} host webserver1 {hardware ethernet 00:0C:29:8C:C8:A4;fixed-address 172.16.5.100;option routers 172.16.0.1;option domain-name “http://il23f.blog.51cto.com”;option domain-name-servers 172.16.0.1,8.8.8.8;}

验证dhcpd进程是否处于监听状态

[root@localhost ~]# ps aux | grep dhcpdhcpd1708 0.0 0.8 48908 4308 ?Ss 20:27 0:00 /usr/sbin/dhcpd -user dhcpd -group dhcpdroot2844 0.0 0.1 103252 828 pts/0 S+ 21:51 0:00 grep dhcp[root@localhost ~]# ss -unl | grep :67UNCONN00*:67*:*

2、配置TFTP

yum -y install xinetd tftp-server tftpchkconfig xinetd onchkconfig tftp onservice xinetd start[root@localhost ~]# ss -unl | grep :69UNCONN00*:69*:*

3、准备安装树

mkdir /var/www/html/centos6mount –bind /media/cdrom /var/www/html/centos6service httpd start

4、准备/var/lib/tftpboot下文件

yum -y install syslinuxcp /media/cdrom/images/pxeboot/{vmlinuz,initrd.img} /var/lib/tftpboot/cp /media/cdrom/isolinux/{boot.msg,vesamenu.c32,splash.jpg} /var/lib/tftpboot/cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/mkdir /var/lib/tftpboot/pxelinux.cfgcp /media/cdrom/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default5、制作ks.cfg文件

5、制作kickstart文件ks.cfg,,放到/var/www/html目录下

#version=DEVEL# Firewall configurationfirewall –disabled# Install OS instead of upgradeinstall# Use network installationurl –url=”http://172.16.5.2/centos6″repo –name=”CentOS” –baseurl=http://172.16.5.2/centos6 –cost=100# Root passwordrootpw –iscrypted $1$seblmxLh$CowavZZ/Le1Yc9pWSXSCV/# System authorization informationauth –useshadow –passalgo=sha512# System keyboardkeyboard us# System languagelang en_US# SELinux configurationselinux –disabled# Installation logging levellogging –level=info# Reboot after installationreboot# System timezonetimezone Asia/Shanghai# Network informationnetwork –bootproto=dhcp –device=eth0 –onboot=on# System bootloader configurationbootloader –append=”crashkernel=auto crashkernel=auto rhgb rhgb quiet quiet” –location=mbr –driveorder=”sda”# Clear the Master Boot Recordzerombr# Partition clearing informationclearpart –all# Disk partitioning informationpart /boot –fstype=”ext4″ –size=200part / –fstype=”ext4″ –size=5000part swap –fstype=”swap” –size=1000%postecho -e ‘My 51cto blot: \n’ >> /etc/issuesed -i ‘1,$s@id:[0-9]:initdefault:@id:3:initdefault:@g’ /etc/inittab[ ! -d /root/.ssh ] && mkdir /root/.ssh && chmod og=— /root/.sshcat >> /root/.ssh/authorized_keys << EOFEOF# Enable funcdsed -i ‘s@certmaster =.*@certmaster = 172.16.0.1@g’ /etc/certmaster/minion.conf/sbin/chkconfig funcd off# Set the hostnameClientName=`ifconfig eth0 | awk ‘/inet addr:/{print $2}’ | awk -F. ‘{print $NF}’`sed -i “s@HOSTNAME=.*@HOSTNAME=client$ClientName.il23f.blog.51cto.com@g” /etc/sysconfig/networks# set puppet agentsed -i ‘/\[main\]/a server=il23f.blog.51cto.com’ /etc/puppet/puppet.conf/sbin/chkconfig puppet off# set hostsecho ‘172.16.0.1 il23f.blog.51cto.com’ >> /etc/hosts# yum repo%end%packages@base@basic-desktop@chinese-support@client-mgmt-tools@core@desktop-platform@fonts@general-desktop@graphical-admin-tools@legacy-x@network-file-system-client@perl-runtime@remote-desktop-clients@x11%end因为在路上你就已经收获了自由自在的好心情。

Linux—图解PXE实现全自动安装系统

相关文章:

你感兴趣的文章:

标签云: