什麼是KickStart
KickStart是一種無人職守安裝方式。KickStart的工作原理是通過記錄典型的安裝過程中所需人工干預填寫的各種參數,並生成一個名爲ks.cfg的文件;在其後的安裝過程中(不只侷限於生成KickStart安裝文件的機器)當出現要求填寫參數的情況時,安裝程序會首先去查找KickStart生成的文件,當找到合適的參數時,就採用找到的參數,當沒有找到合適的參數時,才需要安裝者手工干預。這樣,如果KickStart文件涵蓋了安裝過程中出現的所有需要填寫的參數時,安裝者完全可以只告訴安裝程序從何處取ks.cfg文件,然後去忙自己的事情。等安裝完畢,安裝程序會根據ks.cfg中設置的重啓選項來重啓系統,並結束安裝。
什麼是PXE
PXE(preboot execute environment)是由Intel公司開發的最新技術,工作於Client/Server的網絡模式,支持工作站通過網絡從遠端服務器下載映像,並由此支持來自網絡的操作系統的啓動過程,其啓動過程中,終端要求服務器分配IP地址,再用TFTP(trivial file transfer protocol)或MTFTP(multicast trivial file transfer protocol)協議下載一個啓動軟件包到本機內存中並執行,由這個啓動軟件包完成終端基本軟件設置,從而引導預先安裝在服務器中的終端操作系統。
網絡拓撲圖:
在機房中批量上線安裝服務器通常會使用如上圖所示的結構批量安裝,由於我們的工作電腦通常都是windows系統(office需要),所以再裝個VMware虛擬機,在虛擬機中架設PXE server不失爲一種好方法。
VMware workstation虛擬機的設置:安裝好CentOS並且虛擬機網絡連接方式爲橋接(bridge)
以下所有配置都在虛擬機中的CentOS完成:
使用PXE+Kickstart就可以製作網絡多機器自動安裝,網絡安裝的方式有三種:NFS、HTTP和FTP。綜合起來看,部署這樣的自動安裝環境需要的條件是:
1.DHCP 服務器
2.TFTP 服務器
3.KickStart所生成的ks.cfg配置文件
4.一臺存放系統安裝文件的服務器,如 NFS、HTTP 或 FTP 服務器
5.帶有一個 PXE 支持網卡的將安裝的主機
把系統安裝光盤mount到主機上
#mount /dev/cdrom /mnt/cdrom
安裝所需要的服務
yum -y install dhcp dhcp-devel nfs-utils nfs-utils-lib tftp tftp-server syslinux
配置TFTP,制定可供下載文件的目錄。
- 1、編輯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
- {
- disable = no #找到disable,修改其值爲no
- socket_type = dgram
- protocol = udp
- wait = yes
- user = root
- server = /usr/sbin/in.tftpd
- server_args = -s /tftpboot #此處爲TFTP提供下載的位置
- per_source = 11
- cps = 100 2
- flags = IPv4
- }
- 2,TFTP目錄建立與設置
- #mkdir /tftpboot
- #cp /usr/share/syslinux/pxelinux.0 /tftpboot/
- #mkdir /tftpboot/pxelinux.cfg
- #cp /mnt/cdrom/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
- #cp /mnt/cdrom/isolinux/* /tftpboot #把光盤中isolinux裏的所有文件複製到/tftpboot下
重啓動TFTP:service xinetd restart
DHCP服務器設置
- # DHCP Server Configuration file.
- # see /usr/share/doc/dhcp*/dhcpd.conf.sample
- # see 'man 5 dhcpd.conf'
- #
- #
- ddns-update-style interim;
- ignore client-updates;
- subnet 10.20.30.0 netmask 255.255.255.0 {
- option routers 10.20.30.1;
- option subnet-mask 255.255.255.0;
- option domain-name-servers 10.20.30.2;
- range dynamic-bootp 10.20.30.2 10.20.30.100;
- default-lease-time 21600;
- max-lease-time 43200;
- next-server 10.20.30.2; ###重要
- filename "pxelinux.0"; ###重要
- }
- 單就網絡安裝來說,只要在已經安裝配置好的DHCP服務器上添加指定服務器IP和指定pxelinux.0便可。
重啓動DHCP:service dhcpd restart
編輯/tftpboot/pxelinux.cfg/default
- default vesamenu.c32
- #prompt 1
- timeout 10 #超時時間
- display boot.msg
- menu background splash.jpg
- menu title Welcome to CentOS 6.3!
- 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=ftp://10.20.30.2/pub/ks.cfg initrdinitrd=initrd.img ## 設置重點
- append ks=nfs:10.20.30.2:/tftpboot/ks.cfg initrdinitrd=initrd.img ##設置重點
- label vesa
- menu label Install system with ^basic video driver
- kernel vmlinuz
- append initrdinitrd=initrd.img xdriver=vesa nomodeset
- label rescue
- menu label ^Rescue installed system
- kernel vmlinuz
- append initrdinitrd=initrd.img rescue
- label local
- menu label Boot from ^local drive
- localboot 0xffff
- label memtest86
- menu label ^Memory test
- kernel memtest
- append -
- ############FTP、NFS、HTTP三種安裝方式的配置路徑寫法##########
- ############主要是爲了讓安裝引導程序找到ks.cfg配置文件########
- ##############################################################
- # append ks=ftp://10.20.30.2/pub/ks.cfg initrdinitrd=initrd.img
- # append ks=nfs:10.20.30.2:/tftpboot/ks.cfg initrdinitrd=initrd.img
- # append ks=http://10.20.30.2/linux/ks.cfg initrdinitrd=initrd.img
- ##############################################################
對安裝光盤的定製
- #
- #/root/anaconda-ks.cfg . 安裝系統時由anaconda自動生成的ks.cfg文件
- #vi anaconda-ks.cfg
- # Kickstart file automatically generated by anaconda.
- #version=DEVEL
- install
- #cdrom
- lang en_US.UTF-8
- keyboard us
- network --onboot yes --device eth0 --bootproto dhcp --noipv6 #這裏我把它設置爲開機DHCP自動獲取IP,默認爲--onboot no。
- rootpw --iscrypted $6$FLLlvfqZKzvs/9bu$oflTVbcg8ZDgfCvBCDeyIBrgswymV7.W6ZoKc0Ona0GT/SCmBvMokbD2Ty86GH.qMOzXKlh6fTUQJRq4C50FC1
- firewall --service=ssh
- authconfig --enableshadow --passalgo=sha512
- selinux --enforcing
- timezone --utc Asia/Shanghai
- #url --url=ftp://10.20.30.2/pub ###FTP 的方式
- #nfs --server=10.20.30.2 --dir=/mnt/cdrom ###NFS的方式
- #url --url=http://10.20.30.2/linux ###HTTP的方式
- bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
- # The following is the partition information you requested
- # Note that any partitions you deleted are not expressed
- # here so unless you clear all partitions first, this is
- # not guaranteed to work
- zerombr #注意此處,清空MBR
- clearpart --all --initlabel #重新初始化硬盤分區
- part /boot --fstype=ext4 --size=200 #/boot分區,200M
- part swap --size=1024 #swap 分區,1024M
- part / --fstype=ext4 --grow --size=1 #根分區/,意爲剩下所有的空閒空間都留給/
- #repo --name="CentOS" --baseurl=cdrom:sr0 --cost=100 #暫未明白這是什麼意思,先註釋掉
- reboot #安裝完成後自動重啓
- %packages --nobase #這裏定義需要安裝的包
- @core #最小化安裝只有一個core就夠了。
- %post #%post後面可以接一些命令、腳本。如/bin/touch /root/test.cfg,安裝完成後會在/root目錄下看到test.cfg文件
- /bin/touch /root/test.cfg
- #######################################################
- #下面是我創建SSH 公鑰的腳本
- #######################################################
- if [ ! -d /root/.ssh ]; then
- mkdir /root/.ssh/
- fi
- if [ ! -f /root/.ssh/authorized_keys ]; then
- touch /root/.ssh/authorized_keys
- fi
- cat <<EOF > /root/.ssh/authorized_keys
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDDZCIIaD6lCRhmRY4wwdhLcqfstvd0aT90Py9g0RTtZxkh7NcJuR/+zupmQ0Bet3UW2sGfiP3JSviQvi82QK9+orh0IC+cCboE0usgSH89nra0LLc0y2Iv816lhjh5Dmn9ubfT5uCkgnJMIu10qUqZbu2b/ypMwMe/5jEFBdG89
- w
- EOF
- %end #必須的結束標誌
安裝方式之一:FTP
- 安裝vsftpd之後默認允許匿名訪問FTP公共目錄/var/ftp/pub,所以無需對vsftd配置文件進行修改。
- 只需要把ks.cfg文件和光盤中的所有文件複製到/var/ftp/pub就可以了。
- #cp /root/anaconda-ks.cfg /var/ftp/pub/ks.cfg
- #cp -a /mnt/cdrom/* /var/ftp/pub
- #分別修改ks.cfg和/tftpboot/pxelinux.cfg/default文件對應的方式
安裝方式之二:NFS
- 編輯NFS的配置文件,添加以下兩句
- /tftpboot *(ro,sync) #/tftpboot 可被網絡上任何主機讀取
- /mnt/cdrom *(ro,sync) #/mnt/cdrom 可被網絡上任何主機讀取
- 分別修改ks.cfg和/tftpboot/pxelinux.cfg/default文件對應的方式
安裝方式之三:HTTP
- 1,把ks.cfg和/mnt/cdrom裏的所有文件複製到apache指定的目錄下
- 2,分別修改ks.cfg和/tftpboot/pxelinux.cfg/default文件對應的方式