PXE kickstart無人值守安裝RHEL5
——以下所有服務均安裝在同一個服務器上
——安裝RHEL5.9
理論部分請看:
一、搭建YUM
——用於提供各種安裝包
1、掛載光盤
[root@localhost /]# mount /dev/cdrom /mnt mount: block device /dev/cdrom is write-protected, mounting read-only [root@localhost /]#
2、修改YUM倉庫配置文件
注意YUM源的倉庫名字要以rhel開頭,不然在後面配置自應答文件會出錯,無法讀取rpm包
[root@localhost /]# vim /etc/yum.repos.d/rhel-debuginfo.repo 1 [rhel-debuginfo] 2 name=Red Hat Enterprise Linux 6.4 3 baseurl=file:///mnt/Server 4 enabled=1 5 gpgcheck=0
3、清理緩存,並驗證YUM是否搭建成功
[root@localhost /]# yum clean all Loaded plugins: product-id, security, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Cleaning up Everything [root@localhost /]# yum list | wc 3356 10030 271265 [root@localhost /]#
二、搭建DNS服務
——此步是可選的,安裝dns是爲了給服務器批量分配有規律的主機名
1、安裝bind、bind-chroot、caching-nameserver
[root@localhost /]# yum -y install bind bind-chroot caching-nameserver
2、建立dns服務主配置文件。也可以用模板
[root@localhost /]# vim /var/named/chroot/etc/named.conf 1 options{ 2 directory "/var/named"; 3 }; 4 zone "tarena.com"{ 5 type master; 6 file "tarena.com.zone"; 7 }; 8 zone "10.168.192.in-addr.arpa"{ 9 type master; 10 file "tarena.com.arpa"; 11 };
檢查是否有錯
[root@localhost /]# cd /var/named/chroot/etc/ [root@localhost etc]# [root@localhost etc]# named-checkconf named.conf [root@localhost etc]#
3、建立正向區域文件
[root@localhost named]# vim tarena.com.zone 1 $TTL 3600 2 @ IN SOA tarena.com. root.tarena.com. ( 3 2014030300 4 28800 5 14400 6 17200 7 86400 8 ) 9 IN NS dns.tarena.com. 10 dns IN A 192.168.10.2 11 $GENERATE 3-253 student$ IN A 192.168.10.$
4、建立反向區域文件
1 $TTL 3600 2 @ IN SOA tarena.com. root.tarena.com. ( 3 2014030300 4 28800 5 14400 6 17200 7 86400 8 ) 9 IN NS dns.tarena.com. 10 dns IN PTR 192.168.10.2 11 $GENERATE 3-253 $ IN PTR student$.tarena.com.
5、檢查區域文件是否有錯
[root@localhost named]# named-checkzone tarena.com tarena.com.zone zone tarena.com/IN: loaded serial 2014030300 OK [root@localhost named]# named-checkzone tarena.com tarena.com.arpa zone tarena.com/IN: loaded serial 2014030300 OK [root@localhost named]#
6、啓動服務並驗證
[root@localhost /]# service named restart 停止 named: [確定] 啓動 named: [確定] [root@localhost /]# nslookup > student10.tarena.com Server: 192.168.10.2 Address: 192.168.10.2#53 Name: student10.tarena.com Address: 192.168.10.10 > 192.168.10.20 Server: 192.168.10.2 Address: 192.168.10.2#53 20.10.168.192.in-addr.arpa name = student20.tarena.com. >
三、搭建DHCP服務
1、安裝dhcp服務主程序包
[root@localhost /]# yum -y install dhcp
2、編輯主配置文件/etc/dhcpd.conf
注意比常規配置多加了next-server和filename
[root@localhost /]# vim /etc/dhcpd.conf 1 ddns-update-style interim; 2 ignore client-updates; 3 subnet 192.168.10.0 netmask 255.255.255.0 { 4 option routers 192.168.10.254; 5 option subnet-mask 255.255.255.0; 6 option domain-name "tarena.com"; 7 option domain-name-servers tarena.com; 8 option time-offset -18000; 9 range dynamic-bootp 192.168.10.2 192.168.10.253; 10 default-lease-time 21600; 11 max-lease-time 43200; 12 next-server 192.168.10.2; 13 filename "pxelinux.0"; 14 }
3、啓動服務。
如果啓動失敗可用dhcpd命令排錯
[root@localhost /]# service dhcpd restart 關閉 dhcpd: [確定] 啓動 dhcpd: [確定] [root@localhost /]#
四、搭建tftp服務
1、安裝tftp主程序包
一般默認已安裝
[root@localhost /]# rpm -q tftp-server tftp-server-0.49-2 [root@localhost /]#
2、配置/etc/xinetd.d/tftp
把disable=yes改爲disable=no,啓用tftp
8 disable = no
3、重啓xinetd服務,使TFTP服務器生效。查看udp69號端口是否監聽
[root@localhost /]# netstat -anlup | grep :69 udp 0 0 0.0.0.0:69 0.0.0.0:* 5148/xinetd [root@localhost /]#
4、把系統引導文件pxelinux.0共享到tftp的家目錄下/tftpboot
4.1查看是否安裝syslinux
——syslinux是一個功能強大的引導加載程序
[root@localhost /]# rpm -q syslinux syslinux-4.02-7.2.el5 [root@localhost /]#
4.2、把pxelinux.0複製到tftp根目錄
[root@localhost /]# rpm -ql syslinux | grep pxelinux.0 /usr/share/syslinux/gpxelinux.0 /usr/share/syslinux/pxelinux.0 [root@localhost /]# cp /usr/share/syslinux/pxelinux.0 /tftpboot/ [root@localhost /]# ls /tftpboot/pxelinux.0 /tftpboot/pxelinux.0 [root@localhost /]#
5、把光盤中的initrd.img (驅動文件)和vmlinuz(內核文件)拷貝到tftp根目錄
進入/mnt/isolinux目錄
[root@localhost /]# cd /mnt/isolinux/ [root@localhost isolinux]# cp initrd.img vmlinuz /tftpboot/ [root@localhost isolinux]# ls /tftpboot/initrd.img vmlinuz /tftpboot/initrd.img vmlinuz [root@localhost isolinux]#
6、設置默認的啓動菜單文件default
——當系統調用pxelinux.0的時候必定要讀取pxelinux.cfg目錄下的配置文件default。複製光盤鏡像下的isolinux.cfg到pxelinux.cfg,並改名爲default
[root@localhost /]# mkdir -p /tftpboot/pxelinux.cfg [root@localhost /]#cp /mnt/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
6.1修改default文件
要實現pxe無人值守安裝linux,要指明自應答文件ks.cfg的位置
[root@localhost /]# vim /tftpboot/pxelinux.cfg/default 1 default linux 2 prompt 1 3 timeout 600 4 display boot.msg 5 F1 boot.msg 6 F2 options.msg 7 F3 general.msg 8 F4 param.msg 9 F5 rescue.msg 10 label linux 11 kernel vmlinuz 12 append initrd=initrd.img ks=nfs:192.168.10.2:/ks/ks.cfg
五、搭建nfs服務
1、確認已安裝nfs-until、portmap包
[root@localhost /]# rpm -q portmap portmap-4.0-65.2.2.1 [root@localhost /]# rpm -q nfs-utils nfs-utils-1.0.9-66.el5 [root@localhost /]#
2、配置/etc/exports,並重啓服務
共享ks.cfg文件和安裝時所需的rpm包
後面實驗生成的ks.cfg會放在/ks目錄;rpm包就用光盤鏡像的
[root@localhost /]# vim /etc/exports 1 /ks *(ro) 2 /mnt *(ro) 3
[root@localhost /]# service portmap restart 停止 portmap: [確定] 啓動 portmap: [確定] [root@localhost /]# service nfs restart 關閉 NFS mountd: [確定] 關閉 NFS 守護進程: [確定] 關閉 NFS quotas: [確定] 關閉 NFS 服務: [確定] 啓動 NFS 服務: [確定] 關掉 NFS 配額: [確定] 啓動 NFS 守護進程: [確定] 啓動 NFS mountd: [確定] Stopping RPC idmapd: [確定] 正在啓動 RPC idmapd: [確定] [root@localhost /]#
3、生成Kickstart自應答配置文件ks.cfg
通過Kickstart自應答配置文件,在安裝過程中安裝程序就可以自己從該文件中讀取安裝配置,這樣就避免了繁瑣的人機交互,實現無人值守的自動化安裝。
生成Kickstart自動應答配置文件ks.cfg有兩種方式:
(1)通過圖形化Kickstart配置程序進行配置然後生成
(2)直接複製/root/anaconda-ks.cfg改名爲ks.cfg。/root/anaconda-ks.cfg是裝系統後就會存在的一個文件。記錄了裝系統的過程
第二種方法難度很大,直接第一種
3.1、先安裝system-config-kickstart
[root@localhost /]# yum -y install system-config-kickstart
3.2運行system-config-kickstart 啓動kickstart配置程序
以下配置僅按照基本實驗需求設置。
1)基本配置
注意:‘安裝後重新引導系統’的勾要去掉,不然還沒來得及修改BOIS設置,又重新來一次安裝
2)安裝方法
——指定YUM源
3)引導裝載程序選項。按照默認
4)分區信息。僅建兩個分區,啓動分區和根分區
5)網絡配置。添加eth0網卡,用動態獲取IP
6)驗證。默認
7)防火牆配置。禁用防火牆和selinux
7)顯示配置。默認
8)軟件包選擇
——選擇常用的
9)預安裝腳本。默認
10)安裝後腳本。默認
3.3保存文件
——文件名爲ks.cfg,保存到/ks目錄下
4、驗證
可去掉文件的註釋內容;在加上 key –skip 跳過需要輸入序列號;
[root@localhost /]# sed -i '/^#/d' /ks/ks.cfg
[root@localhost /]# ls /ks/ks.cfg /ks/ks.cfg [root@localhost /]# vim /ks/ks.cfg 1 auth --useshadow --enablemd5 2 key --skip
六、重啓所有服務
七、客戶機測試
——bois設置引導方式爲網絡引導
——安裝完成後改回從硬盤啓動