linux中的自动化安装脚本

在这一篇中我们主要来了解linux中调取网络脚本文件的自动化安装,以及对脚本部分语句格式及功能的了解。


一.dhcp服务的搭建

此部分内容不是必须的 主要是为了下一部分:建立新的虚拟机的实验做准备


1.安装dhcp服务

见 一. /6


2.查找dhcp配置文件

[[email protected] software]# rpm -qc dhcp    ##查找dhcp的组态配置文件
/etc/dhcp/dhcpd.conf                    ##最像dhcp的配置文件
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

linux中的自动化安装脚本


3.查看配置文件

[[email protected] software]# cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example      ##根据配置文件提示查看此文件
#   see dhcpd.conf(5) man page
#

linux中的自动化安装脚本


4.根据配置文件提示 将配置文件模版覆盖配置文件

[[email protected] software]# cp /usr/share/doc/dhcp*/dhcpd.conf.example
cp: missing destination file operand after ‘/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example’
Try 'cp --help' for more information.
[[email protected] software]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? yes       ##询问是否覆盖 输入yes

linux中的自动化安装脚本


5.修改配置文件

[[email protected] software]# vim /etc/dhcp/dhcpd.conf
 7 option domain-name "zl.com";    ##局域网名
 8 option domain-name-servers 172.25.254.99;    ##dns网段
 9 
 30 subnet 172.25.99.0 netmask 255.255.255.0 {

 31   range 172.25.99.20   172.25.99.30;

 32   option routers 172.25.99.250}

linux中的自动化安装脚本

linux中的自动化安装脚本


6.重启dhcp服务

linux中的自动化安装脚本


7.排错
  627  >/var/log/messages           ##将系统日志晴空
  628  systemctl restart dhcpd    ##执行命令
  629  cat /var/log/messages       ##通过查看系统日志报错来排错



二.自动化安装脚本建立

1.进入生成安装系统过程中回答系统提示的脚本文件的图形

linux中的自动化安装脚本

linux中的自动化安装脚本


2.进入图形选择配置(按自己需求选择)


3.点击save 生成文件ks.cfg 保存到/var/www/html/

linux中的自动化安装脚本


4.编写ks.cfg文件 增加安装的软件

在刚才图形中选择配置的时候 没有选择安转软件的模块 需要我们自己在脚本中添加

linux中的自动化安装脚本

%packages  ##安装软件
lftp          ##单个软件
@base         ##软件组
%end

%post       ##安装后执行的命令
touch file{1..5}
%end

linux中的自动化安装脚本


5.检查写ks.cfg是否有语法错误

注意:只能检测语法错误 不能检测内容是否合理

[[email protected] html]# ksvalidator ks.cfg 
The following problem occurred on line 44 of the kickstart file:    ##第44行有错误
Section %packages does not end with %end.                           ##错误为没有结束%end符


6.测试ks.cfg是能在网络共享

linux中的自动化安装脚本

(可以通进行下一步)


7.编写执行创建新的虚拟机的shell脚本命令

linux中的自动化安装脚本

linux中的自动化安装脚本


8.脚本文件加权限

linux中的自动化安装脚本


9.执行命令 完成自动化安装虚拟机