之前的工做中作过一次无人值守全自动批量安装Centos,无耐当时太忙,忘了作笔记。如今恰好公司新进了一批服务器要上架,要作系统,正好利用这次机会作了以下笔记:html
什么是PXE?什么是Kickstart?此处不在一 一描述,由于网络上对这些概念解释实在是太多了,我就此对PXE+Kickstart的安装条件和详细步骤作一 阐述。linux
执行PXE+Kickstart安装须要先决条件:服务器
DHCP服务器;
网络
TFTP服务器;app
Kickstart所生成的ks.cfg配置文件;ide
一台存放系统安装文件的服务器,如NFS、HTTP或FTP服务器;工具
一台带有支持PXE网卡启动的主机。oop
系以环境介绍:服务器系统为Centos-6.6_x86_64,ip地址为:10.0.0.13。因为服务器是最小化安装的,咱们在后面要用到system-config-kickstart工具,它必须依赖于X Windows,因此咱们要提早安装好X Windows及Desktop并重启系统,使其进入图形模式下。url
1、环境准备spa
[root@test-A ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@test-A ~]# uname -m
x86_64
[root@test-A ~]# yum -y groupinstall 'X Window System'
[root@test-A ~]# yum -y groupinstall 'Desktop'
出错以下:
Error: samba4-common conflicts with samba-common-3.6.23-24.el6_7.x86_64
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
根据错误提示,及错误提示后面系统给出的解决方法为:
1.使用“--skip-broken"选项跳过上面错误;
2.尝试运行"rpm -Va --nofiles --nodigest",解决这上错误
[root@test-A ~]# rpm -Va --nofiles --nodigest #运行此命令,没有任何操做和提示,那么使用第一种方法直接跳过错误
[root@test-A ~]# yum -y groupinstall 'Desktop' --skip-broken #跳过或忽略上面的错误安装'Desktop',一切正常,呵呵
而后修改/etc/inittab文件并重启服务器,使其运行在图形模式下,主要修改的文件内容以下:
id:5:initdefault:
保存退出,init 6重启服务器
2、无人值守安装实战
挂载光盘ISO文件到/mnt/cdrom目录下,以下:
mkdir -p /mnt/cdrom
mount -o loop CentOS-6.6-x86_64-minimal.iso /mnt/cdrom #CentOS-6.6-x86_64-minimal.iso光盘镜像文件可自行下载
安装httpd
rpm -qa httpd #没安装的话就yum安装一下
yum -y install httpd httpd-tools
复制光盘ISO文件下的全部内容(文件和文件夹)到/var/www/html(此目录为Apache默认的DocumentRoot目录)下。
cp -rf /mnt/cdrom/* /var/www/html
安装tftp-server,并启用tftp服务,同时启动xinetd进程
1)安装tftp-server
yum -y install tftp-server
2)修改/etc/xinetd.d/tftp文件,将disable的值由yes变为no,以下:
3)重启xinetd进程
/etc/init.d/xinetd restart
配置支持PXE的启动程序(注意:前面已经将CentOS-6.6-x86_64光盘的内容复制到/var/www/html目录中了,因此只要从/var/www/html目录中复制须要的文件就好了)
mkdir /tftpboot
yum -y install syslinux
cp /usr/share/syslinux/pxelinux.0 /tftpboot
cp /var/www/html/p_w_picpaths/pxeboot/initrd.img /tftpboot
cp /var/www/html/p_w_picpaths/pxeboot/vmlinuz /tftpboot
cp /var/www/html/isolinux/*.msg /tftpboot/
mkdir /tftpboot/pxelinux.cfg
cp /var/www/html/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
注意:此时先不要修改default文件,虽然如今已经能够经过网络来引导并手动安装Kickstart了,可是因为这里咱们说的是无人值守全自动安装,因此先不修改default文件。
安装DHCP服务并配置
yum -y install dhcp
cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf
接着修改/etc/dhcp/dhcpd.conf配置文件,文件最后修改内容以下:
最后启动dhcp服务:/etc/init.d/dhcpd start
安装Kickstart,同时配置system-config-kickstart
1)yum -y install system-config-kickstart
在图形模式下配置Kickstart,以下
2)system-config-kickstart
运行上面的命令能够对系统的一些基本配置进行设置,如时区,root密码等
3)接下来要进行安装了,建议选择httpd安装,切记不要输入任何帐号,而是采用匿名安装。在安装过程当中,根据引导选择安装选项,不须要作更改。
4)安装MBR
5)设置分区
6)配置网络
7)认证配置
8)SELinux 和防火墙配置
9)图形环境配置
10)软件包安装选择
剩下的两个是安装前要运的脚本和安装后要运行的脚本
11)最后将生成的ks.cfg文件保存到/var/www/html下,ks.cfg文件的配置方法为自动化无人值守安装的重点和难点,此文件稍有配置不当就须要人为干预。
一并附上完整的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://10.0.0.13/"
# Root password
rootpw --iscrypted $1$S1ifBkvb$GT.0H.quaeofa6G4mVgUq0
# System authorization information
auth --useshadow --passalgo=sha512
# Use graphical install
graphical
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Installation logging level
logging --level=info
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# 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=13800
修改/tftpboot/pxelinux.cfg/default文件,指定读取ks.cfg的方法,即修改文件的第1行内容,改动后文件的第1行内容以下:
default linux
修改文件的第22行内容,改动后的内容以下:
append initrd=initrd.img ks=http://10.0.0.13/ks.cfg
另外,建意将timeout时间由原先的600改成1,timeout时间是引导时等待用户手动选择的时间,设为”1“表示直接引导。
一并附上修改后的文件内容,以下:
default linux
#prompt 1
timeout 1
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.6!
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 initrd=initrd.img ks=http://10.0.0.13/ks.cfg ksdevice=eth0 #ksdevice=eth0当客户端有多个网卡时,务必加上此选项,不然系统会让你手动选择,这样就失去了全自动无人值守安装的意义了!
label vesa
menu label Install system with ^basic video driver
kernel vmlinuz
append initrd=initrd.img xdriver=vesa nomodeset
label rescue
menu label ^Rescue installed system
kernel vmlinuz
append initrd=initrd.img rescue
label local
menu label Boot from ^local drive
localboot 0xffff
label memtest86
menu label ^Memory test
kernel memtest
append -
启动全部Kickstart须要的全部服务器后,就能够开始”无人值守全自动化安装CentOS系统“了。启动命令以下:
/etc/init.d/httpd start
chkconfig httpd on
/etc/init.d/dhcpd start
chkconfig dhcpd on
/etc/init.d/xinetd restart
chkconfig xinetd on
附上无人值守安装效果图