PEX自动化安装CentOS7之Kickstart

最近公司线上采购一批服务器(100台),上架后需要自己安装操作系统,部署相关软件环境,安装常规思路直接一台一台部署,但是100台一台一台的安装耗时不说,而且安装过程中有可能出现环境安装不一致,所以思来想去,决定采用网络批量部署,但是常规的网络批量部署需要我们用鼠标和键盘一台一台去点鼠标和选择对应的选项,那么有没有方便实用而且又简单的方法呢?答案是肯定的:  Kickstart 和Cobbler

在介绍具体安装方法之前,我们先来了解一下什么是pxe,pxe能干什么,Kickstart是什么,Cobbler又有什么特别。

一、什么是PEX?

  1. PXE,全名Pre-boot Execution Environment,预启动执行环境;
  2. 通过网络接口启动计算机,不依赖本地存储设备(如硬盘)或本地已安装的操作系统;
  3. 由Intel和Systemsoft公司于1999年9月20日公布的技术;
  4. Client/Server的工作模式;
  5. PXE客户端会调用网际协议(IP)、用户数据报协议(UDP)、动态主机设定协议(DHCP)、小型文件传输协议(TFTP)等网络协议;
  6.  PXE客户端(client)这个术语是指机器在PXE启动过程中的角色。一个PXE客户端可以是一台服务器、笔记本电脑或者其他装有PXE启动代码的机器(我们电脑的网卡)。

二、PXE工作过程大概如下

  1.        pxe客户端向DHCP服务器发送广播请求,该广播包为UDP,请求IPD地址信息
  2.        DHCP服务器向pxe客户端返回请求的IP地址信息和PXE文件位置存放位置信息(一般位于tftp服务器上)
  3.       pxe客户端向TFTP服务器发送pxelinux.0文件的请求信息
  4.       TFTP服务器发回给PXE客户端pxelinux.0文件相关信息
  5.       pxe客户端执行pxelinux.0文件内容
  6.       pxe客户端再次向TFTP请求配置文件pxelinux.cfg的相关信息
  7.       TFTP服务器发送pxelinux.cfg配置文件到pxe客户端
  8.      pxe客户接收到pxelinux.cfg配置文件后读取之
  9.      pxe客户端再次向TFTP请求vmlinuz
  10.      TFTP响应请求返回pxe客户端vmlimuz文件
  11.      pxe客户端最后向TFTP服务器请求initrd.img文件
  12.      TFTP响应pxe请求并返回initrd.img文件给pxe客户端
  13.      pxe客户端读取Linux内核,然后启动安装程序

这里借用老男孩教育流程图:

          

具体分解为:

a、 PXE Client向DHCP发送请求
PXE Client从自己的PXE网卡启动,通过PXE BootROM(自启动芯片)会以UDP(简单用户数据报协议)发送一个广播请求,向本网络中的DHCP服务器索取IP。

b、DHCP服务器提供信息
DHCP服务器收到客户端的请求,验证是否来至合法的PXE Client的请求,验证通过它将给客户端一个“提供”响应,这个“提供”响应中包含了为客户端分配的IP地址、pxelinux启动程序(TFTP)位置,以及配置文件所在位置。

c、PXE客户端请求下载启动文件
客户端收到服务器的“回应”后,会回应一个帧,以请求传送启动所需文件。这些启动文件包括:pxelinux.0、pxelinux.cfg/default、vmlinuz、initrd.img等文件。

d、Boot Server响应客户端请求并传送文件
当服务器收到客户端的请求后,他们之间之后将有更多的信息在客户端与服务器之间作应答, 用以决定启动参数。BootROM由TFTP通讯协议从Boot Server下载启动安装程序所必须的文件(pxelinux.0、pxelinux.cfg/default)。default文件下载完成后,会根据该文件中定义的引导顺序,启动Linux安装程序的引导内核。

e、请求下载自动应答文件
客户端通过pxelinux.cfg/default文件成功的引导Linux安装内核后,安装程序首先必须确定你通过什么安装介质来安装linux,如果是通过网络安装(NFS, FTP, HTTP),则会在这个时候初始化网络,并定位安装源位置。接着会读取default文件中指定的自动应答文件ks.cfg所在位置,根据该位置请求下载该文件。

 这里有个问题:
    在第2步和第5步初始化2次网络了,这是由于PXE获取的是安装用的内核以及安装程序等,而安装程序要获取的是安装系统所需的二进制包以及配置文件。因此PXE模块和安装程序是相对独立的,PXE的网络配置并不能传递给安装程序,从而进行两次获取IP地址过程,但IP地址在DHCP的租期内是一样的。

