PXE 预启动执行环境及Kickstart 自动安装系统

首先要关闭防火墙,和selinux
systemctl stop firewalld
systemctl status firewalld
setenforce 0 临时的关闭selinux
/etc/selinux/config中的改为SELINUX=disabled
这个要关闭虚拟机重启才能生效
如果服务机是使用仅主机模式上网的,要安装的虚拟机也要配成仅主机模式上网

1).配置dhcp环境
1.dhcp (pxe 客户端需要获取 ip 地址)
安装dhcp
yum install dhcp
# yum install dhcp
2.修改配置文件
查看配置文件
rpm -ql dhcp
/etc/NetworkManager
/etc/NetworkManager/dispatcher.d
/etc/NetworkManager/dispatcher.d/12-dhcpd
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/dhcp/scripts
利用模板文件修改
cp /usr/share/doc/dhcp*/dhcpd.conf.example dhcpd.conf
# dhcpd.conf
# vim /etc/dhcp/dhcpd.conf
subnet 10.222.88.0 netmask 255.255.255.0 {
range 10.222.88.30 10.222.88.121;
filename "pxelinux.0" ; //虚拟机的引导文件
next-server 10.222.88.1 ;//自己本地的作为PEX的ip地址

}

4.添加修改一个静态网络,ip地址在刚才的地址内
nmcli connection add con-name www ipv4.addresses 10.222.88.1/24 ipv4.method manual type ethernet ifname ens33
5.开启服务
systemctl start dhcpd
2).安装tftp-server
安装tftp-server
[root@CentOS73-1 ~]# yum install tftp-server
[root@CentOS73-1 ~]# systemctl start tftp-server
[root@CentOS73-1 ~]# systemctl status tftp-server
测试 tftp server
在 /var/lib/tftpboot 中创建一个文件,a.txt,然后下载 a.txt 测试
[root@centos74-1 ~ ]
# cd /var/lib/tftpboot/
[root@centos74-1 /var/lib/tftpboot ]
# ls
[root@centos74-1 /var/lib/tftpboot ]
# touch a.txt
[root@centos74-1 /var/lib/tftpboot ]
# echo haha > a.txt
安装 tftp 客户端
[root@centos74-1 ~ ]
# yum install tftp
开启服务
systemctl start tftp
从 /var/lib/tftpboot 目录切换到另一个目录,下载测试文件
[root@centos74-1 ~ ]
# cd /tmp/
[root@centos74-1 /tmp ]
# tftp 127.0.0.1
tftp> status
Connected to 127.0.0.1.
Mode: netascii Verbose: off Tracing: off Literal: off
Rexmt-interval: 5 seconds, Max-timeout: 25 seconds
tftp> get a.txt
tftp> quit
[root@centos74-1 /tmp ]
3). 复制 pxelinux.0 vmlinuz initrd.img 等文件到 tftp server
查找 yum 源中可以提供 pxelinux.0 文件的 rpm 包( pxe client 需要执行行的第一个文件)
cp /mnt/selinux
[root@CentOS73-1 /tmp]# yum provides "*/ pxelinux.0 "
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
syslinux -4.05-13.el7.x86_64 : Simple kernel loader which boots from a FAT filesystem
Repo : base
Matched from:
Filename : /usr/share/syslinux/pxelinux.0
[root@CentOS73-1 /tmp]# yum install syslinux
[root@centos74-1 ~ ]
# cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
4)
进入光盘目录,复制 pxelinux.cfg 到 /var/lib/tftpboot/

[root@wangying mnt]# cd isolinux/
[root@wangying isolinux]# ls
boot.cat grub.conf isolinux.bin memtest TRANS.TBL vmlinuz
boot.msg initrd.img isolinux.cfg splash.png vesamenu.c32
[root@wangying isolinux]#
[root@centos74-1 /media/centos7.4/isolinux ]
# cp vmlinuz initrd.img isolinux.cfg /var/lib/tftpboot/
[root@centos74-1 /var/lib/tftpboot ]
# cd /var/lib/tftpboot/
/var/lib/tftpboot目录下的文件
[root@wangying tftpboot]# pwd
/var/lib/tftpboot
[root@wangying tftpboot]# ls
a.txt initrd.img pxelinux.0 pxelinux.cfg vesamenu.c32 vmlinuz
[root@wangying tftpboot]#

