1. 程式人生 > >Kickstart無人值守安裝CentOS

Kickstart無人值守安裝CentOS

centos kickstart pxe

一、準備工作

[[email protected] ~]# iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
[[email protected]
/* */ ~]# getenforce Disabled [[email protected] ~]# crontab -l 0 * * * * /usr/sbin/ntpdate 210.72.145.44 64.147.116.229 time.nist.gov [[email protected] ~]# hostname kickstart.contoso.com

相關服務器及服務說明如下:

角色IP地址服務說明
Kickstart服務器192.168.49.201apache,dhcp,tftp,kickstartVMware NAT網絡
Centos客戶端192.168.49.4
待安裝操作系統,pxe啟動

二、安裝過程

1、掛載CentOS 6.5系統盤

[[email protected] ~]# mount /dev/sr0 /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sr0 on /mnt type iso9660 (ro)

2、安裝apache並啟動服務

[[email protected] ~]# yum -y install httpd
[[email protected] ~]# rpm -qa |grep httpd
httpd-tools-2.2.15-59.el6.centos.x86_64
httpd-2.2.15-59.el6.centos.x86_64
[[email protected] ~]# /etc/init.d/httpd start

待服務啟動後,將/mnt下的光盤文件拷貝到/var/www/html中去(當然也可以省略這一步,可以配置apache的根目錄為/mnt即可,這裏為了不去修改apache配置所以添加該步驟):

