一、Kickstart


当我们用后端管理文件安装虚拟机时,发现在安装前需要手动回答一系列的问题。那么,我们能否用镜像文件无交互的安装虚拟机吗?
答案是肯定的!还记得我们之前了解过的编辑可运行的脚本吗?
哈哈,此处亦然。

其设置过程如下:

1)安装kickstart软件

[[email protected] yum.repos.d]# yum install system-config-kickstart -y

2)调取kickstart图形界面并进行一系列设置

[[email protected] yum.repos.d]# system-config-kickstart 

>基本信息设定(语言、时区、密码等)

介绍kickstart、dhcp

>安装模式选择

介绍kickstart、dhcp

>引导装载程序选项

介绍kickstart、dhcp

>分区划分策略

介绍kickstart、dhcp

介绍kickstart、dhcp

介绍kickstart、dhcp

介绍kickstart、dhcp

>添加网络配置

介绍kickstart、dhcp

>火墙配置信息(设置火墙为开机不启动)

介绍kickstart、dhcp

>安装后执行脚本(可以不写)

介绍kickstart、dhcp

>保存在/root目录下

介绍kickstart、dhcp

3)文本方式添加所需的包及服务

[[email protected] ~]# ls /root
anaconda-ks.cfg  foundation-config-post.log  rht-ks-post.log  tmp
Desktop          ks.cfg                      rht-ks-pre.log
[[email protected] ~]# vim ks.cfg
\
注:如若是添加服务,即直接写服务即可。如lftp
若是添加包,需要在前面加上'@',如@base
最后以%end结尾,%post表示安装后做的动作

*4)ksvalidator命令检测

只能帮助审核ks文件的格式,不能审核配置的内容
介绍kickstart、dhcp
[[email protected] html]# ksvalidator /root/ks.cfg
The following problem occurred on line 49 of the kickstart file:

Unknown kickstart section: %package

5)将ks.cfg进行共享

之前选择的安装模式为http,故放在/var/www/html/目录中
[[email protected] ~]# cp ks.cfg /var/www/html/
[[email protected] ~]# cd /var/www/html/
[[email protected] html]# ls
ks.cfg  rhel7.2  software

6)脚本编写并运行

[[email protected] html]# vim /mnt/Create_Auto.sh
介绍kickstart、dhcp
[[email protected] html]# cd /mnt
[[email protected] mnt]# chmod +x Create_Auto.sh
[[email protected] mnt]#./Create_Auto.sh westos
介绍kickstart、dhcp
由于我们设置的ip为dhcp自动获取,如上结果表示其无法自动获取ip,由于系统中没有DHCP服务,故安装无法正常进行。接下来,我们来了解以下DHCP安装流程。

二、dhcp  


1.安装

yum install dhcp -y

2.生成配置文件

cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf

3.修改配置文件完成配置

vim /etc/dhcp/dhcpd.conf
  1 # dhcpd.conf
  2 #
  3 # Sample configuration file for ISC dhcpd
  4 #
  5 
  6 # option definitions common to all supported networks...
  7 option domain-name "westos.com";        ##指定域名(可自行更改)
  8 option domain-name-servers 192.168.43.1;    ##指定客户主机获得到的dns
  9 
 10 default-lease-time 600;            ##最短租约期
 11 max-lease-time 7200;            ##最长租约期
。。。。。。。。。。
。。。。。。。。。。。。
 27 #subnet 10.152.187.0 netmask 255.255.255.0 { ##删除27&28两行         #
 28 #}
 29 
 30 # This is a very basic subnet declaration.
 31 
 32 subnet 172.25.254.0 netmask 255.255.255.0 {   --->网段及子网掩码
 33   range 172.25.254.109 172.25.254.200;      --->自动获取ip范围
 34   option routers 172.25.254.9;          --->网关
 35 }
 #####36行以后的全部删除################################

4.重启服务

systemctl restart dhcpd

实操:

[python] view plain copy
  1. [[email protected] html]# yum install dhcp -y  
  2. [[email protected] dhcp]# vim /etc/dhcp/dhcpd.conf  

介绍kickstart、dhcp

[python] view plain copy
  1. [[email protected] dhcp]# cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf  
  2. cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y  
  3. [[email protected] dhcp]# vim /etc/dhcp/dhcpd.conf  
  4. [[email protected] dhcp]# systemctl restart dhcpd.service  
  5. [[email protected] mnt]# ./Create_Auto.sh westos  

介绍kickstart、dhcp介绍kickstart、dhcp


三、拓展

1.关于取消异常挂载的方法:

介绍kickstart、dhcp

2.kickstart文件参数解析

介绍kickstart、dhcp

介绍kickstart、dhcp


相关文章: