簡介:
批量安裝操作系統工具之 Kickstart ,RedHat 早前推出的產品( 不多說了,現在都玩 Cobbler 啦,見 http://www.linuxidc.com/Linux/2016-04/129977.htm?)。
測試環境:CentOS 6.6 x86_64 minimal
一、安裝軟件包
shell > yum -y install dhcp tftp-server syslinux nfs-utils kickstart
二、配置 DHCP
shell > cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
cp:是否覆蓋"/etc/dhcp/dhcpd.conf"? y
shell > vim /etc/dhcp/dhcpd.conf
# dhcpd.conf
# option definitions common to all supported networks...
option domain-name-servers 192.168.214.2, 202.106.46.151;
# A slightly different configuration for an internal subnet.
subnet 192.168.214.0 netmask 255.255.255.0 {
range 192.168.214.100 192.168.214.120;
option routers 192.168.214.2;
option subnet-mask 255.255.255.0;
filename "/pxelinux.0";
default-lease-time 600;
max-lease-time 7200;
}
三、配置 tftp
shell > vim /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no ## 原為 yes
per_source = 11
cps = 100 2
flags = IPv4
}
四、pxelinux.0
shell > cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
shell > mount /dev/cdrom /mnt/
shell > cp /mnt/isolinux/* /var/lib/tftpboot/
shell > cd /var/lib/tftpboot/
shell > mkdir pxelinux.cfg
shell > mv isolinux.cfg pxelinux.cfg/default
五、配置 NFS
shell > vim /etc/exports
/mnt 192.168.0.0/24(ro,sync)
六、最后的調整
shell > chkconfig --add nfs
shell > chkconfig --add dhcpd
shell > chkconfig --add xinetd
shell > chkconfig --add rpcbind
shell > chkconfig --level 35 nfs on
shell > chkconfig --level 35 dhcpd on
shell > chkconfig --level 35 xinetd on
shell > chkconfig --level 35 rpcbind on
shell > exportfs -ar
shell > service dhcpd restart
關閉 dhcpd: [確定]
正在啟動 dhcpd: [確定]
shell > service xinetd restart
停止 xinetd: [確定]
正在啟動 xinetd: [確定]
shell > service rpcbind restart
停止 rpcbind: [確定]
正在啟動 rpcbind: [確定]
shell > service nfs restart
關閉 NFS 守護進程: [確定]
關閉 NFS mountd: [確定]
關閉 NFS 服務: [確定]
Shutting down RPC idmapd: [確定]
啟動 NFS 服務: [確定]
啟動 NFS mountd: [確定]
啟動 NFS 守護進程: [確定]
正在啟動 RPC idmapd: [確定]
shell > setenforce 0
shell > service iptables stop
七、測試 PXE 引導安裝
1、客戶機設置從網絡引導(其實不用設置,本地找不到自然會去網絡找),就可以看到安裝界面
2、選擇語言( Chinese Simplified )
3、OK
4、選擇鍵盤( us )OK
5、選擇媒體位置( NFS Directory )OK
6、配置網絡( 默認即可 )OK
7、設置 NFS 服務( NFS server name: 192.168.214.10 ## NFS 服務器地址
CentOS directroy: /mnt ## ISO 存放位置 )OK
8、這里出現正常的安裝界面,證明沒有問題( 跟光盤安裝一模樣即可 )
## 這是實現了 PXE 引導安裝,想要無人干預還得配置 Kickstart !
八、安裝桌面環境
## 以下操作直接在虛擬機中執行,非終端連接 !(不是必要的)
shell > yum grouplist | grep -iP "(x window system|desktop)"
Desktop
X Winsow System
## 其中搜索出來的這兩個包是我們需要安裝的。
shell > yum update ## 首先需要更新一下 yum
shell > yum -y groupinstall "X Window System"
shell > yum -y groupinstall "Desktop"
shell > yum -y groupinstall "Chinese Support" ## 安裝中文支持
shell > init 5
## 現在已經進入桌面環境
1、設置字體(不是必須的)
## 打開終端時,默認顯示的字體簡直難看到極致,中間還有空格亂入,對處女座來說根本忍不了!
系統--首選項--外觀--字體--( 將等寬字體改為 AR PL UKai CN )--確定即可
2、安裝軟件包 system-config-kickstart
shell > yum -y install system-config-kickstart
shell > system-config-kickstart ## 啟動 Kickstart 配置程序
## 接下來就全是鼠標點點點啦 !
·基本配置
默認語言 :簡體中文,也可以默認 ( English )
鍵盤 :默認即可
時區 :Asia/Shanghai ,按實際情況來
UTC 時鐘 :勾選
根口令 :123456
確認根口令:123456
根口令加密:默認是勾上的,不用管
高級配置
安裝后重新引導系統:勾選
·安裝方法
執行新安裝:勾選
選擇 NFS :
NFS 服務器:192.168.214.10
NFS 目錄 :/mnt ## NFS 共享的 ISO 存放目錄
·引導裝載程序選項
安裝類型
安裝新引導裝載程序:勾選
安裝選項
在主引導記錄(MBR)上安裝引導裝載程序
·分區信息
主引導記錄
清除主引導記錄:勾選
分區
刪除所有現存分區:勾選
磁盤標簽
初始化磁盤標簽:勾選
布局
添加分區( 跟裝真機一樣 )
·網絡配置
添加網絡設備--網絡設備(eth0)--網絡類型(DHCP)--確認即可
·驗證
默認
·防火墻配置
全部禁用
·顯示配置
安裝圖形環境:不勾選(如果不想安裝的話)
禁用
·軟件包選擇
默認
·預安裝腳本
默認
·安裝后腳本
默認
選擇--文件--保存--(將文件保存到 /root 目錄下,文件名為 ks.cfg)
shell > mkdir /nfsdir
shell > cp ks.cfg /nfsdir
shell > chown 777 /nfsdir/ks.cfg
shell > vim /etc/exports
/mnt 192.168.214.0/24(ro,sync)
/nfsdir 192.168.214.0/24(ro,sync) ## 添加共享目錄
shell > exportfs -ar
shell > vim /var/lib/tftpboot/pxelinux.cfg/default
default vesamenu.c32
#prompt 1
timeout 50
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 ks=nfs:192.168.214.10:/nfsdir/ks.cfg initrd=initrd.img
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 -
## 其中,timeout 50 ( 這個參數原為 600 ,就是一進去系統時那個選擇模式的時間,我們不想等待太長時間所以調為 5 秒 )
## 在第一個 label 中加入了:ks=nfs:192.168.214.10:/nfsdir/ks.cfg ( 定義 ks.cfg 路徑 )
label linux
menu label ^Install or upgrade an existing system
menu default
kernel vmlinuz
append ks=nfs:192.168.214.10:/nfsdir/ks.cfg initrd=initrd.img
## 下面貼一下 ks.cfg 的文件內容( 不需要修改 )
shell > vim /nfsdir/ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use NFS installation media
nfs --server=192.168.214.10 --dir=/mnt
# Root password
rootpw --iscrypted $1$56NxQt/e$3fz.wnuWl7Ak7q9TIpwl0.
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
# System keyboard
keyboard us
# System language
lang zh_CN
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone --isUtc 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=1
4、重新啟動服務,測試無人值守
## 執行第 六 步操作
## 現在客戶機只需開機( 引導方式為網絡引導,其實不用設置,自己會去找的),即可 !
## 經測試沒問題 !
使用PXE+DHCP+Apache+Kickstart無人值守安裝CentOS5.8 x86_64 http://www.linuxidc.com/Linux/2012-12/76913p4.htm
Linux PXE無人值守安裝出現 PXE-E32:TFTP OPen timeout的解決辦法 http://www.linuxidc.com/Linux/2014-03/98986.htm
RHCE認證之無人值守安裝Linux系統(FTP+TFTP+DHCP+Kickstart+PXE) http://www.linuxidc.com/Linux/2013-10/91013.htm