Linux系統無人值守全自動安裝html
centos or redhat 7及以上python
dhcp:給須要安裝的系統分配及規劃地址段,同時指定tftp地址以及pxelinux.0路徑linux
tftp、tftp-server:提供引導文件與系統安裝所必須的文件vim
httpd or vsftpd: 提供網絡安裝的系統鏡像windows
syslinux: 提供引導文件centos
system-config-kickstart: 製做系統自動安裝的文件bash
全部須要安裝的機器網卡支持pxe網絡
主板支持網絡啓動引導app
二層網絡已打通less
pxe安裝圖示過程:
pxe+kicakstart實現圖示過程:
5.1 pxe+kickstart測試環境
我這採用VMware和virt-manager軟件來實現,VMware貌似有bug,建立選擇系統類型時得選擇windows(virtualbox同樣)
系統:centos7.2
網卡:我設置了兩張,一張採用nat鏈接外網配置環境,網段192.168.192.0/24
另一張採用自定義虛擬網絡,內部pxe安裝使用,網段192.168.70/24
5.2禁用selinux以及firewall
setenforce 0 #臨時使用
sed –I 's/SELINUX=enforcing/SELINUX=disabled/g' #永久
systemctl stop firewalld
systemctl disable firewalld
5.3軟件安裝
yum -y install dhcp tftp tftp-server vsftp syslinux system-config-kickstart
5.4配置
5.4.1 dhcp
[root@localhost ~]# cat /etc/dhcp/dhcpd.conf
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
allow booting;
allow bootp;
dns-update-style interim;
ignore client-updates;
subnet 192.168.70.0 netmask 255.255.255.0
{
range 192.168.70.10 192.168.70.100;
option domain-name-servers 192.168.70.128;
option routers 192.168.70.128;
default-lease-time 21600;
max-lease-time 43200;
#指定TFTP server地址
next-server 192.168.70.128;
#指定pxelinux啓動文件位置,和TFTP一塊兒
filename "pxelinux.0";
}
5.4.2 tftp
須要安裝的系統ISO掛載
tftp默認由守護進程xinetd管控,若是沒有的話能夠安裝
yum –y install xinetd
[root@localhost tftpboot]# cat /etc/xinetd.d/tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol. The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
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改爲no
per_source = 11
cps = 100 2
flags = IPv4
}
拷貝系統文件至tftp下
包括:
內核文件:vmlinuz initrd.img
引導菜單配置文件: isolinux.cfg
系統自帶的兩種窗口模塊之一:vesamenu.c32
窗口提示信息文件:boot.msg
窗口背景圖片:splash.png
cp /mnt/cdrom/isolinux/* /var/lib/tftpboot/
mkdir /var/lib/tftpboot/pxelinux.cfg
拷貝引導菜單文件至此目錄下
mv /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
拷貝引導文件至tftp默認目錄下
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot
修改引導菜單文件
vim /var/lib/tftpboot/pxelinux.cfg/default
主要修改以下信息
timeout 600 #引導界面等到時間,默認60s
能夠修改成 timeout 100 默認等待10s
引導界面的顯示項
label linux
menu label ^Install CentOS Linux 7
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 quiet
label check
menu label Test this ^media & install CentOS Linux 7
menu default
kernel vmlinuz
append initrd=initrd.img inst.stage2=hd:LABEL=CentOS\x207\x20x86_64 rd.live.check quiet
menu separator # insert an empty line
# utilities submenu
menu begin ^Troubleshooting
menu title Troubleshooting
.
.
.
menu end
上述東西其實均可以刪掉,若是你肯定安裝內容的話,留下第一段label便可
以下:
label linux
menu label ^Install CentOS Linux 7
kernel vmlinuz
menu default #默認以此啓動項啓動,不然不會自動進入
append initrd=initrd.img ks=ftp://192.168.70.128/pub/dvd/ks.cfg quiet
#指定無人值守安裝啓動的文件ks.cfg,此文件指定了系統以怎樣的方式安裝
此文件必要的東西必須得所有設定好,不然會致使沒法自動安裝
完成上述東西,已經能夠拿到地址,經過pxe進入系統安裝界面,可是以怎麼樣的方式安裝以及安裝文件尚未準備
5.4.3 ftp
ftp存放系統鏡像文件,固然也能夠用http或者nfs均可以
ftp默認目錄/var/ftp/pub/
mkdir /var/ftp/pub/dvd
cp /mnt/cdrom/* /var/ftp/pub/dvd
此ftp沒有沒有作任何權限控制,因此這樣就能夠了
5.4.4 system-config-kickstart
生成無人值守安裝文件(這個製做過程得具有圖形界面才行)
執行system-config-kickstart
過程不在贅述,有兩個注意事項
這個地方要想選擇到指定安裝的包,yum倉庫文件的第一個名字必須爲development
[root@localhost pxelinux.cfg]# cat /etc/yum.repos.d/local.repo
[development]
name=local
baseurl=file:///mnt/cdrom
弄完以後記得保存,自己是沒有保存按鈕的,保存到指定目錄便可
查看ks.cfg文件
cp /root/ks.cfg /var/ftp/pub/dvd
最小化安裝文件以下:
[root@localhost dvd]# cat ks.cfg-bak20190505
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
text
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$Aa.OZSX8$eOmsbrStc.BKV4FmtpyuQ.
# Use network installation
url --url="ftp://192.168.70.128/pub/dvd"
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Firewall configuration
firewall --disabled
# Network information
network --bootproto=dhcp --device=eth0
# 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
# Disk partitioning information
part /boot --fstype="xfs" --size=800
part / --fstype="xfs" --size=7100
part swap --fstype="swap" --size=2048
%packages
%end
圖形化界面安裝以及指定一些其餘服務
[root@localhost dvd]# cat ks.cfg
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$yrN7JsmC$mHFf1GnWpdspcxBFzabsd0
# Use network installation
##指定安裝文件的位置
url --url="ftp://192.168.70.128/pub/dvd"
# System language
lang en_US
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
#圖形化界面安裝
graphical
firstboot --disable
# SELinux configuration
selinux –disabled
#指定主機名字
network --hostname=Centos7.contoso.com
#建立指定永不
user --groups=wheel --name=tony --gecos="tony"
# Firewall configuration
firewall --disabled
# Network information
#建立網卡名字
network --bootproto=dhcp --device=eth0
# 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 /boot --fstype="xfs" --size=800
part / --fstype="xfs" --size=8196
part swap --fstype="swap" --size=2048
#安裝的包,%packages開始,%end結束,@表明組安裝,-單個服務安裝
%packages
@base
@gnome-desktop
@virtualization-client
@virtualization-hypervisor
@virtualization-platform
@virtualization-tools
-abrt-addon-ccpp
-abrt-addon-python
-abrt-cli
-abrt-console-notification
-bash-completion
-blktrace
-bridge-utils
-bzip2
-chrony
-cryptsetup
-dmraid
-dosfstools
-ethtool
-fprintd-pam
-gnupg2
-hunspell
-hunspell-en
-kpatch
-ledmon
-libaio
-libreport-plugin-mailx
-libstoragemgmt
-lvm2
-man-pages
-man-pages-overrides
-mdadm
-mlocate
-mtr
-nano
-ntpdate
-pinfo
-plymouth
-pm-utils
-rdate
-rfkill
-rng-tools
-rsync
-scl-utils
-setuptool
-smartmontools
-sos
-sssd-client
-strace
-sysstat
-systemtap-runtime
-tcpdump
-tcsh
-teamd
-time
-unzip
-usbutils
-vim-enhanced
-virt-what
-wget
-which
-words
-xfsdump
-xz
-yum-langpacks
-yum-utils
-zip
%end
只作簡單的部分截圖
客戶端進入DHCP獲取階段
DHCP獲取成功,進入引導菜單界面
啓動基本的內核,開始傳送安裝文件
進入自動安裝界面
利用cobbler實現,見別人文檔:https://www.cnblogs.com/zhangxingeng/p/9702625.html
cobbler+dhcp or dnsmasq+tftp+http+rsync