#############################
##### unit1自動安裝系統 #####
#############################
###################################
#### Network Install(HTTP,FTP,NFS) ####
###################################
#######1.kickstart腳本######
kickstart腳本是自動應答系統在安裝過程中一切問題的腳本文件
在這個文件可以實現系統的自動安裝
在系統安裝完畢後會在系統的root家目錄中生成
anaconda-ks.cfg這個文件就是以此係統爲模板生成的kickstart腳本
#######2.kickstart腳本的製作######
手動編寫kickstart的難度太大
系統中system-config-kickstart工具可以以圖形的方式製作kickstart
yum install system-config-kickstart -y##安裝kickstart圖形制作工具
system-config-kickstart ##打開圖形ks製作工具
ksvalidator ks.cfg##檢測ks語法(只能檢測語法錯誤)
補充注意:
因爲ks工具的自身bug,導致軟件包的安裝功能不能選擇。所以需要編輯/mnt/ks.cfg配置文件
vim /mnt/ks.cfg
38 %packages##安裝軟件包
39 @base##@表示組,base表示基本組。
此行表示只安裝基本組,即安裝之後的系統無圖形
40 %end
如果想要安裝圖形等軟件,可以參考真機家目錄下的anaconda-ks.cfg文件。
#######3.kickstart文件共享######
yum install httpd -y##通過http協議共享ks文件
systemctl stop firewalld.server
systemctl enable firewalld.server
systemctl start httpd
systemctl enable httpd
cp /mnt/ks.cfg /var/www/html##/var/www/html是http服務器默認的發佈路徑
######4.安裝虛擬機#####
[root@localhost ~]#virt-install \
> --name kstest \
> --ram 1000 \
> --file /var/lib/libvirt/images/kstest.qcow2 \
> --file--size 8 \
> --extra-args "ks=http://172.25.254.119/ks.cfg" &##安裝時查看的ks文件
##############################
######Network Boot(PXE)#######
##############################
######1.PXE網絡安裝的相應軟件安裝######
[root@localhost ~]# yum whatprovides */pxelinux.0
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
syslinux-4.05-12.el7.x86_64 : Simple kernel loader which boots
: from a FAT filesystem
Repo : SOURCE
Matched from:
Filename : /usr/share/syslinux/pxelinux.0
syslinux-4.05-12.el7.x86_64 : Simple kernel loader which boots
: from a FAT filesystem
Repo : @SOURCE
Matched from:
Filename : /usr/share/syslinux/pxelinux.0
##通過yum whatprovides查看pxelinux.0文件的安裝包叫做syslinux
[root@localhost ~]# yum install dhcp tftp-server syslinux httpd xinetd.x86_64 -y
[root@localhost ~]# systemctl stop firewalld.service
[root@localhost ~]# systemctl disable firewalld.service
[root@localhost ~]# vim /etc/xinetd.d/tftp
14 disable = yes
|| 改爲
\/
14 disable = no
[root@localhost ~]# systemctl restart xinetd.service
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
########2.必須文件的下載複製########
[root@localhost ~]# rpm -ql syslinux |grep pxelinux.0##查詢軟件生成文件
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/pxelinux.0##這個是配置文件
[root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/##將該配置文件(即pxe啓動的所有配置文件)複製到tftp server的默認目錄下
將linux系統的iso鏡像掛載到/var/lib/tftpboot/下,或者將iso裏的文件複製到/var/lib/tftpboot/
由於該實驗是用虛擬機作爲tftp server的所以可以用給虛擬即加光驅的方式添加系統iso鏡像:(方式如圖)
[root@localhost ~]# cd /var/lib/tftpboot/##切換到/var/lib/tftpboot/目錄下
[root@localhost tftpboot]# mkdir pxelinux.cfg##創建pxelinux.cfg文件
[root@localhost tftpboot]# ls##查看默認目錄下的文件和目錄
boot.cat isolinux.bin pxelinux.cfg vesamenu.c32
boot.msg isolinux.cfg splash.png vmlinuz
grub.conf memtest TRANS.TBL
initrd.img pxelinux.0 upgrade.img
[root@localhost tftpboot]# cp isolinux.cfg pxelinux.cfg/default##將引導界面配置文件放到pxe啓動的引導界面的默認配置文件目錄下
##因爲pxe啓動讀取的文件是pxelinux.cfg文件,而用iso啓動則讀取的是
########3.dhcp server的配置##########
[root@localhost dhcp]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
[root@localhost dhcp]# vim dhcpd.conf
(刪除27,28行)
7 option domain-name "localhost.localdomain";
8 option domain-name-servers 172.25.254.250; ##dns服務器地址
32 subnet 172.25.254.0 netmask 255.255.255.0 {##dhcp的網段,和子網掩碼
33 range 172.25.254.200 172.25.254.220;##地址池
34 option routers 172.25.254.19;##網關
35 next-server 172.25.254.119;##tftp server地址
36 filename "pxelinux.0";##配置文件名
37 }
[root@localhost tftpboot]# systemctl restart dhcpd
[root@localhost tftpboot]# vim pxelinux.cfg/default##編輯pxe安裝引導界面的配置
2 timeout 600##引導界面上顯示的多少秒不操作之後按默認選項啓動
11 menu title Red Hat Enterprise Linux 7.2##引導界面的標題
61 label linux
62 menu label ^Install Red Hat Enterprise Linux 7.2
63 kernel vmlinuz
64 append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2 \x20Server.x86_64 quiet
65
66 label check
67 menu label Test this ^media & install Red Hat Enterpri se Linux 7.2
68 menu default##默認選擇該選項
69 kernel vmlinuz
70 append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2\x20Server.x86_64 rd.live.check quiet
##引導界面的菜單的選項
||
||
\/
61 label linux
62 menu label ^Install Red Hat Enterprise Linux 7.1
63 kernel vmlinuz
64 menu default##默認選擇該選項
65 append initrd=initrd.img repo=ftp://172.25.254.119/pub /rhel7.1 ks=172.25.254.119/ks.cfg##設置repo和ks文件的路徑
66
67 label check
68 menu label Test this ^media & install Red Hat Enterpri se Linux 7.2
69 kernel vmlinuz
70 append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.2 \x20Server.x86_64 rd.live.check quiet