PXE無人值守安裝系統

實驗拓撲:
             RHEL6.5_1
-----CentOS6.5(vmnet1)----------(vmnet1)
            RHEL6.5_2
實驗一:搭建PXE裝機服務器
    操做系統:RHEL 6.5
    網卡鏈接:eth0  (VMnet1)
    主機名:svr5.tarena.com
    IP地址:192.168.4.5/24
    關閉 iptables 防火牆、SELinux防禦機制html

1.檢查實驗環境
[root@svr5 ~]# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:0C:29:57:1E:86 
          inet addr:192.168.4.5  Bcast:192.168.4.255  Mask:255.255.255.0
...
[root@svr5 ~]# hostname
svr5.tarena.com
[root@svr5 ~]# yum repolist
[root@svr5 ~]# iptables -F
[root@svr5 ~]# service iptables save
[root@svr5 ~]# grep SELINUX=disabled /etc/sysconfig/selinux
SELINUX=disabled
[root@svr5 ~]# setenforce 0
2.配置YUM源(真實機以前已經配置好了,過程略...)
檢查一下
ftp://192.168.4.1/pub/iso/rhel6.5
3.配置DNS
[root@svr5 ~]# rpm -q bind bind-chroot
[root@svr5 ~]# yum -y install bind bind-chroot bind-utils
[root@svr5 ~]# cp -p /etc/named.conf /etc/named.conf.bak
[root@svr5 ~]# vim /etc/named.conf
...
 11         listen-on port 53 { any; };
 12 //      listen-on-v6 port 53 { ::1; };
...
 17         allow-query     { any; };
...
 42 zone "tarena.com" IN {
 43         type master;
 44         file "tarena.com.zone";
 45 };
 46
 47 zone "4.168.192.in-addr.arpa" IN {
 48         type master;
 49         file "192.168.4.arpa";
 50 };
...
[root@svr5 ~]# named-checkconf /etc/named.conf
[root@svr5 ~]# cd /var/named/
[root@svr5 named]# cp -p named.empty tarena.com.zone
[root@svr5 named]# cat tarena.com.zone
$TTL 3H
@ IN SOA @ rname.invalid. (
     2015011401 ; serial
     1D ; refresh
     1H ; retry
     1W ; expire
     3H ) ; minimum
 IN NS dns1.tarena.com.
dns1 IN A 192.168.4.5
$GENERATE  100-200  pc$ IN   A 192.168.4.$
[root@svr5 named]# cp -p tarena.com.zone 192.168.4.arpa
[root@svr5 named]# cat 192.168.4.arpa
$TTL 3H
@ IN SOA @ rname.invalid. (
     2015011401 ; serial
     1D ; refresh
     1H ; retry
     1W ; expire
     3H ) ; minimum
 IN NS dns1.tarena.com.
