运维工具pxe环境的实现(一)

<p>
</p><p class="MsoNormal" align="center" style="text-align:center;"> <span style="line-height:1.5;">PXE and Cobbler </span> </p><p class="MsoNormal" align="center" style="text-align:left;"> <span style="line-height:1.5;">1,pxe
</span> </p><p class="MsoNormal" align="center" style="text-align:center;"> <span style="line-height:1.5;">
</span> </p><p>
</p><p class="MsoNormal"> <span>PEX</span>全称:预引导执行环境(<span>Preboot  execute environment</span>)<span></span> </p><p class="MsoNormal"> <span>PXE</span>依赖<span>ftp,http,tftp,dhcp</span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> 搭建<span>dhcp</span>:<span>dynamin host configuration protocol</span> </p><p class="MsoNormal"> <span>www.Isc.org</span> </p><p class="MsoNormal"> <span>[root@Pxe ~]#<span style="color:#E56600;"> yum -y install dhcp</span></span> </p><p class="MsoNormal"> <span>[root@Pex ~]# ifconfig eth2 10.5.5.1/24 up</span> </p><p class="MsoNormal"> <span>[root@Pex ~]# cp/usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf</span> </p><p class="MsoNormal"> <span>cp: overwrite /etc/dhcp/dhcpd.conf'? y</span> </p><p class="MsoNormal"> <span>[root@Pex ~]#vim /etc/dhcp/dhcpd.conf</span> </p><p class="MsoNormal"> <span>option domain-name "example.org";&nbsp;&nbsp;&nbsp; </span>搜索域域名<span></span> </p><p class="MsoNormal"> <span>option domain-name-servers ns1.example.org,ns2.example.org;&nbsp; dns</span>服务器<span></span> </p><p class="MsoNormal"> <span>&nbsp;</span> </p><p class="MsoNormal"> <span>default-lease-time 600;&nbsp;&nbsp; </span>默认租约期限<span></span> </p><p class="MsoNormal"> <span>max-lease-time 7200;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; </span>最大租约期限<span></span> </p><p class="MsoNormal"> <span>log-facility local7;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; </span>记录日志使用的那个<span>facility</span> </p><p class="MsoNormal"> <span>subnet 10.152.187.0 netmask 255.255.255.0 {} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>定义一个为其分配地址的网络<span></span> </p><p class="MsoNormal"> <span>&nbsp;</span> </p><p class="MsoNormal"> <span>subnet 10.5.5.0 &nbsp;netmask 255.255.255.0 { </span> </p><p class="MsoNormal"> <span>&nbsp;range 10.5.5.20 &nbsp;10.5.5.50; </span>地址池<span></span> </p><p class="MsoNormal"> <span>#&nbsp;option domain-name-servers ns1.internal.example.org;</span> </p><p class="MsoNormal"> <span>#&nbsp;option domain-name "internal.example.org";</span> </p><p class="MsoNormal"> <span>&nbsp;option routers 10.5.5.1;&nbsp; </span>网关<span></span> </p><p class="MsoNormal"> <span>&nbsp;</span> </p><p class="MsoNormal"> <span>&nbsp;</span> </p><p class="MsoNormal"> <span>[root@Pex ~]# service dhcpd restart</span> </p><p class="MsoNormal"> <span>Shutting down dhcpd:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&nbsp; OK&nbsp; ]</span> </p><p class="MsoNormal"> <span>Starting dhcpd:</span> </p><p class="MsoNormal"> <span>[root@Pex ~]# ss -unl |grep :67</span> </p><p class="MsoNormal"> <span>UNCONN&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *:67&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *:*&nbsp;&nbsp;&nbsp;&nbsp; </span> </p><p class="MsoNormal"> <span>[root@Pex ~]#</span> </p><p class="MsoNormal"> 确保<span>iptables</span>没有阻止<span></span> </p><p class="MsoNormal"> <span>[root@Pex ~]# iptables -L -n</span> </p><p class="MsoNormal"> <span>&nbsp;</span> </p><p class="MsoNormal"> 在第二台机器进行获取,正常获取到<span>10.5.5.x</span> </p><p class="MsoNormal"> 在<span>PXE</span>查看<span>IP</span>地址租约日志<span></span> </p><p class="MsoNormal"> <span>[root@Pex ~]# tail/var/lib/dhcpd/dhcpd.leases</span> </p><p class="MsoNormal"> <span>server-duid"\000\001\000\001\035\034J\206\000\014)b#";</span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> <span>lease 10.5.5.20 {</span> </p><p class="MsoNormal"> <span> starts 2 2015/06/23 16:53:51;</span> </p><p class="MsoNormal"> <span> ends 2 2015/06/23 17:53:51;</span> </p><p class="MsoNormal"> <span> cltt 2 2015/06/23 16:53:51;</span> </p><p class="MsoNormal"> <span> binding state active;</span> </p><p class="MsoNormal"> <span> next binding state free;</span> </p><p class="MsoNormal"> <span> hardware ethernet 00:0c:29:b5:3c:7d;</span> </p><p class="MsoNormal"> <span>}</span> </p><p class="MsoNormal"> <span>[root@Pex ~]#</span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> <span>DHCP</span>在分配地址时,也可以绑定<span>MAC</span>地址,假设我们绑定<span>MAC</span>地址<span>00:0C:29:B5:3C:7D</span>,<span>ip</span>为<span>10.5.5.30</span> </p><p class="MsoNormal"> 注意:这里的地址肯定不能使用地址池的地址,使用地址池之外的预留地址<span></span> </p><p class="MsoNormal"> <span>host ftpserver {</span> </p><p class="MsoNormal"> <span>       hardware ethernet 00:0C:29:B5:3C:7D</span>;<span></span> </p><p class="MsoNormal"> <span>       fixed-address 10.0.10.60</span>;<span></span> </p><p class="MsoNormal"> <span>}</span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> [root@Pex ~]# vim /etc/dhcp/dhcpd.conf</p><p class="MsoNormal"> 在<span>option routers 10.0.10.1;</span>添加以下两项<span></span> </p><p class="MsoNormal"> <span> next-server 10.0.10.1;  </span>告诉<span>dhcp</span>,<span>tftp</span>是谁<span></span> </p><p class="MsoNormal"> <span> filename "pxelinux.0";  </span>这个文件由<span>syslinux</span>提供,这个文件的存放位置在<span>tftp</span>目录下 <span></span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> 在<span>PXE</span>机器上安装<span>tftp</span>服务器<span></span> </p><p class="MsoNormal"> <span>[root@Pex ~]#yum  -y install tftp-server tftp</span> </p><p class="MsoNormal"> 复制文件测试<span></span> </p><p class="MsoNormal"> <span>[root@Pex ~]# cp /etc/fstab/var/lib/tftpboot/</span> </p><p class="MsoNormal"> <span>[root@Pex ~]# tftp 10.5.5.1</span> </p><p class="MsoNormal"> <span>[root@Pex dhcp]# cd /var/lib/ tftpboot/</span> </p><p class="MsoNormal"> <span>[root@Pex tftpboot]# ls</span> </p><p class="MsoNormal"> <span>fstab</span> </p><p class="MsoNormal"> 这种方式基于<span>UDP</span>,文件传输有可能发生错误!<span></span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> 安装syslinux复制pxelinux.0文件</p><p class="MsoNormal"> <span>[root@Pex tftpboot]# yum -y installsyslinux</span> </p><p class="MsoNormal"> 将<span>pxelinux.0</span>复制到<span>tftpboot</span>目录下<span></span> </p><p class="MsoNormal"> <span>[root@Pex tftpboot]# cp/usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/</span> </p><p class="MsoNormal"> 复制完成后,仅仅只是把<span>PXE</span>环境配置好,还需要挂载光盘把基于<span>PXE</span>启动的文件复制过来<span></span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> 如果互联网有安装树的源,也可以使用。这里演示使用挂载本地光盘<span></span> </p><p class="MsoNormal"> <span>[root@Pex ~]# mount -r /dev/cdrom /mnt/</span> </p><p class="MsoNormal"> <span>[root@Pex ~]# cd /mnt/</span> </p><p class="MsoNormal"> <span>[root@Pex mnt]# cd isolinux/</span> </p><p class="MsoNormal"> <span>[root@Pex isolinux]# cd ..</span> </p><p class="MsoNormal"> <span>[root@Pex mnt]# cd images/pxeboot/</span> </p><p class="MsoNormal"> 而后复制文件vmlinuz  initrd.img到/var/lib/tftpboot/<span></span> </p><p class="MsoNormal"> 复制vesamenu.c32splash.jpg boot.msg<span> </span>到<span>/var/lib/tftpboot/</span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> <span>[root@Pex pxeboot]# cp /mnt/images/pxeboot/vmlinuz initrd.img      /var/lib/tftpboot/</span> </p><p class="MsoNormal"> <span>[root@Pex pxeboot]# cd ../../isolinux/</span> </p><p class="MsoNormal"> <span>[root@Pex isolinux]# cp vesamenu.c32splash.jpg boot.msg  /var/lib/tftpboot/</span> </p><p class="MsoNormal"> 创建pxelinux.cfg目录<span></span> </p><p class="MsoNormal"> <span>[root@Pex isolinux]# mkdir/var/lib/tftpboot/pxelinux.cfg</span> </p><p class="MsoNormal"> 复制光盘中isolinux.cfg到/var/lib/tftpboot/pexlinux.cfg中命名为default<span></span> </p><p class="MsoNormal"> <span>[root@Pex isolinux]# cp isolinux.cfg/var/lib/tftpboot/pxelinux.cfg/default</span> </p><p class="MsoNormal"> 我们编辑default,在menu title Welcome to CentOS 6.6添加LinuxEA字段标识</p><p class="MsoNormal"> <span>[root@Pex pxelinux.cfg]# vim default </span> </p><p class="MsoNormal"> <span>menu title Welcome to CentOS 6.6 LinuxEA!</span> </p><p class="MsoNormal"> </p><p class="MsoNormal"> 我们开始测试。从网卡启动!测试下能否读取到<span>pxe</span>的<span>tftp</span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> 而后在/var/www/html/下创建centos6.6目录,将本地光盘绑定至centos6.6<span></span> </p><p class="MsoNormal"> <span>[root@Pex isolinux]#Mkdir /var/www/html/centos6.6</span> </p><p class="MsoNormal"> <span>[root@Pex isolinux]#Mount –bind /mnt/var/www/html/centos6.6</span> </p><p class="MsoNormal"> 在启动<span>httpd</span> </p><p class="MsoNormal"> <span>[root@Pex isolinux]#Service httpd start</span> </p><p class="MsoNormal"> 通过浏览器<span>http://172.16.249.108/centos6.6/<;/span>访问<span></span> </p><p class="MsoNormal"> <span></span> </p><p class="MsoNormal"> <span> </span> </p><p class="MsoNormal"> 而后我们就开始复制Kickstart文件了,这个文件在/root/目录下,叫anaconda-ks.cfg、我们把他复制到/var/www/html/下,改名为ks.cfg
<span>[root@Pex isolinux]#  cp /root/anaconda-ks.cfg  /var/www/html/ks.cfg</span><span></span> </p><p class="MsoNormal"> 回头编辑<span>/var/lib/tftpboot/pxelinux.cfg/default</span>文件,添加<span>ks.cfg</span>文件<span></span> </p><p class="MsoNormal"> <span>[root@localhost pxelinux.cfg]# vim/var/lib/tftpboot/pxelinux.cfg/default</span> </p><p class="MsoNormal"> <span>label linux</span> </p><p class="MsoNormal"> <span> menu label ^Install or upgrade an existing system</span> </p><p class="MsoNormal"> <span> menu default</span> </p><p class="MsoNormal"> <span> kernel vmlinuz</span> </p><p class="MsoNormal"> <span> append initrd=initrd.img <span style="color:#E53333;"> ks=http://10.5.5.1/ks.cfg<;/span></span> </p><p class="MsoNormal"> <span><span style="color:#E53333;">
</span></span> </p><p class="MsoNormal"> <span><span style="color:#E53333;">
</span></span> </p><p class="MsoNormal"> <span><span style="color:#E53333;">
</span></span> </p><p class="MsoNormal"> <span><span style="color:#E53333;">
</span></span> </p>

<p class="MsoNormal"> <span> </span> </p>

0 分享

您可以选择一种方式赞助本站

支付宝扫码赞助

支付宝扫码赞助

日期: 2015-06-24分类: 自动化

标签: ops_tool

发表评论