f、客户端安装操作系统
将ks.cfg文件下载回来后,通过该文件找到OS Server,并按照该文件的配置请求下载安装过程需要的软件包。
OS Server和客户端建立连接后,将开始传输软件包,客户端将开始安装操作系统。安装完成后,将提示重新引导计算机。

 三、批量装机软件介绍

Kickstart和Cobbler都属于红帽(redhat)下的开源工具

     Kickstart是一种无人值守的安装方式。它的工作原理是在安装过程中记录人工干预填写的各种参数,并生成一个名为ks.cfg的文件。如果在自动安装过程中出现要填写参数的情况,安装程序首先会去查找ks.cfg文件,如果找到合适的参数,就采用所找到的参数;如果没有找到合适的参数,便会弹出对话框让安装者手工填写。所以,如果ks.cfg文件涵盖了安装过程中所有需要填写的参数,那么安装者完全可以只告诉安装程序从何处下载ks.cfg文件,然后就去忙自己的事情。等安装完毕,安装程序会根据ks.cfg中的设置重启/关闭系统,并结束安装。

Cobbler集中和简化了通过网络安装操作系统需要使用到的DHCP、TFTP和DNS服务的配置。Cobbler不仅有一个命令行界面,还提供了一个Web界面,大大降低了使用者的入门水平。Cobbler内置了一个轻量级配置管理系统,但它也支持和其它配置管理系统集成,如Puppet,暂时不支持SaltStack。

** 简单的说,Cobbler是对kickstart的封装,简化安装步骤、使用流程,降低使用者的门槛。**

四、安装准备环境:

 1 [root@localhost ~]# cat /etc/redhat-release 
 2 CentOS Linux release 7.2.1511 (Core) 
 3 [root@localhost ~]# systemctl status firewalld
 4 ● firewalld.service - firewalld - dynamic firewall daemon
 5    Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
 6    Active: inactive (dead)
 7 [root@localhost ~]#
 8 [root@localhost ~]# getenforce
 9 Disabled
10 [root@localhost ~]#
1 [root@localhost ~]# ifconfig enp2s0|grep inet
2         inet 10.0.10.11  netmask 255.255.255.0  broadcast 10.0.10.255
3         inet6 fe80::62a4:4cff:fe7b:7d5f  prefixlen 64  scopeid 0x20<link>
4 [root@localhost ~]# 

注意:

      我这里的网络环境为一台两台PC直接和交换机连接,如果用虚拟机,网卡采用NAT模式,不能使用桥接模式,因为后面我们要搭建一个DHCP服务器,如果一个网段里有两个DHCP服务会有冲突。

      VMware的NAT模式的DHCP服务也要关闭,避免干扰。

      

五、部署DHCP、TFTP、HTTP服务

  ①DHCP部署

 1 [root@localhost ~]# yum install httpd -y
 2 [root@localhost ~]# cat /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.ori
 3 [root@localhost ~]# cat /etc/dhcp/dhcpd.conf
 4 #
 5 # DHCP Server Configuration file.
 6 #   see /usr/share/doc/dhcp*/dhcpd.conf.example
 7 #   see dhcpd.conf(5) man page
 8 #
 9 authoritative;
10 subnet 10.0.10.0 netmask 255.255.255.0 {
11 range 10.0.10.100 10.0.10.200;
12 option subnet-mask 255.255.255.0;
13 default-lease-time 21600;
14 max-lease-time 43200;
15 next-server 10.0.10.101;
16 filename "/pxelinux.0";
17 }
18 [root@localhost ~]# 
19 
20 说明:
21 subnet 10.0.10.0 netmask 255.255.255.0 #子网地址划分
22 range 10.0.10.100 10.0.10.200          #可分配的IP地址范围
23 option subnet-mask 255.255.255.0       #设定子网掩码
24 default-lease-time 21600               #默认IP地址租用时间段
25 max-lease-time 43200                   #最大的IP地址租用时间段
26 next-server 10.0.10.101                #告诉pxe客户端TFTP服务器的IP
27 filename "/pxelinux.0";                #告诉pxe客户端从TFTP跟目录下载pxelinux.0文件
28 
29 [root@localhost ~]# netstat -lnupt|grep dhcp
30 udp        0      0 0.0.0.0:67              0.0.0.0:*                           3667/dhcpd
31 [root@localhost ~]#
32 
33 DHCP指定监控网卡:
34 [root@localhost ~]# vim /etc/sysconfig/dhcpd
35 # Command line options here
36 DHCPDARGS=eth1                        #指定监听网卡
37 
38 [root@localhost ~]# systemctl restart dhcpd
39 [root@localhost ~]# ps xua|grep dhcpd
40 dhcpd     3950  0.1  0.2 103012  7620 ?        Ss   16:51   0:00 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid
41 root      3952  0.0  0.0 112644   948 pts/1    S+   16:51   0:00 grep --color=auto dhcpd
42 [root@localhost ~]# 