5 IN PTR dns1.tarena.com.
$GENERATE 100-200 $ IN PTR pc$.tarena.com.
[root@svr5 ~]# rndc-confgen -r /dev/urandom -a
[root@svr5 ~]# service named restart
[root@svr5 ~]# chkconfig named on
[root@svr5 ~]# host pc100.tarena.com 192.168.4.5
[root@svr5 ~]# host 192.168.4.150 192.168.4.5
4.配置DHCP
[root@svr5 ~]# rpm -q dhcp
[root@svr5 ~]# yum -y install dhcp
[root@svr5 ~]# cat /etc/dhcp/dhcpd.conf
option domain-name "tarena.com";
option domain-name-servers 192.168.4.5;
default-lease-time 7200;
max-lease-time 14400;
subnet 192.168.4.0 netmask 255.255.255.0 {
   range 192.168.4.100 192.168.4.200;
   option routers 192.168.4.1;
 next-server 192.168.4.5;
 filename "pxelinux.0";
}
[root@svr5 ~]# service dhcpd restart
[root@svr5 ~]# chkconfig dhcpd on
5.配置TFTP
[root@svr5 ~]# rpm -q tftp-server
[root@svr5 ~]# yum -y install tftp-server
[root@svr5 ~]# chkconfig tftp on
[root@svr5 ~]# service xinetd restart
[root@svr5 ~]# chkconfig xinetd on
[root@svr5 named]# netstat -anptu | grep xinetd
udp   0  0 0.0.0.0:69    0.0.0.0:*   2526/xinetd    
6.準備啓動文件
[root@svr5 ~]# yum -y install syslinux
[root@svr5 ~]# cd /usr/share/syslinux/
[root@svr5 syslinux]# cp pxelinux.0 /var/lib/tftpboot/
[root@svr5 syslinux]# cd /var/lib/tftpboot/
[root@svr5 tftpboot]# yum -y install wget
[root@svr5 tftpboot]# wget ftp://192.168.4.1/pub/iso/rhel6.5/isolinux/vmlinuz
[root@svr5 tftpboot]# wget ftp://192.168.4.1/pub/iso/rhel6.5/isolinux/initrd.img
[root@svr5 tftpboot]# ls
initrd.img  pxelinux.0  vmlinuz
7.測試tftp
[root@svr5 tftpboot]# cd /tmp/
[root@svr5 tmp]# yum -y install tftp
[root@svr5 tmp]# tftp 192.168.4.5 -c get pxelinux.0
[root@svr5 tmp]# ls -lh pxelinux.0
-rw-r--r-- 1 root root 27K 1月  14 14:43 pxelinux.0
8.配置啓動菜單
[root@svr5 ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[root@svr5 ~]# cd /var/lib/tftpboot/pxelinux.cfg/
[root@svr5 pxelinux.cfg]# wget ftp://192.168.4.1/pub/iso/rhel6.5/isolinux/isolinux.cfg
[root@svr5 pxelinux.cfg]# mv isolinux.cfg default
linux

準備應答文件
    找一臺已裝好的RHEL6.5模板客戶機(本例中可選PXE服務器本機),經過system-config-kickstart工具建立rhel6-ks.cfg應答文件
[root@svr5 ~]# yum -y install system-config-kickstart
[root@svr5 ~]# system-config-kickstart  //在圖形桌面下運行,詳細見截圖
     !!!! 基本配置:指定默認語言、時區、根口令(redhat)
     !!!! 安裝方式:新安裝、FTP安裝(192.168.4.一、/pub/iso/rhel6.5)
     !!!! 分區信息:清除主引導記錄、刪除全部現存分區、初始化磁盤標籤、/boot 200MB、SWAP 2GB、/  剩餘空間
     !!!! 網絡配置:第一塊網卡DHCP自動獲取
     !!!! 防火牆配置:禁用SELinux、禁用防火牆
     !!!! 軟件包選擇:不安裝圖形桌面
將文件另存爲/root/rhel6.5-ks.cfg
2.將生成rhel6.5-ks.cfg文件上傳到ftp服務器上面
[root@svr5 ~]# scp /root/rhel6.5-ks.cfg root@192.168.4.1:/var/ftp/pub/
[root@svr5 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default   //修改引導配置文件
default  linux     //默認從哪一個標籤引導系統
prompt 1      //是否交互式安裝
timeout 600      //進入默認系統的等待超時(單位:1/10秒)
label linux     //定義名爲linux的標籤
        kernel  vmlinuz //選擇此標籤時,須要加載的內核文件
        append  ks=ftp://192.168.4.1/pub/rhel6.5-ks.cfg initrd=initrd.img   //下載並啓用自動應答文件
3.檢查ftp://192.168.4.1上面的文件
[root@svr5 ~]# elinks --dump ftp://192.168.4.1/pub/rhel6.5-ks.cfg
4.啓動一臺裸客戶機(新建虛擬機),測試無人值守安裝
     !!!! 安裝設置過程會自動應答,免手工交互
     !!!! 等待客戶機系統安裝完成vim

實驗三:安裝後腳本操做
 安裝完成後自動配置yum客戶端文件
 自動安裝httpd服務並設置開機啓動
 配置默認網頁內容爲"I Love Studying..."bash

1.直接編輯FTP服務器上的ks文件,在最下面添加以下內容
[root@localhost ~]# vim /var/ftp/pub/rhel6.5-ks.cfg
...
%post --interpreter=/bin/bash
rm -rf /etc/yum.repos.d/*
echo '[rhel6]
name=RedHat Linux 6.5
baseurl=ftp://192.168.4.1/pub/iso/rhel6.5
enabled=1
gpgcheck=0' > /etc/yum.repos.d/rhel6.repo
yum clean all
yum -y install httpd
echo 'I Love Studying...' > /var/www/html/index.html
/etc/init.d/httpd start
chkconfig httpd on
%end
2.啓動一臺裸客戶機(新建虛擬機),測試無人值守安裝
3.檢查裝好的客戶機,確認POST腳本設置結果
[root@pc100 ~]# ifconfig eth0 | grep "inet addr" //查看自動配置的IP地址
          inet addr:192.168.4.100  Bcast:192.168.4.255  Mask:255.255.255.0
[root@pc100 ~]# chkconfig --list httpd //查看Web服務的自啓動態
httpd    0:off 1:off 2:on 3:on 4:on 5:on 6:關閉
[root@pc100 ~]# yum -y install elinks //確保可yum安裝軟件包
[root@pc100 ~]# elinks --dump http://127.0.0.1 //訪問測試網頁
I Love Linux...服務器

相關文章
相關標籤/搜索