1、无人值守自动安装系统是操作系统大规模的安装的方式,可以避免很多麻烦;
pex((preboot execute environment):预启动执行环境,有Inter公司开发,基于C/S模式的技术,能够让客户端通过网络去服务器端下载启动镜像,实习网络启动;在整个过程中,客户端会从服务器端得到IP地址,在利用TFTP服务下载镜像到本地的内存中并执行,在由这个启动文件完成终端你的各种配置;
kickstart:这个技术的核心是自动应答文件,就是在本来安装过程中需要我们手动设置的语言、密码、网络参数通过读取自动应答文件实现自动配置,所有需要提前把对操作系统的配置写入自动写入应答文件,开始安装操作系统时,自动安装程序自动读取应答文件,实现自动化安装;
而生成kickstart文件有如下三种方式;
手动编写kickstart文件;
通过system-config-kickstart图形化工具;
1:安装服务的服务器IP地址:192.168.149.132
1:安装DHCP服务:
[root@localhost_04 ~]# yum install -y dhcp
[root@localhost_04 ~]# vim /etc/dhcp/dhcpd.conf
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example
# see dhcpd.conf(5) man page
log-facility local7;
subnet 192.168.149.0 netmask 255.255.255.0 {
range 192.168.149.160 192.168.13.200; #指定获取动态地址池的IP地址段192.168.149.160-200;
option domain-name-servers 114.114.114.114; #指定DNS地址;
option routers 192.168.149.2; #指定网关地址;
default-lease-time 600; #默认租约时间;
max-lease-time 7200; #最大租约时间;
next-server 192.168.149.132; #TFTP地址;
filename "pxelinux.0"; #启动文件的名称是pxelinux.0;
}
注释:指定192.168.149.0/24这个段网络分配IP地址,动态地址池为192.168.149.160-200这四十个地址;客户端获取的网关是192.168.149.2,指定TFTP的地址是192.168.149.132,指定启动文件名称为 pxelinux.0;
启动DHCP服务;
[root@localhost_04 ~]# service dhcpd restart
Redirecting to /bin/systemctl restart dhcpd.service
[root@localhost_04 ~]# ps aux |grep dhcpd
dhcpd 55165 0.0 0.7 105912 7788 ? Ss 14:44 0:00 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
root 55167 0.0 0.0 112720 972 pts/0 R+ 14:44 0:00 grep --color=auto dhcpd[root@localhost_04 ~]# netstat -lnp|grep dhcp
udp 0 0 0.0.0.0:67 0.0.0.0:* 55165/dhcpd
raw 0 0 0.0.0.0:1 0.0.0.0:* 7 55165/dhcpd
2、安装TFTP服务;
[root@localhost_04 ~]# yum install -y tftp-server
[root@localhost_04 ~]# yum -y install xinetd
[root@localhost_04 ~]# vim /etc/xinetd.d/tftp
cat /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
启动tftp服务;
[root@localhost_04 ~]# service xinetd restart
Redirecting to /bin/systemctl restart xinetd.service
[root@localhost_04 ~]# ps aux |grep xinetd
root 55457 0.0 0.1 27164 1016 ? Ss 15:12 0:00 /usr/sbin/xinetd -stayalive -pidfile /var/run/xinetd.pid
root 55459 0.0 0.0 112720 972 pts/0 R+ 15:12 0:00 grep --color=auto xinetd
配置说明:共享路径为 /var/lib/tftpboot
3、安装引导程序:syslinux,并将客户端所需文件复制到TFTP服务器;
[root@localhost_04 ~]# yum install -y syslinux #安装引导程序;
[root@localhost_04 ~]# cp /usr/share/syslinux/p
pcitest.c32 pmload.c32 poweroff.com pwd.c32 pxechain.com pxelinux.0
[root@localhost_04 ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
4:挂载光盘或者ISO文件的系统到media中,将安装镜像中的启动镜像文件和启动配置文件复制到TFTP共享目录下;
[root@localhost_04 ~]# mount /dev/cdrom /media/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost_04 ~]# ls /media/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
[root@localhost_04 ~]# cp /media/isolinux/{vmlinuz,initrd.img} /var/lib/tftpboot/
注释:只拷贝isolinx目录下 vmlinuz和initrd.img这两个文件即可;
修改启动配置文件;
[root@localhost_04 ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
[root@localhost_04 ~]# cat !$
cat /var/lib/tftpboot/pxelinux.cfg/default
default linux
#prompt 1
timeout 600
display boot.msg
menu background splash.jpg
menu title Welcome to CentOS 6.5!
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=nfs:192.168.13.101:/ks/ks.cfg
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 -
注释:default指定默认引导方式,即以label开头的引导方式;
kernel 指定内核的引导文件,ks指定自动应答文件的位置,本例通过192.168.149.132的NFS共享的方式读取kickstart文件;
5:创建kickstart自动应答文件;
[root@localhost_04 ~]# mkdir /ks
[root@localhost_04 ~]# touch /ks/ks.cfg
[root@localhost_04 ~]# vim /ks/ks.cfg
cat /ks/ks.cfg
[root@localhost_04 ks]# cat ks.cfg
#platform=x86, AMD64, 或 Intel EM64T
#version=DEVEL
# 禁用防火墙规则iptables
firewall --disabled
# 安装系统
install
# nfs服务器地址ip,及nfs上的系统镜像路径
nfs --server=192.168.149.132 --dir=/media
# Root 密码(加密的123456)
rootpw --iscrypted $1$16PXgd.m$C4vE6OJCMGfQVadgm0DSe.
# System authorization information
auth --useshadow --passalgo=sha512
# 使用字符界面安装
#text
graphical
firstboot --disable
# 美式键盘
keyboard us
# 系统语言
lang en_US
# 关闭Selinux
selinux --disabled
# 不配置图形界面
skipx
# 安装日志记录级别为 info
logging --level=info
# 安装完成后重启
reboot
# 系统时区
timezone Asia/Shanghai
# 网络配置:动态获取ip、网卡名称eth0,开机自动启动网络服务,不开启ipv6,主机名(自定义,可以不写,默认localdomain:localhost)
network --bootproto=dhcp --device=eth0 --onboot=on --noipv6 --hostname=CentOS04
# 系统启动引导配置:mbr引导
bootloader --location=mbr
# 磁盘分区,zerombr:一定要有,不然安装的时候会停在格式化分区界面
zerombr
clearpart --all --initlabel
# 磁盘分区方式
part /boot --fstype="ext4" --size=200
part swap --fstype="swap" --size=2000
part / --fstype="ext4" --grow --size=1
# 安装完成后要执行的脚本
#%post
#/sbin/chkconfig --level 2345 network on
%packages
@base
%end
6:部署NFS;安装:
yum install -y nfs-utils
[root@localhost_04 ~]# service nfs start
Redirecting to /bin/systemctl start nfs.service
root 55804 0.0 0.0 112720 968 pts/0 R+ 15:20 0:00 grep --color=auto ngs
[root@localhost_04 ~]# ps aux |grep nfs
root 55777 0.0 0.0 0 0 ? S< 15:19 0:00 [nfsd4_callbacks]
root 55793 0.0 0.0 0 0 ? S 15:19 0:00 [nfsd]
root 55794 0.0 0.0 0 0 ? S 15:19 0:00 [nfsd]
root 55795 0.0 0.0 0 0 ? S 15:19 0:00 [nfsd]
root 55796 0.0 0.0 0 0 ? S 15:19 0:00 [nfsd]
root 55797 0.0 0.0 0 0 ? S 15:19 0:00 [nfsd]
root 55798 0.0 0.0 0 0 ? S 15:19 0:00 [nfsd]
root 55799 0.0 0.0 0 0 ? S 15:19 0:00 [nfsd]
root 55800 0.0 0.0 0 0 ? S 15:19 0:00 [nfsd]
root 55806 0.0 0.0 112720 972 pts/0 R+ 15:20 0:00 grep --color=auto nfs
7、首次安装开启客户机,不需要去修改Blos启动项,默认回去网络安装;