②TFTP服务部署

   TFTP(Trivial File Transfer Protocol,简单文件传输协议)是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务。端口号为69。

 1 [root@localhost ~]# yum install tftp-server
 2 [root@localhost ~]# cat /etc/xinetd.d/tftp 
 3 # default: off
 4 # description: The tftp server serves files using the trivial file transfer \
 5 #       protocol.  The tftp protocol is often used to boot diskless \
 6 #       workstations, download configuration files to network-aware printers, \
 7 #       and to start the installation process for some operating systems.
 8 service tftp
 9 {
10         socket_type             = dgram
11         protocol                = udp
12         wait                    = yes
13         user                    = root
14         server                  = /usr/sbin/in.tftpd
15         server_args             = -s /var/lib/tftpboot #tftp资源文件目录了,可以根据实际情况修改,一般不修改
16         disable                 = yes #no改为yes
17         per_source              = 11
18         cps                     = 100 2
19         flags                   = IPv4
20 }
21 [root@localhost ~]#
22 [root@localhost ~]# netstat -lnupt|grep 69
23 udp6       0      0 :::69                   :::*                                1/systemd           
24 [root@localhost ~]# 

③配置HTTP服务

  http服务提供OS镜像下载地址

 1 [root@localhost ~]# yum install httpd -y
 2 [root@localhost ~]# mkdir -p /data/os/image/
 3 [root@localhost ~]# mkdir -p /var/www/html/CentOS7
 4 [root@localhost ~]# mount /dev/cdrom /var/www/html/CentOS7
 5 [root@localhost ~]# rsync -pavz /var/www/html/CentOS7 /data/os/image/CentOS7 #这里便于下载直接把操作系统文件拷贝到创建的/data/os/image/CentOS7目录下
 6 修改httpd配置文件
 7 DocumentRoot指定目录有"/var/www/html"修改为"/data/os/image"
 8 [root@localhost ~]# grep "/data/os/image" /etc/httpd/conf/httpd.conf
 9 DocumentRoot "/data/os/image"
10 <Directory "/data/os/image">
11 <Directory "/data/os/image">
12 [root@localhost ~]# 
13 [root@localhost ~]# systemctl restart httpd
14 [root@localhost ~]# 

保证可以通过浏览器访问到OS镜像内容

④配置支持PXE启动程序

 pxe引导配置(bootstrap)

 syslinux是一个功能强大的引导加载程序,并且兼容各种介质。syslinux是一个小型的LInux操作系统。它的目的是高度简化收菜安装Linux的时间,并建立修护或其他特殊用户的启动盘。一般系统没有pxelinux.0这个文件。

 1 [root@localhost ~]# yum install syslinux -y
 2 [root@localhost ~]# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
 3 #复制启动菜单程序文件
 4 [root@localhost ~]# cp -a /data/os/image/CentOS7/isolinux/* /var/lib/tftpboot/
 5 [root@localhost ~]# ls /var/lib/tftpboot/
 6 boot.cat  grub.conf   isolinux.bin  memtest   pxelinux.0    splash.png  upgrade.img   vmlinuz
 7 boot.msg  initrd.img  isolinux.cfg  menu.c32  TRANS.TBL   vesamenu.c32
 8 [root@localhost ~]# 
 9 #创建pxelinux.cfg目录,存放个pxe客户端的配置文件
10 [root@localhost ~]# mkdir -p /var/lib/tftpboot/pxelinux.cfg/
11 [root@localhost ~]# cp -a /data/os/image/CentOS7/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default

⑤配置网络安装文件default

1 [root@localhost ~]# vim /var/lib/tftpboot/pxelinux.cfg/default
2 label manual7
3       menu label Manual Install CentOS Linux 7
4       kernel vmlinuz
5       append initrd=initrd.img method=http://10.0.10.111/CentOS7/

启动客户端,出现如下界面:

接下来就是手动安装了,如果要自动安装呢?

那么就要修改default文件并指定安装配置文件CentOS-7.2.1511.cfg

