您的位置:首页 > 运维架构 > Apache

PXE+DHCP+Apache+Kickstart无人值守安装CentOS-6.6

2016-01-18 01:40 1116 查看
以前的工作中做过一次无人值守全自动批量安装Centos,无耐当时太忙,忘了做笔记。现在刚好公司新进了一批服务器要上架,要做系统,正好利用此次机会做了如下笔记:
什么是PXE?什么是Kickstart?此处不在一 一描述,因为网络上对这些概念解释实在是太多了,我就此对PXE+Kickstart的安装条件和详细步骤做一 阐述。
执行PXE+Kickstart安装需要先决条件:
DHCP服务器;

TFTP服务器;

Kickstart所生成的ks.cfg配置文件;

一台存放系统安装文件的服务器,如NFS、HTTP或FTP服务器;

一台带有支持PXE网卡启动的主机。

系以环境介绍:服务器系统为Centos-6.6_x86_64,ip地址为:10.0.0.13。由于服务器是最小化安装的,我们在后面要用到system-config-kickstart工具,它必须依赖于X Windows,所以我们要提前安装好X Windows及Desktop并重启系统,使其进入图形模式下。
一、环境准备
[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重启服务器

二、无人值守安装实战
挂载光盘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/images/pxeboot/initrd.img /tftpboot
cp /var/www/html/images/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

附上无人值守安装效果图













本文出自 “兰州linux运维” 博客,请务必保留此出处http://linuxzkq.blog.51cto.com/9379412/1736010
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: