部署三台Rockylinux9服务器
实验要求
1. 自动安装ubuntu server20以上版本
2. 自动部署三台Rockylinux9服务器,最小化安装,安装基础包,并设定国内源,设静态IP
实验步骤
安装软件
# yum源必须有epel源
# dnf install -y epel-release
#关闭防火墙和selinux
systemctl stop firewalld && systemctl disable firewalld
sed -i 's/^SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
# reboot
三、部署Cobbler
1、安装软件
# dnf -y install cobbler dhcp-server
dnf -y install syslinux dnf-plugins-core pykickstart
创建三台虚拟机,设定MAC地址
将三台虚拟机的MAC地址记录下来:
00:50:56:3B:64:2F
00:50:56:23:4A:8E
00:50:56:39:61:7A
2、配置cobbler
(1)修改Cobbler主配置文件
# 生成密文密码
openssl passwd -1 "qweasd"
$1$hNAtwYE4$.l1apMwOWpCDpSmE.MBdG0
#设置root密码
vi /etc/cobbler/settings.yaml
default_password_crypted: "$1$hNAtwYE4$.l1apMwOWpCDpSmE.MBdG0"
$1$hNAtwYE4$.l1apMwOWpCDpSmE.MBdG0
# cobbler接管dhcp
manage_dhcp: true
manage_dhcp_v4: true
#cobbler服务器地址
server: 192.168.8.100 --指定自己的ip地址
#tftp地址
next_server_v4: 192.168.100.128 --指定自己的ip地址
#cobbler接管tftp
manage_tftpd: true
#当bios首选启动项是pxe时,此项设置为true,可避免重启反复安装系统,否则为false
pxe_just_once: true
- 修改dhcp模版文件
添加
host server01 {
hardware ethernet 00:50:56:3B:64:2F;
fixed-address 192.168.8.110;
}
host server02 {
hardware ethernet 00:50:56:23:4A:8E;
fixed-address 192.168.8.120;
}
host server03 {
hardware ethernet 00:50:56:39:61:7A;
fixed-address 192.168.8.130;
}
# vi /etc/cobbler/dhcp.template
……
subnet 192.168.8.10 netmask 255.255.255.0 { #-网段和子网掩码
option routers 192.168.8.2; #-网关
option domain-name-servers 8.8.8.8; #dns
option subnet-mask 255.255.255.0;
range dynamic-bootp 192.168.8.100 192.168.8.254; #--起始范围
host server01 {
hardware ethernet 00:50:56:3B:64:2F; #-复制自己生成的mac地址
fixed-address 192.168.8.110;
}
host server02 {
hardware ethernet 00:50:56:23:4A:8E;
fixed-address 192.168.8.120;
}
host server03 {
hardware ethernet 00:50:56:39:61:7A;
fixed-address 192.168.8.130;
}
default-lease-time 21600;
max-lease-time 43200;
next-server $next_server_v4;
……
(3)启动cobbler,同步配置
# systemctl enable --now cobblerd
# cobbler sync
(4)启动dhcp、tftp、http服务
# systemctl enable --now tftp httpd dhcpd
#生成引导加载程序 cobbler mkloaders ,此命令适用cobblerV3.3.1及之后的版本
# cobbler mkloaders
# 查看
# ls /var/lib/cobbler/loaders/
grub libcom32.c32 linux.c32 menu.c32
ldlinux.c32 libutil.c32 memdisk pxelinux.0
3、导入系统镜像资源
# 挂载光盘镜像
# mount /dev/cdrom /mnt/ #虚拟机挂载
# 导入系统镜像资源,并查看
cobbler profile add --name rocky-9-x86_64 --distro=rocky-9-x86_64 --autoinstall=rocky9.ks
# cobbler distro list
rocky-9-x86_64
# cobbler profile list
rocky-9-x86_64
注:导入的镜像资源存放在 /var/www/cobbler/distro_mirror/目录中。
#重启cobbler,同步配置
# systemctl restart cobblerd
# cobbler sync
#查看生成的启动菜单
# cat /var/lib/tftpboot/pxelinux.cfg/default
定义应答文件
# vi /var/lib/cobbler/templates/rocky9.ks
# version=Rocky9
ignoredisk --only-use=nvme0n1
# Partition clearing information
clearpart --all --initlabel
# Use graphical install
text
# Use CDROM installation media
# url --url=http://192.168.8.10/cblr/links/rocky9-x86_64/
url --url=$tree
reboot
# Keyboard layouts
keyboard --vckeymap=cn --xlayouts='cn'
# System language
lang en_US.UTF-8
selinux --disabled
firewall --disabled
# Network information
network --bootproto=dhcp --device=ens33 --ipv6=auto --activate
# Root password
rootpw --iscrypted $1$s14oAn0D$evyEyWiCjQGRaDrI8UeP90
# Run the Setup Agent on first boot
firstboot --enable
# Do not configure the X Window System
skipx
# System services
services --disabled="chronyd"
# System timezone
timezone Asia/Shanghai --isUtc --nontp
# Disk partitioning information
zerombr
part /boot --fstype="ext4" --ondisk=nvme0n1 --size=1024
part /swap --fstype="swap" --ondisk=nvme0n1 --size=2048
part / --fstype="xfs" --ondisk=nvme0n1 --grow --size=1
%packages
@base
@^minimal-environment
%end
%addon com_redhat_kdump --enable --reserve-mb='auto'
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/Rocky-*.repo
%end
%post
#!/bin/sh
#设置允许root用户ssh登录
echo "PermitRootLogin yes" >>/etc/ssh/sshd_config
sysemctl restart sshd
%end
%anaconda
pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
%end
#更新启动菜单
# cobbler profile remove --name rocky-9-x86_64
# cobbler profile add --name rocky-9-x86_64 --distro=rocky-9-x86_64 --autoinstall=rocky9.ks
重启cobbler,同步配置
# systemctl restart cobblerd
# cobbler sync
# cobbler profile list
rocky-9-x86_64
测试