1 label centos7     #auto install centos7
2       menu label Auto Install CentOS Linux 7
3       kernel vmlinuz
4       append initrd=initrd.img ks=http://172.16.1.201/ks_config/CentOS-7.2.1511.cfg

CentOS7-7.2.1511.cfg内容如下

 1 #version=DEVEL
 2 # System authorization information
 3 auth --enableshadow --passalgo=sha512
 4 # Use CDROM installation media
 5 #cdrom
 6 url --url=http://10.0.10.11/CentOS7
 7 # Use graphical install
 8 #graphical
 9 text
10 # Run the Setup Agent on first boot
11 firstboot --enable
12 ignoredisk --only-use=sda
13 # Keyboard layouts
14 keyboard --vckeymap=us --xlayouts='us'
15 # System language
16 lang en_US.UTF-8
17 
18 # Network information
19 network  --bootproto=dhcp --device=ens32 --onboot=on --ipv6=auto --activate
20 network  --hostname=localhost.localdomain
21 
22 # Root password
23 rootpw --iscrypted $6$KvKpJji3uieQkGBS$5s1fuvxc0WcOW77438w.bLZJwTxV8afFC.NL6X0zCfRj8pfrldm37lKgR5iSsY.z9pNd7Q9rxvqfIU0O1CUnX.
24 # System services
25 services --enabled="chronyd"
26 # System timezone
27 timezone Asia/Shanghai --isUtc --ntpservers=0.centos.pool.ntp.org,1.centos.pool.ntp.org,2.centos.pool.ntp.org,3.centos.pool.ntp.org
28 # System bootloader configuration
29 bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
30 # Partition clearing information
31 #clearpart --none --initlabel
32 zerombr
33 clearpart --all
34 reboot
35 # Disk partitioning information
36 part swap --fstype="swap" --ondisk=sda --size=131072
37 part /boot --fstype="xfs" --ondisk=sda --size=2048
38 part /opt --fstype="xfs" --ondisk=sda --size=122880
39 part /data --fstype="xfs" --ondisk=sda --size=204800
40 part /log --fstype="xfs" --ondisk=sda --size=122880
41 part / --fstype="xfs" --ondisk=sda --size=102400
42 firstboot --disabled
43 selinux --disabled
44 firewall --disabled
45 logging --level=info
46 reboot
47 %packages
48 @base
49 @compat-libraries
50 kexec-tools
51 autofs
52 @compat-libraries
53 @debugging
54 @development
55 tree
56 nmap
57 sysstat
58 rsyslog
59 lrzsz
60 dos2unix
61 telnet
62 wget
63 vim
64 wget
65 net-tools
66 sysstat
67 bash-completion
68 %end

CentOS-7.2.1511.cfg文件解释:

具体参考:https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/installation_guide/sect-simple-install-kickstart

 1 关键字     含义
 2 install     告知安装程序,这是一次全新安装,而不是升级upgrade。
 3 url --url=" "     通过FTP或HTTP从远程服务器上的安装树中安装。
 4 url --url="http://10.0.10.11/CentOS7/"
 5 url --url ftp://<username>:<password>@<server>/<dir>
 6 nfs     从指定的NFS服务器安装。
 7 nfs --server=nfsserver.example.com --dir=/tmp/install-tree
 8 text     使用文本模式安装。
 9 lang     设置在安装过程中使用的语言以及系统的缺省语言。lang en_US.UTF-8
10 keyboard     设置系统键盘类型。keyboard us
11 zerombr     清除mbr引导信息。
12 bootloader     系统引导相关配置。
13 bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet"
14 --location=,指定引导记录被写入的位置.有效的值如下:mbr(缺省),partition(在包含内核的分区的第一个扇区安装引导装载程序)或none(不安装引导装载程序)。
15 --driveorder,指定在BIOS引导顺序中居首的驱动器。
16 --append=,指定内核参数.要指定多个参数,使用空格分隔它们。
17 network     为通过网络的kickstart安装以及所安装的系统配置联网信息。
18 network --bootproto=dhcp --device=eth0 --onboot=yes --noipv6 --hostname=CentOS6
19 --bootproto=[dhcp/bootp/static]中的一种,缺省值是dhcp。bootp和dhcp被认为是相同的。
20 static方法要求在kickstart文件里输入所有的网络信息。
21 network --bootproto=static --ip=10.0.10.100 --netmask=255.255.255.0 --gateway=10.0.0.2 --nameserver=10.0.0.2
22 请注意所有配置信息都必须在一行上指定,不能使用反斜线来换行。
23 --ip=,要安装的机器的IP地址.
24 --gateway=,IP地址格式的默认网关.
25 --netmask=,安装的系统的子网掩码.
26 --hostname=,安装的系统的主机名.
27 --onboot=,是否在引导时启用该设备.
28 --noipv6=,禁用此设备的IPv6.
29 --nameserver=,配置dns解析.
30 timezone     设置系统时区。timezone --utc Asia/Shanghai
31 authconfig     系统认证信息。authconfig --enableshadow --passalgo=sha512
32 设置密码加密方式为sha512 启用shadow文件。
33 rootpw     root密码
34 clearpart     清空分区。clearpart --all --initlabel
35 --all 从系统中清除所有分区,--initlable 初始化磁盘标签
36 part     磁盘分区。
37 part /boot --fstype=ext4 --asprimary --size=200
38 part swap --size=1024
39 part / --fstype=ext4 --grow --asprimary --size=200
40 --fstype=,为分区设置文件系统类型.有效的类型为ext2,ext3,swap和vfat。
41 --asprimary,强迫把分区分配为主分区,否则提示分区失败。
42 --size=,以MB为单位的分区最小值.在此处指定一个整数值,如500.不要在数字后面加MB。
43 --grow,告诉分区使用所有可用空间(若有),或使用设置的最大值。
44 firstboot     负责协助配置redhat一些重要的信息。
45 firstboot --disable
46 selinux     关闭selinux。selinux --disabled
47 firewall     关闭防火墙。firewall --disabled
48 logging     设置日志级别。logging --level=info
49 reboot     设定安装完成后重启,此选项必须存在,不然kickstart显示一条消息,并等待用户按任意键后才重新引导,也可以选择halt关机。

为了实现全自动化安装并优化系统,我们可以在cfg文件中加入优化脚本;

调整后的cfg文件如下:

 1 #version=DEVEL
 2 # System authorization information
 3 auth --enableshadow --passalgo=sha512
 4 # Use CDROM installation media
 5 #cdrom
 6 url --url=http://10.0.10.11/CentOS7
 7 # Use graphical install
 8 #graphical
 9 text