cp -aR /mnt/* /var/www/html
[[email protected] ~]# ll /var/www/html/
total 324
-r--r--r-- 1 root root     14 Nov 29  2013 CentOS_BuildTag
dr-xr-xr-x 3 root root   4096 Nov 29  2013 EFI
-r--r--r-- 1 root root    212 Nov 28  2013 EULA
-r--r--r-- 1 root root  18009 Nov 28  2013 GPL
dr-xr-xr-x 3 root root   4096 Nov 29  2013 images
dr-xr-xr-x 2 root root   4096 Nov 29  2013 isolinux
-rw-r--r-- 1 root root   1126 Jul 14 01:58 ks.cfg
dr-xr-xr-x 2 root root 258048 Nov 29  2013 Packages
-r--r--r-- 1 root root   1354 Nov 28  2013 RELEASE-NOTES-en-US.html
dr-xr-xr-x 2 root root   4096 Nov 29  2013 repodata
-r--r--r-- 1 root root   1706 Nov 28  2013 RPM-GPG-KEY-CentOS-6
-r--r--r-- 1 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Debug-6
-r--r--r-- 1 root root   1730 Nov 28  2013 RPM-GPG-KEY-CentOS-Security-6
-r--r--r-- 1 root root   1734 Nov 28  2013 RPM-GPG-KEY-CentOS-Testing-6
-r--r--r-- 1 root root   3380 Nov 29  2013 TRANS.TBL

3、安裝tftp-server,並啟用tftp服務

[[email protected] ~]# yum -y install tftp-server
[[email protected] ~]# rpm -qa|grep tftp
tftp-server-0.49-8.el6.x86_64
[[email protected] ~]# sed -i ‘/disable/s/yes/no/‘ /etc/xinetd.d/tftp 
[[email protected] ~]# sed -n ‘/disable/p‘ /etc/xinetd.d/tftp 
disable= no
[[email protected] ~]# /etc/init.d/xinetd start
Starting xinetd:                                           [  OK  ]

4、準備pxe啟動所需文件

[[email protected] ~]# cp /var/www/html/images/pxeboot/initrd.img /var/lib/tftpboot/
[[email protected] ~]# cp /var/www/html/images/pxeboot/vmlinuz /var/lib/tftpboot/
[[email protected] ~]# cp /var/www/html/isolinux/*.msg /var/lib/tftpboot/
[[email protected] ~]# cp /var/www/html/isolinux/splash.jpg /var/lib/tftpboot/
[[email protected] ~]# cp /var/www/html/isolinux/vesamenu.c32 /var/lib/tftpboot/
[[email protected] ~]# mkdir /var/lib/tftpboot/pxelinux.cfg
[[email protected] ~]# cp /var/www/html/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

5、安裝syslinux並拷貝pxelinux.0文件

[[email protected] ~]# yum -y install syslinux
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package syslinux.x86_64 0:4.04-3.el6 will be installed
--> Processing Dependency: syslinux-nonlinux for package: syslinux-4.04-3.el6.x86_64
--> Processing Dependency: mtools for package: syslinux-4.04-3.el6.x86_64
--> Running transaction check
---> Package mtools.x86_64 0:4.0.12-1.el6 will be installed
---> Package syslinux-nonlinux.noarch 0:4.04-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================
 Package                     Arch             Version                 Repository      Size
===========================================================================================
Installing:
 syslinux                    x86_64           4.04-3.el6              base           346 k
Installing for dependencies:
 mtools                      x86_64           4.0.12-1.el6            base           194 k
 syslinux-nonlinux           noarch           4.04-3.el6              base           584 k
Transaction Summary
===========================================================================================
Install       3 Package(s)
Total download size: 1.1 M
Installed size: 2.5 M
Downloading Packages:
(1/3): mtools-4.0.12-1.el6.x86_64.rpm                               | 194 kB     00:00     
(2/3): syslinux-4.04-3.el6.x86_64.rpm                               | 346 kB     00:00     
(3/3): syslinux-nonlinux-4.04-3.el6.noarch.rpm                      | 584 kB     00:00     
-------------------------------------------------------------------------------------------
Total                                                      1.1 MB/s | 1.1 MB     00:01     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : mtools-4.0.12-1.el6.x86_64                                              1/3 
  Installing : syslinux-nonlinux-4.04-3.el6.noarch                                     2/3 
  Installing : syslinux-4.04-3.el6.x86_64                                              3/3 
  Verifying  : syslinux-4.04-3.el6.x86_64                                              1/3 
  Verifying  : syslinux-nonlinux-4.04-3.el6.noarch                                     2/3 
  Verifying  : mtools-4.0.12-1.el6.x86_64                                              3/3 
Installed:
  syslinux.x86_64 0:4.04-3.el6                                                             
Dependency Installed:
  mtools.x86_64 0:4.0.12-1.el6            syslinux-nonlinux.noarch 0:4.04-3.el6           
Complete!
[[email protected] ~]# rpm -ql syslinux-nonlinux
/usr/share/syslinux/altmbr.bin
/usr/share/syslinux/altmbr_c.bin
/usr/share/syslinux/altmbr_f.bin
/usr/share/syslinux/cat.c32
/usr/share/syslinux/chain.c32
/usr/share/syslinux/cmd.c32
/usr/share/syslinux/config.c32
/usr/share/syslinux/cpuid.c32
/usr/share/syslinux/cpuidtest.c32
/usr/share/syslinux/disk.c32
/usr/share/syslinux/dmitest.c32
/usr/share/syslinux/elf.c32
/usr/share/syslinux/ethersel.c32
/usr/share/syslinux/gfxboot.c32
/usr/share/syslinux/gptmbr.bin
/usr/share/syslinux/gptmbr_c.bin
/usr/share/syslinux/gptmbr_f.bin
/usr/share/syslinux/gpxecmd.c32
/usr/share/syslinux/gpxelinux.0
/usr/share/syslinux/gpxelinuxk.0
/usr/share/syslinux/hdt.c32
/usr/share/syslinux/host.c32
/usr/share/syslinux/ifcpu.c32
/usr/share/syslinux/ifcpu64.c32
/usr/share/syslinux/ifplop.c32
/usr/share/syslinux/int18.com
/usr/share/syslinux/isohdpfx.bin
/usr/share/syslinux/isohdpfx_c.bin
/usr/share/syslinux/isohdpfx_f.bin
/usr/share/syslinux/isohdppx.bin
/usr/share/syslinux/isohdppx_c.bin
/usr/share/syslinux/isohdppx_f.bin
/usr/share/syslinux/isolinux-debug.bin
/usr/share/syslinux/isolinux.bin
/usr/share/syslinux/kbdmap.c32
/usr/share/syslinux/linux.c32
/usr/share/syslinux/ls.c32
/usr/share/syslinux/lua.c32
/usr/share/syslinux/mboot.c32
/usr/share/syslinux/mbr.bin
/usr/share/syslinux/mbr_c.bin
/usr/share/syslinux/mbr_f.bin
/usr/share/syslinux/memdisk
/usr/share/syslinux/memdump.com
/usr/share/syslinux/meminfo.c32
/usr/share/syslinux/menu.c32
/usr/share/syslinux/pcitest.c32
/usr/share/syslinux/pmload.c32
/usr/share/syslinux/poweroff.com
/usr/share/syslinux/pwd.c32
/usr/share/syslinux/pxechain.com
/usr/share/syslinux/pxelinux.0
/usr/share/syslinux/reboot.c32
/usr/share/syslinux/rosh.c32
/usr/share/syslinux/sanboot.c32
/usr/share/syslinux/sdi.c32
/usr/share/syslinux/sysdump.c32
/usr/share/syslinux/syslinux.com
/usr/share/syslinux/syslinux.exe
/usr/share/syslinux/syslinux64.exe
/usr/share/syslinux/ver.com
/usr/share/syslinux/vesainfo.c32
/usr/share/syslinux/vesamenu.c32
/usr/share/syslinux/vpdtest.c32
/usr/share/syslinux/whichsys.c32
[[email protected] ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/

5、安裝dhcp並啟動服務

[[email protected] ~]# yum -y install dhcp
[[email protected] ~]# vi /etc/dhcp/dhcpd.conf
[[email protected] ~]# cat /etc/dhcp/dhcpd.conf 
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample
#   see ‘man 5 dhcpd.conf‘
#
ddns-update-style interim;            #設置DHCP服務器模式
ignore client-updates;                #禁止客戶端更新
log-facility local7;        #使用rsyslog記錄日誌
subnet 192.168.49.0 netmask 255.255.255.0 {
    range 192.168.49.3 192.168.49.30;      #地址池
    option routers 192.168.49.2;           #網關地址
    option subnet-mask 255.255.255.0;      #子網掩碼
    option domain-name-servers 192.168.49.2;    #設置DNS
    option domain-name "contoso.com";          #域名搜索列表
    default-lease-time 600;         #默認租約期限(單位秒)
    max-lease-time 7200;            #最大租約期限(單位秒)
    next-server 192.168.49.201;     #下一個訪問的服務器地址,tftp服務器地址
    filename "pxelinux.0";          #在next-server上需要下載的文件
}
[[email protected] ~]# service dhcpd configtest
Syntax: OK
[[email protected] ~]# dhcpd
Internet Systems Consortium DHCP Server 4.1.1-P1
Copyright 2004-2010 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Wrote 0 leases to leases file.
Listening on LPF/eth0/00:0c:29:c1:d4:3d/192.168.49.0/24
Sending on   LPF/eth0/00:0c:29:c1:d4:3d/192.168.49.0/24
Sending on   Socket/fallback/fallback-net
[[email protected] ~]# /etc/init.d/dhcpd start
[[email protected] ~]# /etc/init.d/dhcpd status
dhcpd (pid  1670) is running...

6、檢查相關服務運行情況並添加開機自啟動

[[email protected] ~]# /etc/init.d/httpd status
httpd (pid  1770) is running...
[[email protected] ~]# chkconfig httpd on
[[email protected] ~]# /etc/init.d/xinetd status
xinetd (pid  1585) is running...
[[email protected] ~]# chkconfig xinetd on
[[email protected] ~]# /etc/init.d/dhcpd status
dhcpd (pid  1670) is running...
[[email protected] ~]# chkconfig dhcpd on

7、準備ks.cfg文件

下面通過system-config-kickstart的圖形界面進行無人值守安裝設置,如果熟知ks.cfg文件的格式,可以自己寫腳本來完成,當然這裏只是示例。

因為system-config-kickstart需要在圖形界面下操作,所以首先要在操作系統中安裝圖形界面:

[[email protected] httpd]# yum -y groupinstall ‘X Window System‘
yum -y groupinstall ‘Desktop‘
yum -y groupinstall ‘Desktop Platform‘ ‘Desktop Platform Development‘ ‘Graphical Administration Tools‘

然後,使用yum安裝system-config-kickstart:

[[email protected] httpd]# yum install system-config-kickstart

最後,執行system-config-kickstart命令:

[[email protected] httpd]# system-config-kickstart

技術分享

基本設置,包含語言、時區、root密碼等信息,

技術分享

選擇安裝方式和安裝源,

技術分享

選擇安裝類型,GRUB選項以及安裝選項,

技術分享

磁盤分區相關選項,

技術分享

網絡配置選項,

技術分享

登錄認證方式設置,有多種認證方式可選,如NIS、LDAP、Kerberos5等等,

技術分享

防火墻設置,

技術分享

顯示配置,

技術分享

選擇軟件包,

技術分享

預安裝腳本,

技術分享

安裝後的處理腳本,

技術分享

選好之後,點擊“File",然後在下拉菜單中選擇“Save”,

技術分享

選擇文件保存位置,確定後選擇save保存。

[[email protected] httpd]# ll /var/www/html/ks.cfg 
-rw-r--r-- 1 root root 1126 Jul 14 01:58 /var/www/html/ks.cfg
[[email protected] httpd]# cat /var/www/html/ks.cfg 
#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
url --url="http://192.168.49.201/"
# Root password
rootpw --iscrypted $1$Y8sHozoZ$2BCNRpLHzBEab6Etd46hF1
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
graphical
# System keyboard
keyboard us
# System language
lang en_US
# 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/Chongqing
# 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
%packages
@base
@chinese-support
@development
cjkuni-fonts-ghostscript
dos2unix
%end

8、修改/var/lib/tftpboot/pxelinux.cfg/default,使客戶端自動加載ks.cfg配置

[[email protected] httpd]# vi /var/lib/tftpboot/pxelinux.cfg/default 
[[email protected] httpd]# cat /var/lib/tftpboot/pxelinux.cfg/default 
......
label linux
  menu label ^Install or upgrade an existing system
  menu default
  kernel vmlinuz
append initrd=initrd.img ks=http://192.168.49.201/ks.cfg text
......

三、測試

創建一個VMware虛擬機,網絡選擇NAT模式,然後不添加啟動影響,開機啟動

技術分享

開機看到這個畫面,很親切啊有木有,

技術分享

選擇鍵盤類型,

技術分享

選擇安裝方式,

技術分享

填寫kickstart服務器的地址,

技術分享

好吧,系統已經開始安裝了,

技術分享

安裝中,

技術分享

安裝接近尾聲,

技術分享

安裝結束,使用之前設置的密碼成功進入操作系統,因為沒有安裝圖形桌面,所以就是這樣的界面了,ok,至此成功結束。


本文出自 “IT小二郎” 博客,請務必保留此出處http://jerry12356.blog.51cto.com/4308715/1948715

Kickstart無人值守安裝CentOS