Pxe+Kickstart
實現無人值守批量網絡安裝操作系統
說明:
當批量給主機安裝操作系統時,我們不可能用傳統的方式——用光盤、U盤等,一臺一臺逐個安裝,這樣一來,費時又力,對於批量部署主機時,效率是極低的。所以,我們通過
Pxe+Kickstart技術來實現企業中集羣服務的批量安裝,近而將網絡技術人員從繁忙中解脫出來,之後你就可以去悠閒地去飲一杯coffee了,過半個多小時回來,這批服務器都乘乘地
擁有了自己的操作系統。下面是詳細配置過程:
實驗環境準備
VmwareworkStation虛擬機
一臺裝有Linux操作系統的虛擬機,這裏命名它爲PXE-Server(靜態IP爲192.168.1.254)
新建2臺虛擬裸機(待安裝的所有裸機網卡都配置成vmnet1)
實驗過程概述
PXE-Server上安裝dhcpd 、tftp 、nfs、httpd三個服務
將相關內核和啓動引導文件initrd.img pxelinux.0 pxelinux.cfg vmlinuz放到tftp根目錄/tftpboot下
步驟:
1.配置yum庫
[root@localhost ~]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# cp rhel-debuginfo.repo yang.repo
[root@localhost yum.repos.d]#vim yang.repo
[rhel-server] //[ ]裏要以rhel- 開頭,製作kickstart文件選擇安裝包時要用到
name=Red Hat Enterprise Linux Server
baseurl=file:///misc/cd/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
測試yum庫安裝情況
[root@localhost ~]#yum list
Loaded plugins: product-id, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Installed Packages
Deployment_Guide-en-US.noarch 5.8-1.el5 installed
Deployment_Guide-zh-CN.noarch 5.8-1.el5 installed
Deployment_Guide-zh-TW.noarch 5.8-1.el5 installed
GConf2.i386 2.14.0-9.el5 installed
.
.
出現上邊的界面表示yum庫安裝成功!
2.安裝並配置DHCP服務
[root@localhost ~]# yum -y install dhcp* //安裝
[root@localhost ~]# vim /etc/dhcpd.conf //配置
ddns-update-style interim;
next-server 192.168.1.254; //
filename "pxelinux.0";
subnet 192.168.1.0 netmask 255.255.255.0 {
option subnet-mask 255.255.255.0;
option domain-name "tarena.com";
option domain-name-servers 192.168.1.254;
range dynamic-bootp 192.168.1.1 192.168.1.10;
default-lease-time 21600;
max-lease-time 43200;
}
3.安裝NFS共享服務
[root@localhost ~]# yum -y install nfs-utils portmap //安裝軟件包nfs-utils- 1.0.9-66.el5 portmap-4.0-65.2.2.1
[root@localhost ~]# vim /etc/exports // 修改主配置文件
/data/iso/rhel5.9 *(ro)
[root@localhost ~]# mkdir -p /data/iso/rhel5.9 //創建系統鏡像存放目錄
[root@localhost ~]# cp -rf /misc/cd/* /data/iso/rhel5.9 //拷貝光盤所有
也可以用掛載的方法,同樣實現訪問鏡像文件的作用
[root@localhost ~]# umount -a
[root@localhost ~]# mount /misc/cd /data/iso/rhel5.9
3.安裝並配置TFTP服務
[root@localhost ~]# yum -yinstall tftp
[root@localhost ~]#service xinetd restart //開啓tftp臨時服務
[root@localhost ~]# cd /misc/cd/images/pxeboot //進入光盤目錄
[root@localhost pxeboot]# ls
initrd.img README TRANS.TBL vmlinuz
[root@localhost pxeboot]# cp initrd.img vmlinuz /tftpboot
[root@localhost ~]#vim /etc/xinetd.d/tftp //配置tftp臨時服務文件
[root@localhost ~]# find / -name pxelinux.0 //查找pxelinux.0文件存位置
/tftpboot/linux-install/pxelinux.0
/usr/share/syslinux/pxelinux.0
[root@localhost ~]# cp /tftpboot/linux-install/pxelinux.0 /tftpboot //將這個文件拷貝到/tftpboot
若沒找到/pxelinux.0這個文件,則安裝一個包:
[root@localhost ~]# yum –y install syslinux-tftpboot.x86_64
安裝完後到這個位置去找/usr/share/syslinux/pxelinux.0
[root@localhost ~]# cp -rf /tftpboot/linux-install/pxelinux.cfg/ /tftpboot //將pxelinux.cfg拷貝到/tftpboot
若找不到則創建這目錄
[root@localhost pxeboot]# mkdir /tftpboot/pxelinux.cfg
然後
[root@localhost pxeboot]# cp /misc/cd/isolinux/isolinux.cfg \
> /tftpboot/pxelinux.cfg/default //拷貝模板到default
[root@localhost ~]# cd /tftpboot/
[root@localhost tftpboot]# ls
initrd.img linux-install pxelinux.0 pxelinux.cfg vmlinuz
至此/tftpboot下的initrd.img pxelinux.0 pxelinux.cfg vmliuz全部準備好了
4.生成Kickstart無人值守配置文件
[root@localhost ~]# yum -y install system-config-kickstart //安裝生成Kickstart的工具
之後,點擊文件保存到一個目錄下就OK了
5.安裝httpd服務
[root@localhost ~]# yum -y install httpd
[root@localhost ~]# cp /root/ks.cfg /var/www/html/ //ks.cfg是步驟4生成的配置文件 ,/var/www/html/ —— httpd默認站點
[root@localhost ~]# service httpd restart
[root@localhost ~]# chkconfig httpd on
[root@localhost ~]# vim /var/www/html/ks.cfg
在文件中添加key --skip //任意位置
最後vim /tftpboot/pxelinux.cfg/default
6.測試
將兩臺虛擬裸機開機(此後不應有交互的操作,靜等安裝)