10 # Run the Setup Agent on first boot
11 firstboot --enable
12 ignoredisk --only-use=sda
13 # Keyboard layouts
14 keyboard --vckeymap=us --xlayouts='us'
15 # System language
16 lang en_US.UTF-8
17 
18 # Network information
19 network  --bootproto=dhcp --device=ens32 --onboot=on --ipv6=auto --activate
20 network  --hostname=localhost.localdomain
21 
22 # Root password
23 rootpw --iscrypted $6$KvKpJji3uieQkGBS$5s1fuvxc0WcOW77438w.bLZJwTxV8afFC.NL6X0zCfRj8pfrldm37lKgR5iSsY.z9pNd7Q9rxvqfIU0O1CUnX.
24 # System services
25 services --enabled="chronyd"
26 # System timezone
27 timezone Asia/Shanghai --isUtc --ntpservers=0.centos.pool.ntp.org,1.centos.pool.ntp.org,2.centos.pool.ntp.org,3.centos.pool.ntp.org
28 # System bootloader configuration
29 bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
30 # Partition clearing information
31 #clearpart --none --initlabel
32 zerombr
33 clearpart --all
34 reboot
35 # Disk partitioning information
36 part swap --fstype="swap" --ondisk=sda --size=131072
37 part /boot --fstype="xfs" --ondisk=sda --size=2048
38 part /opt --fstype="xfs" --ondisk=sda --size=122880
39 part /data --fstype="xfs" --ondisk=sda --size=204800
40 part /log --fstype="xfs" --ondisk=sda --size=122880
41 part / --fstype="xfs" --ondisk=sda --size=102400
42 firstboot --disabled
43 selinux --disabled
44 firewall --disabled
45 logging --level=info
46 reboot
47 %packages
48 @base
49 @compat-libraries
50 kexec-tools
51 autofs
52 @compat-libraries
53 @debugging
54 @development
55 tree
56 nmap
57 sysstat
58 rsyslog
59 lrzsz
60 dos2unix
61 telnet
62 wget
63 vim
64 wget
65 net-tools
66 sysstat
67 bash-completion
68 %end
69 %post
70 wget -O /tmp/optimization.sh http://10.0.10.11/ks_config/initialization.sh &>/dev/null
71 /bin/sh /tmp/initialization.sh
72 systemctl disable postfix.service 
73 %end
initialization.sh内容如下:
  1 . /etc/init.d/functions
  2 
  3 Ip=10.0.10.11
  4 Port=80
  5 ConfigDir=ks_config
  6 
  7 # Defined result function
  8 function Msg(){
  9         if [ $? -eq 0 ];then
 10           action "$1" /bin/true
 11         else
 12           action "$1" /bin/false
 13         fi
 14 }
 15 
 16 # Defined IP function
 17 function ConfigIP(){
 18 Suffix=`ifconfig em1|awk -F "[ .]+" 'NR==2 {print $6}'`
 19 /bin/cat >/etc/sysconfig/network-scripts/ifcfg-em1 <<-END
 20  DEVICE=em1
 21  TYPE=Ethernet
 22  ONBOOT=yes
 23  NM_CONTROLLED=yes
 24  BOOTPROTO=none
 25  IPADDR=10.0.10.$Suffix
 26  PREFIX=24
 27  DEFROUTE=yes
 28  IPV4_FAILURE_FATAL=yes
 29  IPV6INIT=no
 30  NAME="System em1"
 31 END
 32 Msg "config em1"
 33 }
 34 
 35 # Defined Yum source Functions
 36 function yum(){
 37         YumDir=/etc/yum.repos.d
 38         [ -f "$YumDir/CentOS-Base.repo" ] && cp $YumDir/CentOS-Base.repo{,.ori} 
 39         wget -O $YumDir/CentOS-Base.repo http://$Ip:$Port/$ConfigDir/CentOS-Base.repo &>/dev/null &&\
 40         wget -O $YumDir/epel.repo http://$Ip:$Port/$ConfigDir/epel.repo &>/dev/null &&\
 41         Msg "YUM source"
 42 }
 43 
 44 # Defined Hide the system version number Functions
 45 function HideVersion(){
 46         [ -f "/etc/issue" ] && >/etc/issue
 47         Msg "Hide issue" 
 48         [ -f "/etc/issue.net" ] && > /etc/issue.net
 49         Msg "Hide issue.net"
 50 }
 51 
 52 # Defined OPEN FILES Functions
 53 function openfiles(){
 54         [ -f "/etc/security/limits.conf" ] && {
 55         echo '*  -  nofile  65535' >> /etc/security/limits.conf
 56         Msg "open files"
 57         }
 58 }
 59 
 60 # Defined Kernel parameters Functions
 61 function kernel(){
 62         KernelDir=/etc
 63         [ -f "$KernelDir/sysctl.conf" ] && /bin/mv $KernelDir/sysctl.conf{,.ori}
 64         wget -O $KernelDir/sysctl.conf http://$Ip:$Port/$ConfigDir/sysctl.conf &>/dev/null
 65         Msg "Kernel config"
 66 }
 67 
 68 # Defined SSH Login Config
 69 function sshd(){
 70            [ -f "/etc/ssh/sshd_config" ] && /bin/mv /etc/ssh/sshd_config{,.ori}
 71            wget -O /etc/ssh/sshd_config http://$Ip:$Port/$ConfigDir/sshd_config &>/dev/null
 72            Msg "ssh config"
 73 
 74 }
 75 # Defined Log parameters Functions
 76 function logs(){
 77         [ -f "/etc/rsyslog.conf" ] && /bin/mv /etc/rsyslog.conf{,.ori}
 78         wget -O /etc/rsyslog.conf http://$Ip:$Port/$ConfigDir/rsyslog.conf &>/dev/null
 79         Msg "Log config"
 80 }
 81 
 82 # Defined Time Synchronization Functions
 83 function Time(){
 84         echo '*/5 * * * * /usr/sbin/ntpdate time.nist.gov &>/dev/null' >>/var/spool/cron/root
 85         Msg "Time Synchronization"
 86 }
 87 
 88 
 89 # Defined main Functions
 90 function main(){
 91         ConfigIP
 92         yum
 93         HideVersion
 94         openfiles
 95         kernel
 96         sshd
 97         logs
 98         Time
 99 }
100 
101 main

 我这里把需要下载的文件都拷贝到/data/os/image/ks_config目录下:

至此基于PXE和Kicstart部署自动化部署操作系统安装完成

参考文章:

http://blog.oldboyedu.com/autoinstall-kickstart/

https://www.cnblogs.com/clsn/p/7833333.html

https://www.cnblogs.com/clsn/p/7833333.html

猜你喜欢

转载自www.cnblogs.com/kindnull/p/9106134.html
今日推荐