理论生产环境中必定会有一次性装置多台服务器操作系统的工作,因而,光靠传统的一台台装置,很费时费力,数量不多的状况,还是比拟好应酬,如果一次是几十、几百台,就比拟麻烦了,因而,理论生产环境中都用采纳批量无人值守的装置形式来装置操作系统,所以明天来具体介绍下,通过利用kickstart+PXE+dhcp+nfs组合的形式批量装置操作系统。

1、原理与过程介绍

原理:

利用PXE协定应用服务器通过网络形式启动,后向DHCP服务器申请IP,连贯后将服务端的文件下载到本地,执行一零碎列的操作

过程:

第一步:PXE-client发送申请

将反对PXE启动形式的服务器设置成PXE启动,PEX客户端通过PXE boot ROM以udp的模式发送一个播送包,申请DHCP服务器调配IP地址

第二步:DHCP应答申请并回应

DHCP服务器收到申请后,验证是否来自非法的PXE客户端申请,验证通过后,回应PXE客户端,回应信息中包含调配的IP地址,pxelinux启动程序(TFTP)的地位,以及配置文件的地位

第三步:PXE-client申请下载启动文件

PXE客户端收到回应后,向TFTP服务器申请下载所需的启动零碎安装文件(文件包含:pxelinux.0、pxelinux.cfg/default、vmlinuz、initrd.img等文件)

第四步:TFTP服务器响应申请并传送文件

当TFTP服务器收到申请后,服务器会响应申请并应答申请,之后传送所需的文件给客户端

第五步:PXE-client申请下载自动应答文件

PXE客户端通过pxelinux.cfg/default文件成疏导linux装置后,安装程序必须先确定通过什么形式装置零碎,如果是通过网络,则会在此时进行初始化网络,并定位装置零碎所须要的二进制包以及配置文件的地位,接着读取文件中指定的自动应答文件ks.cfg,而后依据文件地位申请下载文件

第六步:客户端装置零碎

将ks.cfg下载到本地,通过文件找到装置零碎的ISO文件地位,并申请下载所需的软件包,失常连贯后,开始传输软件包,最终开始装置操作系统,装置实现后重新启动

2、配置NFS及共享目录


创立NFS共享目录

[root@kickserver ~]# mkdir /data/sys -p

创立零碎ISO文件挂载目录

[root@kickserver ~]# mkdir /isodir

将光盘挂载到挂载目录

[root@kickserver ~]# mount /dev/cdrom /isodirmount: block device /dev/sr0 is write-protected, mounting read-only[root@kickserver ~]# ls /isodir/CentOS_BuildTag  GPL Packages RPM-GPG-KEY-CentOS-6RPM-GPG-KEY-CentOS-Testing-6  EFI   images    RELEASE-NOTES-en-US.htmlRPM-GPG-KEY-CentOS-Debug-6   TRANS.TBL EULA  isolinux repodata   RPM-GPG-KEY-CentOS-Security-6

查看NFS是否装置

[root@kickserver ~]# rpm -qa |grep nfsnfs-utils-lib-1.1.5-11.el6.x86_64nfs-utils-1.2.3-70.el6_8.2.x86_64nfs4-acl-tools-0.3.3-8.el6.x86_64nfs-utils-lib-devel-1.1.5-11.el6.x86_64[root@kickserver ~]# rpm -qa |grep rpcbindrpcbind-0.2.0-12.el6.x86_64

配置nfs

[root@kickserver ~]# echo "/data/sys 172.16.1.235/24(ro,sync)" >>/etc/exports[root@kickserver ~]# echo "/isodir 172.16.1.235/24(ro,sync)" >>/etc/exports[root@kickserver ~]# tail -2 /etc/exports /data/sys 172.16.1.235/24(ro,sync)/isodir 172.16.1.235/24(ro,sync)

启动服务(留神先后顺序)

[root@kickserver ~]# /etc/init.d/rpcbind startStarting rpcbind:                      [  OK  ][root@kickserver ~]# /etc/init.d/nfs startStarting NFS services:             [  OK  ]Starting NFS quotas:               [  OK  ]Starting NFS mountd:              [  OK  ]Starting NFS daemon:              [  OK  ]Starting RPC idmapd:                [  OK  ][root@kickserver ~]# chkconfig rpcbind on[root@kickserver ~]# chkconfig nfs on[root@kickserver ~]# chkconfig --list |egrep "nfs|rcpbind"nfs  0:off 1:off 2:on 3:on 4:on 5:on 6:offnfslock 0:off 1:off 2:off 3:on 4:on 5:on6:off

查看配置

[root@kickserver ~]# showmount -eclnt_create: RPC: Port mapper failure - Timed out

呈现这个谬误提醒,首先查看防火墙是否敞开

[root@kickserver ~]# /etc/init.d/iptables statusiptables: Firewall is not running.

也可能是本地hosts解析的问题,批改下hosts文件

127.0.0.1 kickserver------>减少这个配置

[root@kickserver ~]# showmount -eExport list for kickserver:/isodir   172.16.1.235/24/data/sys 172.16.1.235/24

3、装置配置TFTP-server


[root@kickserver ~]# yum install tftp-server* -y

------------------------具体过程省略

配置TFTP服务器

[root@kickserver ~]# vi /etc/xinetd.d/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{        socket_type   = dgram        protocol         = udp        wait                = yes        user               = root        server           = /usr/sbin/in.tftpd        server_args  = -s /var/lib/tftpboot  disable       = yes------>批改成no        per_source     = 11        cps                 = 100 2        flags                = IPv4}

启动服务

[root@kickserver ~]# /etc/init.d/xinetd startStarting xinetd:                     [  OK  ][root@kickserver ~]# chkconfig xinetd on[root@kickserver ~]# chkconfig --list|grep xinetdxinetd 0:off1:off 2:on  3:on 4:on  5:on  6:off