[root@centos74-1 /var/lib/tftpboot ]
# mkdir pxelinux.cfg
[root@centos74-1 /var/lib/tftpboot ]
# ls
initrd.img isolinux.cfg pxelinux.0 pxelinux.cfg vmlinuz
[root@centos74-1 /var/lib/tftpboot ]
# mv isolinux.cfg pxelinux.cfg/default
5).
图形化PXE菜单界面,需要用到 /usr/share/syslinux/vesamenu.c32
[root@centos74-1 /var/lib/tftpboot ]
# cp /usr/share/syslinux/vesamenu.c32 /var/lib/tftpboot/
6)安装ftp
# yum install vsftpd -y
[root@centos74-1 /var/lib/tftpboot ]
# mkdir /var/ftp/centos7.5
一定要记住挂载光盘在ftp上
[root@centos74-1 /var/lib/tftpboot ]
# mount /dev/sr0 /var/ftp/pub/centos7.5/
mount: /dev/sr0 is write-protected, mounting read-only
[root@centos74-1 /var/lib/tftpboot ]
# systemctl start vsftpd
7).
修改 pxelinux.cfg 配置文件
至少包含下面几行行
[root@centos74-1 /var/lib/tftpboot ]
# vim pxelinux.cfg/default
default xiaoming
label xiaoming
menu label ^Install wangyingying de CentOS Linux 7
kernel vmlinuz
append initrd= initrd.img inst.repo=ftp://10.222.88.1/centos7.5 net.ifnames=0 biosdevname=0 修改网卡的名字变成eth0
在开启另一个虚拟机进行测试的时候,要检查,dhcp,tftp ,vsftpd 这几个服务是否开启
在pxe手动基础上,进行自动化安装虚拟机
编写 ks 文件,复制到 ftp
生成 root 密码
[root@wangying ftp]# openssl passwd -1 -salt '12345678'
Password: root
$1$12345678$76lAyQ3gK4KwW4QYKF7.0/
[root@wangying ftp]#

[root@centos74-1 /var/ftp/pub ]
编辑自动化安装系统的文件,配置文件的格式要特别注意,等号两边不能有空格,符号之间也不能有空格和换行的,配置文件要有读取的权限
# vim /var/ftp/pub/centos7.5.cfg
version=DEVEL
# System authorization information
auth --enableshadow --passalgo=sha512
reboot  #安装完成猴年自动重启
# Use network installation
url --url="ftp://10.222.88.1/centos7.5/" # 镜像文件的所在位置,配置自己的ftp中镜像的挂载位置
# Use graphical install
# graphical #图形界面安装,在安装图形界面时,要用这个
cmdline #字符界面的显示安装方式
# Run the Setup Agent on first boot
firstboot --disable
firewall --disable
selinux --disable
eula --agreed
ignoredisk --only-use=sda
# Keyboard layouts
keyboard --vckeymap=us --xlayouts='us'
# System language
#lang zh_CN.UTF-8
lang en_US --addsupport=zh_CN.UTF-8

# Network information
network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
#network --bootproto=dhcp --device=eth0 --ipv6=auto --activate
network --hostname=localhost.localdomain

# Root password
rootpw --iscrypted $1$12345678$76lAyQ3gK4KwW4QYKF7.0/
# System timezone
timezone Asia/Shanghai
user --name=wangying --password=$6$TXzadAZfpBMcmbgH$NEB7nVPZ97.M8cc8rdHrIYeAc6xlYVWjBPFYj/QDn4PlEDMaRSJY7PHVKnYtgEMPgNnCXWYlru.fTes3h5/Y2. --iscrypted --gecos="wangying"
zerombr
#bootloader --location=mbr --boot-drive=sda
autopart
# Partition clearing information
clearpart --all --initlabel   #如果之前存在分区的话,上面的zerombr也要写上
%packages
@^minimal #最小化安装,也是linux中的各种组,可以在linux中进行查询,yum grouplist 查看各种安装的组,yum groupinfo "带 GUI 的服务器" 查看组的id这儿要写的就是id
@core   #要安装的各种服务,
vim-enhanced
wget
tree
vsftpd
%end

%addon com_redhat_kdump --disable --reserve-mb='auto'

%end


脚本部分,可以在脚本下面配置各种shell脚本,和命令,对新建的系统进行管理
%post


%end

%packages、%post 都要以%end 结尾

