部署三臺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
測試