kickstart + tftp + dhcp + vsftp 做系統(tǒng)自動化安裝

kickstart + tftp + dhcp + vsftp 做系統(tǒng)自動化安裝

前期準備

關(guān)閉selinux

setenforce 0  #實時關(guān)閉(臨時)
sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config #永久關(guān)閉
getenforce #實時狀態(tài)

關(guān)閉firewalld

systemctl disalbe firewalld
systemctl stop firewalld
systemctl status firewalld

配置yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.def
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sed -i '/aliyuncs/d' /etc/yum.repos.d/CentOS-Base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
sed -i '/aliyuncs/d' /etc/yum.repos.d/epel.repo
掛載光盤或者ISO文件

mount /dev/cdrom /mnt
或者
mount -o loop /tmp/CentOS-7-x86_64-Everything-1611.iso /mnt

配置dhcp服務

yum -y install dhcp
默認/etc/dhcp/dhcpd.conf配置為空,需要使用/usr/share/doc/dhcp*/dhcpd.conf.example模板,刪除多余的subnet塊
修改/etc/dhcp/dhcpd.conf 配置文件,內(nèi)容如下:

subnet 10.1.1.0 netmask 255.255.255.0 { #所屬網(wǎng)段及掩碼;
range 10.1.1.100 10.1.1.200; #IP地址池范圍;
option domain-name-servers 114.114.114.114;  #DNS地址,多個可以中逗號隔開
option domain-name "linuxidc.seagate.com"; #域名服務器名稱
option routers 10.1.1.1; #網(wǎng)關(guān)IP;
option broadcast-address 10.1.1.255; #廣播地址
next-server 10.1.1.41; #TFTP Server 的IP地址;
filename "pxelinux.0"; #pxelinux 啟動文件位置;
default-lease-time 600; #默認租約時間
max-lease-time 7200; #最大租約時間
}

在多網(wǎng)卡的情況下綁定網(wǎng)卡啟動DHCP服務(選配)

[root@localhost pub]# cat /usr/lib/systemd/system/dhcpd.service 
[Unit]
Description=DHCPv4 Server Daemon
Documentation=man:dhcpd(8) man:dhcpd.conf(5)
Wants=network-online.target
After=network-online.target
After=time-sync.target

[Service]
Type=notify
ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid eno33554984

[Install]
WantedBy=multi-user.target

啟動DHCP服務

systemctl enable dhcpd.service
systemctl start dhcpd.service

安裝tftp

yum install tftp-server xinetd –y //此步驟會安裝兩個包,一個是tftp-server另一個是xinetd。
修改/etc/xinetd.d/tftp配置文件,內(nèi)容如下:

service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no #把這行改成no即可;
per_source = 11
cps = 100 2
flags = IPv4
}

啟動xinetd服務

systemctl enable xinetd.service
systemctl start xinetd.service

配置vsftp

yum -y install vsftpd
啟動vsftpd服務

systemctl start vsftpd.service
systemctl enable vsftpd.service

ftp提供系統(tǒng)盤遠程訪問
mkdir /var/ftp/centos73
cp -rf /mnt/* /var/ftp/centos73/

配置pxe(tftp服務提供支持)

yum -y install syslinux
說明:syslinux是一個功能強大的引導加載程序,而且兼容各種介質(zhì)。更加確切地說:SYSLINUX是一個小型的Linux操作系統(tǒng),它的目的是簡化首次安裝Linux的時間,并建立修護或其它特殊用途的啟動盤。
復制啟動文件到/var/lib/tftpboot

cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
cd /mnt/isolinux/
cp -rf initrd.img vmlinuz vesamenu.c32 boot.msg /var/lib/tftpboot/
cp isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default  #PXE Boot Menu,可自定義配置

檢查

# pwd
/var/lib/tftpboot
# ls
initrd.img pxelinux.0 pxelinux.cfg vesamenu.c32 vmlinuz boot.msg

生成sk.cfg文件

第一種:通過圖形界面工具system-config-kickstart生成

yum -y install system-config-kickstart

第二種:手動安裝一個系統(tǒng)后,在/root目錄有一個anaconda-ks.cfg文件,可做sk.cfg模板

配置root密碼
openssl passwd -1 -salt 'bacjin' '123456' #bacjin是附帶字符串,12345才是root密碼

[root@bktest tmp]# openssl passwd -1 -salt 'bacjin' '123456'
$1$bacjin$8uyHr/X68TmoE5QdTGpA6.

把輸出內(nèi)容替換如下iscrypted后面的字符串
rootpw --iscrypted $1$bacjin$8uyHr/X68TmoE5QdTGpA6.

把sk.cnf配置文件拷貝到ftp目錄中
cp /root/ks.cfg /var/ftp/

定制引導頁

編輯/var/lib/tftpboot/pxelinux.cfg/default文件
vim /var/lib/tftpboot/pxelinux.cfg/default

label linux
  menu label ^Install CentOS Linux 7
  menu default
  kernel vmlinuz
  append initrd=initrd.img inst.stage2=ftp://10.1.1.41/centos73 inst.ks=ftp://10.1.1.41/ks.cfg quiet
配置說明:
timeout 600 引導頁等待60秒后就使用默認選項
menu default 引導頁默認選擇項,重要
inst.stage2=ftp://10.1.1.41/centos73 inst.ks=ftp://10.1.1.41/ks.cfg  指定系統(tǒng)光盤和ks.cfg配置文件路徑

重啟服務

systemctl restart dhcpd
systemctl restart vsftp
systemctl restart xinetd

查看監(jiān)聽端口
netstat -tunpl

附帶ks.cnf配置

#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$bacjin$8uyHr/X68TmoE5QdTGpA6.
# Use network installation
url --url="ftp://10.1.1.41/iso"
# System language
lang en_US
# Firewall configuration
firewall --disabled
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# SELinux configuration
selinux --disabled

# Network information
network  --bootproto=dhcp --device=ens33
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all --initlabel
# Disk partitioning information
part swap --fstype="swap" --size=1024
part /boot --fstype="xfs" --size=200
part / --fstype="xfs" --grow --size=1


%packages
@base
@core
@desktop-debugging
@dial-up
@fonts
@gnome-desktop
@guest-agents
@guest-desktop-agents
@input-methods
@internet-browser
@kde-desktop
@multimedia
@print-client
@x11
%end

使用過程中的一些問題

1,ks.cnf如果是在cobbler中,就不能有中文
2, 光盤內(nèi)容其實可以直接掛載到/var/ftp中,不過要重啟vsftp才能看到里面的內(nèi)容,還不如自己復制進去,
3,同網(wǎng)絡(luò)中如果有多個DHCP服務就會有沖突,最好是在獨立的網(wǎng)段中,關(guān)閉路由器的DHCP服務
4,整個流程是
客戶機從DHCP獲取IP和tftp服務IP
再從tftp服務加載引導文件及引導頁
再通過引導選項加載不同的ks.cnf和系統(tǒng)盤
再按照ks.cnf安裝系統(tǒng)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內(nèi)容