之前的工做中作過一次無人值守全自動批量安裝Centos,無耐當時太忙,忘了作筆記。如今恰好公司新進了一批服務器要上架,要作系統,正好利用這次機會作了以下筆記:html
什麼是PXE?什麼是Kickstart?此處不在一 一描述,由於網絡上對這些概念解釋實在是太多了,我就此對PXE+Kickstart的安裝條件和詳細步驟作一 闡述。linux
執行PXE+Kickstart安裝須要先決條件:服務器
DHCP服務器;
網絡
TFTP服務器;app
Kickstart所生成的ks.cfg配置文件;ide
一臺存放系統安裝文件的服務器,如NFS、HTTP或FTP服務器;工具
一臺帶有支持PXE網卡啓動的主機。oop
系以環境介紹:服務器系統爲Centos-6.6_x86_64,ip地址爲:10.0.0.13。因爲服務器是最小化安裝的,咱們在後面要用到system-config-kickstart工具,它必須依賴於X Windows,因此咱們要提早安裝好X Windows及Desktop並重啓系統,使其進入圖形模式下。url
1、環境準備spa
[root@test-A ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@test-A ~]# uname -m
x86_64
[root@test-A ~]# yum -y groupinstall 'X Window System'
[root@test-A ~]# yum -y groupinstall 'Desktop'
出錯以下:
Error: samba4-common conflicts with samba-common-3.6.23-24.el6_7.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
根據錯誤提示,及錯誤提示後面系統給出的解決方法爲:
1.使用「--skip-broken"選項跳過上面錯誤;
2.嘗試運行"rpm -Va --nofiles --nodigest",解決這上錯誤
[root@test-A ~]# rpm -Va --nofiles --nodigest #運行此命令,沒有任何操做和提示,那麼使用第一種方法直接跳過錯誤
[root@test-A ~]# yum -y groupinstall 'Desktop' --skip-broken #跳過或忽略上面的錯誤安裝'Desktop',一切正常,呵呵
而後修改/etc/inittab文件並重啓服務器,使其運行在圖形模式下,主要修改的文件內容以下:
id:5:initdefault:
保存退出,init 6重啓服務器
2、無人值守安裝實戰
掛載光盤ISO文件到/mnt/cdrom目錄下,以下:
mkdir -p /mnt/cdrom
mount -o loop CentOS-6.6-x86_64-minimal.iso /mnt/cdrom #CentOS-6.6-x86_64-minimal.iso光盤鏡像文件可自行下載
安裝httpd
rpm -qa httpd #沒安裝的話就yum安裝一下
yum -y install httpd httpd-tools
複製光盤ISO文件下的全部內容(文件和文件夾)到/var/www/html(此目錄爲Apache默認的DocumentRoot目錄)下。
cp -rf /mnt/cdrom/* /var/www/html
安裝tftp-server,並啓用tftp服務,同時啓動xinetd進程
1)安裝tftp-server
yum -y install tftp-server
2)修改/etc/xinetd.d/tftp文件,將disable的值由yes變爲no,以下:
3)重啓xinetd進程
/etc/init.d/xinetd restart
配置支持PXE的啓動程序(注意:前面已經將CentOS-6.6-x86_64光盤的內容複製到/var/www/html目錄中了,因此只要從/var/www/html目錄中複製須要的文件就好了)
mkdir /tftpboot
yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 /tftpboot
cp /var/www/html/p_w_picpaths/pxeboot/initrd.img /tftpboot
cp /var/www/html/p_w_picpaths/pxeboot/vmlinuz /tftpboot
cp /var/www/html/isolinux/*.msg /tftpboot/
mkdir /tftpboot/pxelinux.cfg
cp /var/www/html/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
注意:此時先不要修改default文件,雖然如今已經能夠經過網絡來引導並手動安裝Kickstart了,可是因爲這裏咱們說的是無人值守全自動安裝,因此先不修改default文件。
安裝DHCP服務並配置
yum -y install dhcp
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
接着修改/etc/dhcp/dhcpd.conf配置文件,文件最後修改內容以下:
最後啓動dhcp服務:/etc/init.d/dhcpd start
安裝Kickstart,同時配置system-config-kickstart
1)yum -y install system-config-kickstart
在圖形模式下配置Kickstart,以下
2)system-config-kickstart
運行上面的命令能夠對系統的一些基本配置進行設置,如時區,root密碼等
3)接下來要進行安裝了,建議選擇httpd安裝,切記不要輸入任何帳號,而是採用匿名安裝。在安裝過程當中,根據引導選擇安裝選項,不須要作更改。
4)安裝MBR
5)設置分區
6)配置網絡
7)認證配置
8)SELinux 和防火牆配置
9)圖形環境配置
10)軟件包安裝選擇
剩下的兩個是安裝前要運的腳本和安裝後要運行的腳本
11)最後將生成的ks.cfg文件保存到/var/www/html下,ks.cfg文件的配置方法爲自動化無人值守安裝的重點和難點,此文件稍有配置不當就須要人爲干預。
一併附上完整的ks.cfg文件,內容以下:
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://10.0.0.13/"
# Root password
rootpw --iscrypted $1$S1ifBkvb$GT.0H.quaeofa6G4mVgUq0
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=1024
part / --fstype="ext4" --grow --size=13800
修改/tftpboot/pxelinux.cfg/default文件,指定讀取ks.cfg的方法,即修改文件的第1行內容,改動後文件的第1行內容以下:
default linux
修改文件的第22行內容,改動後的內容以下:
append initrd=initrd.img ks=http://10.0.0.13/ks.cfg
另外,建意將timeout時間由原先的600改成1,timeout時間是引導時等待用戶手動選擇的時間,設爲」1「表示直接引導。
一併附上修改後的文件內容,以下:
default linux
#prompt 1
timeout 1
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.6!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append initrd=initrd.img ks=http://10.0.0.13/ks.cfg ksdevice=eth0 #ksdevice=eth0當客戶端有多個網卡時,務必加上此選項,不然系統會讓你手動選擇,這樣就失去了全自動無人值守安裝的意義了!
label vesa
menu label Install system with ^basic video driver
kernel vmlinuz
append initrd=initrd.img xdriver=vesa nomodeset
label rescue
menu label ^Rescue installed system
kernel vmlinuz
append initrd=initrd.img rescue
label local
menu label Boot from ^local drive
localboot 0xffff
label memtest86
menu label ^Memory test
kernel memtest
append -
啓動全部Kickstart須要的全部服務器後,就能夠開始」無人值守全自動化安裝CentOS系統「了。啓動命令以下:
/etc/init.d/httpd start
chkconfig httpd on
/etc/init.d/dhcpd start
chkconfig dhcpd on
/etc/init.d/xinetd restart
chkconfig xinetd on
附上無人值守安裝效果圖