kickstart自动化部署
kickstart自动化部署
软件 | 版本 |
---|---|
nginx | 1.14.0 |
节点 | IP | 系统 | 功能 | CPU | 内存 | 硬盘 |
---|---|---|---|---|---|---|
node1 | 10.80.10.1 | centos7.9 | kickstart | 4核心 | 8GB | 20GB |
node2 | 自动分配 | centos7.9 | client | 4核心 | 8GB | 20GB |
node3 | 自动分配 | centos6.10 | client | 4核心 | 8GB | 20GB |
centos7的手动安装简介
下载centos7.9和centos6.10的minimal镜像做准备:
centos7.9镜像下载地址:
https://mirrors.aliyun.com/centos-vault/6.10/isos/x86_64/
centos6.10镜像下载地址:https://mirrors.aliyun.com/centos/7.9.2009/isos/x86_64/
vmware虚拟机安装centos7:
需要手动挂载iso。
需要手动设置时间日期、键盘、磁盘分区、网络等。
物理机手动安装centos7:
需要使用u盘刻录。
需要手动设置时间日期、键盘、磁盘分区、网络等。
kickstart项目能够实现centos7的全自动安装,也就是安装过程自动化,会比手动安装方便很多。
启动说明和kickstart流程简介
服务器的启动优先级,按优先级来启动,如果优先级高的找不到系统启动,则一级一级往下自动选择:
从u盘启动:物理机手动安装系统一般从u盘启动。
从光驱启动:虚拟机手动安装系统一般从光驱启动。
从网络启动:从网络启动会使用pxe客户端,它可以自行获取ip,加载启动文件,自行安装操作系统。
从硬盘启动:安装好系统后就可以从硬盘启动,启动后就能使用系统。
网络启动中的pxe客户端介绍:
pxe全称为preboot execute environment,预启动执行环境。
pxe客户端会使用dhcp客户端去获取ip。
pxe客户端会使用tftp协议去下载预启动文件。
pxe客户端对应的服务器端:
既然pxe客户端会使用dhcp客户端去获取ip,那我们就需要搭建dhcp服务器。
既然pxe客户端会使用tftp协议去下载预启动文件,那我们就需要搭建tftp服务器。
pxe网络启动全自动安装系统的流程介绍:
pxe客户端—>dhcp服务器:获取ip和tftp的地址。
pxe客户端—>tftp服务器:去下载预启动文件。
pxe客户端—>tftp服务器:获取引导文件,引导安装。这边可设置多种安装,例如centos6和centos7的安装。
pxe客户端—>tftp服务器:获取安装需要的vmliuz和initrm.img。
内存加载vmliuz和initrd.img,然后去下载安装文件,全自动安装。
vmware通过网络启动说明:
- 默认通过网络启动pxe客户端会报错。
dhcp服务器的安装和配置
dhcp服务器说明:
dhcp服务器用来给用户分配ip地址。
dhcp服务器还能给pxe客户端配置tftp的信息:地址和预启动文件。
需要关闭虚拟机的dhcp。
node1
下载安装dhcp:
1 | # yum install -y dhcp |
修改dhcp配置文件:
1 | # cp /etc/dhcp/dhcpd.conf{,.bak} |
allow:允许pxe。
next-server:tftp服务器的ip信息,可以配置在非dhcp服务器。
filename:tftp服务器的预启动文件。
subnet:配置dhcp服务器的网络信息。
range dynamic-bootp:设置分配的地址范围。
subnet-mask:配置分配地址的子网掩码。
option routers:配置分配的路由地址。
option domain-name-servers:配置分配的dns地址。
启动dhcp,配置开机自启:
1 | # systemctl start dhcpd |
查看端口和进程:
1 | # netstat -tulnp | grep dhcp |
tftp服务器的安装和配置
tftp服务器:
tftp服务器可用来传输文件。
pxe客户端会来tftp服务器上拉取预启动文件pxelinux.0。
node1
下载安装tftp:
1 | # yum install -y xinetd tftp-server |
修改tftp配置文件:
1 | # cp /etc/xinetd.d/tftp{,.bak} |
disable:改为no说明要启动tftp服务器。
server_args:设置tftp服务器的根目录,pxelinux.0默认会到根目录下查找。
启动tftp,设置开机自启:
1 | # systemctl restart xinetd |
查看端口和进程:
1 | # netstat -tulnp | grep xinetd |
安装pxelinux.0引导文件,会安装到tftp的根目录下/var/lib/tftpboot/:
1 | # yum install -y syslinux-tftpboot |
编辑引导配置:
1 | # mkdir -p /var/lib/tftpboot/pxelinux.cfg |
timeout 300:超时30s。
menu title:供选择时的标题展现。
kernel:配置内核。
append:配置内存加载的文件。
挂载centos7镜像准备自动安装
node1
上传CentOS-7-x86_64-Minimal-2009.iso:
1 | # cd /usr/local/src/ |
镜像挂载:
1 | # mkdir -p /var/www/html/centos7 |
拷贝内核文件:
1 | # mkdir -p /var/lib/tftpboot/centos7 |
设置开机自动挂载镜像:
1 | # vim /etc/rc.local |
1 | # chmod +x /etc/rc.d/rc.local |
配合pex搭建nginx服务器
node1
下载安装nginx:
下载地址:
https://nginx.org/en/download.html
1 | # yum install -y wget gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel |
1 | # /usr/local/nginx/sbin/nginx -V |
修改配置文件:
1 | # vim /usr/local/nginx/conf/nginx.conf |
启动nginx:
1 | # /usr/local/nginx/sbin/nginx |
浏览器访问:http://10.80.10.1/centos7/
编辑centos7的kickstart配置文件:
1 | # vim /var/www/html/ks7.cfg |
install:全新安装。
text:文本安装。
firstboot –disable:设置代理。
keyboard:键盘总局英文。
lang en_US:语言选择英文。
zerombr:清除mbr分区。
reboot:安装完毕后重启。
clearpart:清除分区,磁盘有数据需要小心,默认选项一定不能放安装的这里。
part:设置分区–size指定分区大小。–grow指定使用剩余所有空间,那样的话–size大小随意。
url:指定包的位置。
%packages和%end中间放安装包,最小化安装不用配置。
%post和%end中间放安装后的自定义代码,用来做一些初始化。
硬盘全部分区都给/根分区的配置如下:
part / –asprimary –fstype=”ext4” –grow –size=1
验证全自动安装centos7
pxe网络启动全自动安装系统的流程介绍:
pxe客户端—>dhcp服务器:获取ip和tftp的地址。
pxe客户端—>tftp服务器:去下载预启动文件pxelinux.0,运行预启动文件。
pxe客户端—>tftp服务器:获取引导文件(pxelinux.cfg/default),引导安装。这边可设置多种安装,例如centos6和centos7的安装。
pxe客户端—>tftp服务器:获取安装需要的vmliuz和initrm.img。
内存加载vmliuz和initrd.img,然后去下载安装文件,全自动安装。
安装会获取kickstart配置文件—>http服务器获取kickstart配置文件。
根据kickstart配置文件完成自动化安装,注意http服务器的配置。
创建虚拟机注意:
在vmware上新建一台虚拟,不使用dvd的模式手动安装,使用网络全自动安装。
注意内存至少要2G,内存不足会报错,磁盘可以默认20G。
验证centos7安装,启动虚拟机,进入安装界面,选择install centos7,回车确认:
等待安装,需要一段时间,这里安装完后会自动重启:
node2
进入正常的启动界面,root密码123456,进行测试:
1 | # ifconfig |
centos6的全自动安装配置
node1
添加centos6引导配置:
1 | # vim /var/lib/tftpboot/pxelinux.cfg/default |
编辑centos6的kickstart配置文件:
1 | # vim /var/www/html/ks6.cfg |
上传CentOS-6.10-x86_64-minimal.iso:
1 | # cd /usr/local/src/ |
镜像挂载:
1 | # mkdir -p /var/www/html/centos6 |
1 | # ls /var/www/html/centos6 |
拷贝内核文件:
1 | # mkdir -p /var/lib/tftpboot/centos6 |
镜像挂载,设置开机自动挂载:
1 | # vim /etc/rc.local |
1 | # chmod +x /etc/rc.d/rc.local |
浏览器访问:http://10.80.10.1/centos6/
验证全自动安装centos6和救援模式
创建虚拟机注意:
在vmware上新建一台虚拟,不使用dvd的模式手动安装,使用网络全自动安装。
内存配置了2G,但是centos6可以1G。
验证centos6安装,启动虚拟机,进入安装界面,选择install centos6,回车确认:
等待安装,需要一段时间,这里安装完后会自动重启:
node3
进入正常的启动界面,进行测试:
1 | # ifconfig |
验证救援模式,因为是用的centos7的内核,所以使用centos7的虚拟机测试。重启虚拟机,按F12进入网络启动模式,重新进入安装界面,选择install rescue,回车确认:
等待进入系统,输入3,进入shell:
node2
可以挂载目录,进行修复,这里系统盘是/dev/sda2,具体看kickstart的配置:
1 | # ls /dev/sd* |