重装系统的要求:
不登陆IPMI修改各种信息【包括:1.启动项 2.系统版本 3.修改固定IP】
目录
# 6. 将cobbler、httpd、dhcp、xinetd添加到开机自启
# 11. 启动服务httpd、cobbler,然后检查cobbler
背景:
最近新到一批服务器,厂家已经装过系统了,但是有好多点不符合需求。
服务器分2种用途,一是“存储节点”,二是“计算节点”
1. 重装系统的问题:
- 修改启动项
- 选择系统盘【物理服务器的系统盘不都是sda,有可能是sd*,也有可能是其他的字符】
- IP地址的随机分配
2. 解决思路:
- 用koan服务,解决修改启动项的问题
- 用2个ks文件【存储、计算各一个】,解决系统盘名称不一样的问题
- 用dhcp分配固定的IP地址,解决IP随机分配的问题
环境:
cobbler服务器:
系统:CentOS7.9 IP: 10.100.40.200
客户端:
1> 存储节点:
系统: Centos7.9 IP范围: 10.100.40.1 - 10.100.40.12
2> 计算节点:
系统: Centos7.9 IP范围: 10.100.40.13-10.100.40.18
Cobbler服务端安装
# 1. 关闭selinux、firewall
sed -i s/SELINUX=enforcing/SELINUX=disabled/g /etc/selinux/config
setenforce 0
systemctl disable firewalld.service
systemctl stop firewalld.service
systemctl status firewalld.service
# 2. 调整软件源为国内阿里云
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && yum -y install epel-release
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
# 3. 查看cobbler包
yum search all cobbler

# 4. 安装cobbler
yum -y install cobbler cobbler-web
# 5. 安装dhcp、httpd、xinetd
yum -y install dhcp httpd xinetd pykickstart fence-agents
# 6. 将cobbler、httpd、dhcp、xinetd添加到开机自启
systemctl enable cobblerd.service
systemctl enable httpd.service
systemctl enable dhcpd.service
systemctl enable xinetd.service
# 7. 配置环境
# 先备份一个配置文件 以防不时之需
cp /etc/cobbler/settings{,.bak}
vim /etc/cobbler/settings
| next_server: 10.100.40.200 server: 10.100.40.200 manage_dhcp: 0 #设置为1时,开启cobbler的dhcp管理器 这里不开启,因为之前测试开不开启并没有什么用 都得再配置dhcpd的配置文件 manage_rsync: 1 #设置为1时,开启cobbler的rsync管理器 |
# 8. 生成密码串
# 这个密码就是安装完系统之后的root密码
# 默认为cobbler,配置文件内有注释信息,但是必须要改的,不然后期启动会有问题,提前改了省事
# 格式:
# openssl passwd -1 -salt "任意字符" “密码”
openssl passwd -1 -salt 'suiji' 'centos'
# ... ... # 有输出,这里就不展示了
vim /etc/cobbler/settings
| default_password_crypted: "$1$suiji$21AVC9PiNBQVCgKL7SVrO1" |
# 9. 启用xinetd
# 将disable的值改为“no”
vim /etc/xinetd.d/tftp

systemctl restart xinetd.service
# 10. 启用dhcp服务
# 按以下配置dhcp的话,分配到ip地址后可以直接上网(只要你的网络环境没有问题)
# 备份原始配置文件
cp /etc/dhcp/dhcpd.conf{,.bak}

subnet 10.100.40.0 netmask 255.255.255.0 {
option routers 10.100.40.254;
option domain-name-servers 100.64.2.4;
option subnet-mask 255.255.255.0;
default-lease-time 21600;
max-lease-time 43200;
range 10.100.40.1 10.100.40.20;
next-server 10.100.40.200;
filename "pxelinux.0";
}
host ceph-1 {
hardware ethernet 40:a6:b7:4b:5f:e8;
fixed-address 10.100.40.1;
}
# ... ... 省略一万字
systemctl restart dhcpd.service
systemctl status dhcpd.service
# 11. 启动服务httpd、cobbler,然后检查cobbler
# 只要有修改就把如下的都执行,要多用“cobbler check”
systemctl restart httpd.service
systemctl restart cobblerd.service
cobbler check
cobbler get-loaders
systemctl enable rsyncd.service
systemctl restart rsyncd.service
cobbler sync
cobbler check

# 最后剩下一个 是用来安装debian系统的 我不需要 我就不安装了
# 12. 导入ISO镜像【这里用方式2】
# 记得提前把iso文件上传到 "/root" 下
方式1:
虚拟机的话,在vmware workstation中直接把iso文件放到虚拟CD/DVD中即可
方式2:
直接将iso文件到目录,如下:
mount -o loop /root/CentOS-7-x86_64-DVD-2009.iso /mnt/
导入镜像文件到cobbler
cobbler import --path=/mnt/ --name=CentOS7.9_2009
cobbler import --path=/mnt/ --name=CentOS7.9_2009_jisuan

# 显示导入的镜像
cobbler distro list

# 13. 修改引导配置文件
# cobbler自带的引导模板文件 “/etc/cobbler/pxe/pxedefault.template”
vim /var/lib/tftpboot/pxelinux.cfg/default
DEFAULT menu
PROMPT 0
MENU TITLE Cobbler | http://cobbler.github.io/
TIMEOUT 200
TOTALTIMEOUT 6000
ONTIMEOUT local
# LABEL local
# MENU LABEL (local)
# MENU DEFAULT
# LOCALBOOT -1
LABEL CentOS7.9_2009-x86_64
kernel /images/CentOS7.9_2009-x86_64/vmlinuz
MENU LABEL CentOS7.9_2009-x86_64
append initrd=/images/CentOS7.9_2009-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://10.100.40.200/cblr/svc/op/ks/profile/CentOS7.9_2009-x86_64
ipappend 2
LABEL CentOS7.9_2009_jisuan-x86_64
kernel /images/CentOS7.9_2009_jisuan-x86_64/vmlinuz
MENU LABEL CentOS7.9_2009_jisuan-x86_64
append initrd=/images/CentOS7.9_2009_jisuan-x86_64/initrd.img ksdevice=bootif lang= kssendmac text ks=http://10.100.40.200/cblr/svc/op/ks/profile/CentOS7.9_2009_jisuan-x86_64
ipappend 2
MENU end
| 注释: DEFAULT menu #指定默认引导入口名称(假如指定的是menu,他会一直在menu的界面等待,除非用户敲了回车,才回去安装,否则一直在等待) PROMPT 0 #是否等待用户选择(1表示等待 0表示不等待) LABEL CentOS7.9_2009-x86_64 #启动项 |
# 14. 修改镜像使用的ks文件
# cobbler默认会带好多默认的ks文件,学习用的话倒是足够了,但是生产环境的话,还是需要专门定制的
# 我用的套路是,先手动装一台,然后把 “/root/anaconda-ks.cfg” 拿过来再修改
# 这里列2个我修改过的,另外ks文件倒是可以添加脚本,但是有一些限制,所以如下的ks文件就去掉了执行脚本,有这会儿功夫还不如学学ansible... ...
vim /var/lib/cobbler/kickstarts/centos7.9-2009.cfg
| auth --enableshadow --passalgo=sha512 url --url=$tree graphical firstboot --enable ignoredisk --only-use=sdm keyboard --vckeymap=us --xlayouts='us' lang en_US.UTF-8 network --bootproto=dhcp --device=eno1 --onboot=off --ipv6=auto --no-activate network --bootproto=dhcp --device=eno2 --onboot=off --ipv6=auto network --bootproto=dhcp --device=eno3 --onboot=off --ipv6=auto network --bootproto=dhcp --device=eno4 --onboot=off --ipv6=auto network --bootproto=dhcp --device=ens3f0 --onboot=on --ipv6=auto network --bootproto=dhcp --device=ens3f1 --onboot=on --ipv6=auto rootpw --plaintext centos services --disabled="chronyd" timezone Asia/Shanghai --isUtc --nontp bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sdm clearpart --all --initlabel # clearpart --all --initlabel --drives=sdm part /boot --fstype="xfs" --ondisk=sdm --size=1024 part pv.743 --fstype="lvmpv" --ondisk=sdm --size=226903 volgroup centos --pesize=4096 pv.743 logvol / --fstype="xfs" --size=218708 --name=root --vgname=centos logvol swap --fstype="swap" --size=8192 --name=swap --vgname=centos reboot %packages @^infrastructure-server-environment @base @core kexec-tools %end %addon com_redhat_kdump --enable --reserve-mb='auto' %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 |
vim /var/lib/cobbler/kickstarts/centos7.9-2009_jisuan.cfg
| auth --enableshadow --passalgo=sha512 url --url=$tree graphical firstboot --enable ignoredisk --only-use=sda keyboard --vckeymap=us --xlayouts='us' lang en_US.UTF-8 network --bootproto=dhcp --device=eno1 --onboot=off --ipv6=auto --no-activate network --bootproto=dhcp --device=eno2 --onboot=off --ipv6=auto network --bootproto=dhcp --device=eno3 --onboot=off --ipv6=auto network --bootproto=dhcp --device=eno4 --onboot=off --ipv6=auto network --bootproto=dhcp --device=ens1 --onboot=on --ipv6=auto network --bootproto=dhcp --device=ens3 --onboot=on --ipv6=auto rootpw --plaintext centos services --disabled="chronyd" timezone Asia/Shanghai --isUtc --nontp bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda clearpart --all --initlabel # clearpart --all --initlabel --drives=sda part /boot --fstype="xfs" --ondisk=sda --size=1024 part pv.231 --fstype="lvmpv" --ondisk=sda --size=226702 part /boot/efi --fstype="efi" --ondisk=sda --size=200 --fsoptions="umask=0077,shortname=winnt" volgroup centos --pesize=4096 pv.231 logvol swap --fstype="swap" --size=8192 --name=swap --vgname=centos logvol / --fstype="xfs" --size=218508 --name=root --vgname=centos reboot %packages @^infrastructure-server-environment @base @core kexec-tools %end %addon com_redhat_kdump --enable --reserve-mb='auto' %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 distro list
# 显示镜像报告(镜像配置信息)
cobbler profile report
# 为2个镜像指定ks文件
cobbler profile edit --name=CentOS7.9_2009-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.9-2009.cfg
cobbler profile edit --name=CentOS7.9_2009_jisuan-x86_64 --kickstart=/var/lib/cobbler/kickstarts/centos7.9-2009_jisuan.cfg
# 显示镜像报告(镜像配置信息)
cobbler profile report


# 扩展命令
# 删除镜像配置信息
cobbler profile remove --name centos7.2-x86_64
# 删除镜像[需要先删除镜像配置信息]
cobbler distro remove --name centos7.2-x86_64
开始重装【被重装的主机上执行】
# 注意此部分操作均在 要重新装系统的机器上操作
# 用此方式,被安装的主机必须要有linux操作系统,因为需要安装koan服务,此服务会在 “老系统”的
“/boot/grub2/grub.cfg” 文件添加启动引导,如下图所示

# 下图为在IPMI上截取

# 安装koan【被重装的主机上执行】
yum -y install epel-release && yum -y install koan
# 查看cobbler服务器上的系统版本列表【被重装的主机上执行】
koan --server=10.100.40.200 --list=profiles

# 选择镜像【被重装的主机上执行】
# 存储节点
koan --server=10.100.40.200 --profile=CentOS7.9_2009-x86_64 --replace-self
# 计算节点
koan --server=10.100.40.200 --profile=CentOS7.9_2009_jisuan-x86_64 --replace-self

# 重启即可开始安装【被重装的主机上执行】
reboot
496

被折叠的 条评论
为什么被折叠?