[root@wangying ~]# yum grouplist 查看各种安装的组
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
可用的环境分组:
最小安装
基础设施服务器
计算节点
文件及打印服务器
基本网页服务器
虚拟化主机
带 GUI 的服务器
GNOME 桌面
KDE Plasma Workspaces
开发及生成工作站
可用组:
传统 UNIX 兼容性
兼容性程序库
图形管理工具
安全性工具
开发工具
控制台互联网工具
智能卡支持
科学记数法支持
系统管理
系统管理工具
完成
[root@wangying ~]# yum groupinfo "带 GUI 的服务器" 查看组的id
已加载插件:fastestmirror, langpacks
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
环境分组:带 GUI 的服务器
环境 ID:graphical-server-environment
描述:带有用于操作网络基础设施服务 GUI 的服务器。
必备组:
+base
+core
+desktop-debugging
+dial-up
+fonts
+gnome-desktop
+guest-agents
+guest-desktop-agents
+hardware-monitoring
+input-methods
+internet-browser
+multimedia
+print-client
+x11
可选组:
+backup-server
+directory-server
+dns-server
+file-server
+ftp-server
+ha
+hardware-monitoring
+identity-management-server
+infiniband
+java-platform
+kde-desktop
+large-systems
+load-balancer
+mail-server
+mainframe-access
+mariadb
+network-file-system-client
+performance
+postgresql
+print-server
+remote-desktop-clients
+remote-system-management
+resilient-storage
+virtualization-client
+virtualization-hypervisor
+virtualization-tools
修改 pxelinux.cfg 配制文件
添加新 label
[root@centos74-1 /var/ftp/pub ]
# vim /var/lib/tftpboot/pxelinux.cfg/default
label linux1
menu label ^Install wangying CentOS 7.5 pxe 手动安装
kernel vmlinuz
append initrd=initrd.img inst.repo=ftp://10.222.88.1/centos7.5 net.ifnames=0 biosdevname=0

label linux2
menu label ^Install wangying CentOS 7.5 pxe kickstart 自动安装
menu default
kernel vmlinuz
append initrd=initrd.img ks=ftp://10.222.88.1/centos7.5.cfg

检验 ks 文件
[root@centos74-1 /var/ftp/pub ]
# yum install pykickstart·
[root@centos74-1 /var/ftp/pub ]
# rpm -ql pykickstart | head
/usr/bin/ksflatten
/usr/bin/ksshell
/usr/bin/ksvalidator
/usr/bin/ksverdiff
/usr/lib/python2.7/site-packages/pykickstart
/usr/lib/python2.7/site-packages/pykickstart-1.99.66.12-py2.7.egg-info
/usr/lib/python2.7/site-packages/pykickstart/__init__.py
/usr/lib/python2.7/site-packages/pykickstart/__init__.pyc
/usr/lib/python2.7/site-packages/pykickstart/__init__.pyo
/usr/lib/python2.7/site-packages/pykickstart/base.py
ksvalidator 检测 ks 配置文件,如果文件正常,则没有输出
[root@centos74-1 /var/ftp/pub ]
# ksvalidator /var/ftp/pub/centos7.4.cfg
[root@centos74-1 /var/ftp/pub ]
# ksvalidator /var/ftp/pub/centos7.4.cfg
The following problem occurred on line 3 of the kickstart file:
Unknown command: haha
定制 kickstart 文件
[root@centos74-1 ~ ]
# yum install system-config-kickstart
system-config-kickstart 启动制定文件的的软件,图像化界面
配置自己的ks.cfg文件
完成配置后,点击文件,保存ks.cfg
#platform=IBM iSeries
#version=DEVEL
# Install OS instead of upgrade
install
# Keyboard layouts
keyboard 'us'
# Root password
rootpw --iscrypted $1$L9qB8QOz$hV3gBzN2I5bZC4sC.5WB11
# Use network installation
url --url="ftp://10.222.88.1/centos7.5/"
# System language
lang zh_CN
# System authorization information
auth --useshadow --passalgo=sha512
# Use text mode install
text
firstboot --disable
# SELinux configuration
selinux --disabled

# Firewall configuration
firewall --disabled
# Reboot after installation
reboot
# System timezone
timezone Asia/Shanghai
# System bootloader configuration
bootloader --location=none
# Partition clearing information
clearpart --all
只能完成一部分的配置,需要安装的软件要自己配置在上面的插件生成的配置文件中需要修改几个地方

自动安装一个仅主机模式的虚拟机,就可以实现自动化的安装虚拟机



自动安装,在安装的系统上配置yum源,只需要将下面的代码加在ks配置文件上
%post
rm -rf /etc/yum.d/*.repo
wget
ftp://10.222.88.1/Base.repo -O /etc/yum.d/
%end

猜你喜欢

转载自blog.csdn.net/qq_37194598/article/details/81810114
今日推荐