4、配置PXE疏导(bootstarp)

[root@kickserver ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/  [root@kickserver ~]# ll /var/lib/tftpboot/-rw-r--r--. 1 root root 26759 Dec 13 16:07 /var/lib/tftpboot/pxelinux.0

拷贝网络内核启动文件

[root@kickserver ~]# cp /isodir/images/pxeboot/initrd.img /var/lib/tftpboot/[root@kickserver ~]# cp /isodir/images/pxeboot/vmlinuz /var/lib/tftpboot/[root@kickserver ~]# ll /var/lib/tftpboot/-r-xr-xr-x. 1 root root 4128368 Dec 13 16:12 vmlinuz-r--r--r--. 1 root root 33383679 Dec 13 16:11 initrd.img-rw-r--r--. 1 root root 26759 Dec 13 16:07 pxelinux.0

配置引导文件

[root@kickserver ~]# cd /var/lib/tftpboot/[root@kickserver tftpboot]# mkdir pxelinux.cfg[root@kickserver tftpboot]# cp /isodir/isolinux/isolinux.cfg ./pxelinux.cfg/default[root@kickserver tftpboot]# vi ./pxelinux.cfg/defaultmenu label ^Install or upgrade an existing systemdefault test#prompt 1timeout 600display boot.msgmenu background splash.jpgmenu title Welcome to CentOS 6.5!menu color border 0 #ffffffff #00000000menu color sel 7 #ffffffff #ff000000menu color title 0 #ffffffff #00000000menu color tabmsg 0 #ffffffff #00000000menu color unsel 0 #ffffffff #00000000menu color hotsel 0 #ff000000 #ffffffffmenu color hotkey 7 #ffffffff #ff000000menu color scrollbar 0 #ffffffff #00000000label test  kernel vmlinuz  append ks=nfs:172.16.1.235:/data/sys/kickstart/ks.cfg initrd=initrd.img test#减少此行配置文件

5、装置配置DHCP

[root@kickserver tftpboot]# yum install dhcp* -y

配置DHCP服务器

[root@kickserver tftpboot]# cd /etc/dhcp/[root@kickserver dhcp]# vi dhcpd.conf## DHCP Server Configuration file.#   see /usr/share/doc/dhcp*/dhcpd.conf.sample#   see 'man 5 dhcpd.conf'#ddns-update-style none;ignore client-updates;allow booting;allow bootp;default-lease-time 21600;max-lease-time 43200;option routers 172.16.1.1; subnet 172.16.1.0 netmask 255.255.255.0 { range dynamic-bootp 172.16.1.100 172.16.1.120;next-server 172.16.1.235; filename "/data/sys/kickstart/ks.cfg";next-server 172.16.1.235;filename "/var/lib/tftpboot/pxelinux.0";}减少上述标记局部的配置内容

启动服务

[root@centos6 dhcp]# /etc/init.d/dhcpd startStarting dhcpd:                            [  OK  ][root@centos6 dhcp]# chkconfig dhcpd on[root@centos6 dhcp]# chkconfig --list|grep dhcpddhcpd0:off 1:off 2:on 3:on 4:on5:on 6:off

6、装置配置kickstart

[root@centos6 dhcp]# mkdir /data/sys/kickstart -p#创立文件目录[root@centos6 dhcp]# cp /root/anaconda-ks.cfg /data/sys/kickstart/ks.cfg#拷贝配置文件[root@centos6 dhcp]# ll /data/sys/kickstart/ks.cfg-rw------- 1 root root 1229 Dec 13 18:16 /data/sys/kickstart/ks.cfg#批改默认权限,例其它用户可读[root@centos6 dhcp]# chmod 644 /data/sys/kickstart/ks.cfg[root@centos6 dhcp]# ll /data/sys/kickstart/ks.cfg       -rw-r--r-- 1 root root 1229 Dec 13 18:16 /data/sys/kickstart/ks.cfg

配置ks.cfg文件(重要步骤)

[root@centos6 dhcp]# cd /data/sys/kickstart/[root@centos6 kickstart]# vi ks.cfg # Kickstart file automatically generated by anaconda.#version=DEVELinstall#cdrom  #正文默认的装置形式,新增上面的配置nfs --server=172.16.1.235 --dir=/isodirlang en_US.UTF-8keyboard usnetwork --onboot no --device eth0 --bootproto dhcp --noipv6#rootpw  --iscrypted $6$zKfIpmK0g7MKWBVy$I8sk1Q8CAmkEA/zUwhNYC.A1DJOw6un2qbww2empzQx04DGjSvmLbZ2ESVMyOzU0DyT9qsz/IfNsD0Teim//N1rootpw 123456firewall --service=sshauthconfig --enableshadow --passalgo=sha512selinux --disabledtimezone --utc Asia/Shanghaibootloader --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#clearpart --all --drives=sda#part /boot --fstype=ext4 --size=500#part pv.008002 --grow --size=1#volgroup vg_centos6 --pesize=4096 pv.008002#logvol / --fstype=ext4 --name=lv_root --vgname=vg_centos6 --grow --size=1024 --maxsize=51200#logvol swap --name=lv_swap --vgname=vg_centos6 --grow --size=1984 --maxsize=1984zerombr#革除mbr疏导repo --name="CentOS"  --baseurl=cdrom:sr0 --cost=100%packages  #这个软件包可自行定义减少@base@compat-libraries@core@debugging@development@server-policy@workstation-policysgpiodevice-mapper-persistent-datasystemtap-client%end

7、配置PXE客户端疏导并启动服务器

重新启动服务器

能够分明的看到加载之前配置的文件

整个过程无需人工干预,全副自动化实现