毕业三年已经过去,光速又续费了三年
0x00.前言
还不是因为CentOS 8
提前停止支持,虽然良心云的公共镜像中含有AlmaLinux 8.5
亦或是Rocky Linux 8.5
但自己还是选择折腾封装红帽的自定义镜像,Self-Support
它不香吗?就翻红帽文档呗

0x01.自定义镜像
其实国外的公有云大都提供了RHEL
的镜像,而国内则只看到福报云和红帽有PY
交易:Red Hat云接入计划
出于安全性的考量,决定自己动手丰衣足食,坚决不用第三方提供的RHEL
镜像,良心云也提供了制作 Linux 镜像的文档
并且谷歌还搜索到了一步一步导入RHEL镜像到腾讯云,这下更有自信心了2333
0x02.cn-py-dl-r8
入口在云服务器
控制台的服务迁移
下,不管是在线迁移还是离线迁移都需要先在本地安装好系统,然后进行迁移
本着节省传输和迁移的时间决定使用离线迁移
的方法,并且目前在线迁移
处于公测期间,害得加群申请开通服务……
没有新版镜像就还是用rhel-8.5-x86_64-dvd.iso
,一顿操作猛如虎,很快就在vCenter
新装好了一台,毕竟之前已经装过一次了(
需要注意的是不需要默认勾选的GUI
类型,图形化桌面内存占用还是太高了#108271669063819198,安装完成之后照着良心云文档一步一步的检查
1. 确认OS
分区为MBR
分区,而非GPT
1 | [root@UPS-PC home]# parted -l /dev/sda | grep 'Partition Table' |
2. 确认操作系统以BIOS
方式启动,而非EFI
1 | [root@UPS-PC home]# ls /sys/firmware/efi |
3. 确认GRUB
使用硬盘UUID
挂载
首先查询到/root
的文件系统名称为/dev/sda1
,然后查询UUID
,最后检查/etc/fstab
发现已经是UUID
,并且未挂载其它硬盘
1 | [root@UPS-PC home]# df -TH |
4. 确认/etc/shadow
权限可以读写
1 | [root@UPS-PC home]# ll /etc/shadow |
5. 确认内核支持Virtio
驱动
很不幸RHEL 8.5
默认不支持,需要重新配置临时文件系统initramfs
1 | [root@UPS-PC home]# grep -i virtio /boot/config-$(uname -r) |
6. 安装cloud-init
使用RHEL
标准仓库自带源,毕竟都用红帽了果断拒绝良心云文档中的手动编译
1 | [root@UPS-PC home]# yum install cloud-init -y |
看来在cn-py-dl-r8
不注册是绕不过去了,subscription-manager
一条register --auto-attach
搞定,在执行这条命令之后还是一如既往的需要等待很久……
1 | [root@UPS-PC home]# subscription-manager register --username <rm> --password <rm> --auto-attach |
然后执行结束正准备安装cloud-init
的时候,发现害没完事儿(╯°□°)╯︵┻━┻
1 | [root@UPS-PC home]# yum install cloud-init -y |
2000 years later
点击此处 ← 查看折叠
1 | [root@UPS-PC home]# yum install cloud-init -y |
然后使用良心云提供的cloud.cfg
替代原有的
点击此处 ← 查看折叠
1 | [root@UPS-PC home]# cat /etc/cloud/cloud.cfg |
点击此处 ← 查看折叠
1 | [root@UPS-PC home]# echo '' > /etc/cloud/cloud.cfg |
执行init
检查相关配置是否成功,然后删掉缓存记录
1 | [root@UPS-PC ~]# cloud-init init --local |
得益于良心云文档的排版错误,差点儿错过三个步骤草
- 首先是添加
syslog
用户:useradd syslog
- 然后是修改服务单元文件
点击此处 ← 查看折叠
1 | [root@UPS-PC home]# cat /lib/systemd/system/cloud-init-local.service |
- 最后配置服务自启动
点击此处 ← 查看折叠
1 | [root@UPS-PC home]# systemctl status cloud-init-local |
7. 确认木有VMware tools
结果发现还真有,vCenter
这么快就给装上了……
1 | [root@UPS-PC home]# ps aux | grep vmtool |
不过是open-vm-tools
而不是通过.pl
脚本安装的
点击此处 ← 查看折叠
1 | [root@UPS-PC home]# find / -name 'vmware-uninstall-tools.p' |
8. 确认分区和大小
1 | [root@UPS-PC home]# mount |
9. 更改网络端口到eth0
网卡更换为
Virtio Nic
,默认只提供eth0
良心云文档中并没有写,参考前人在GRUB_CMDLINE_LINUX
追加net.ifnames=0 biosdevname=0
1 | [root@UPS-PC home]# cat /etc/default/grub |
然后重新编译GRUB
启动配置
1 | [root@UPS-PC home]# grub2-mkconfig -o /boot/grub2/grub.cfg |
最后修改网卡配置文件,并重命名ifcfg-ens192
至ifcfg-eth0
1 | [root@UPS-PC home]# cat /etc/sysconfig/network-scripts/ifcfg-ens192 |
至此终于搞完一半了,然后关机,导出OVF
模板,上传VMDK
至COS
,最后导入自定义镜像
本来以为不需要等待多久,结果过了一会儿还没完成不打算等了,没想到的是电脑关机后刚上床就导入完成了草#108267441787923547,只能白天继续来搞了……
此章节时间线#108266452237726140
0x03.cn-tx-bj1-r8
另一半则是开始着手重装cn-tx-bj1-c8
的系统,终于可以使用自己制作的rhel-85-x86-64-minimal
自定义镜像来安装了,成功启动!

虽然看到cloud-init
还是报了DNS
解析失败等错误,但是毕竟系统起来了可以后期慢慢修,并不知道会有多少坑等着呢……
然后的Linux
云主机初始化操作就异常娴熟了,简单列几点吧~
修改
hostname
等待重启1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30[root@VM-32-113-centos ~]# vi /etc/hosts
[root@VM-32-113-centos ~]# cat /etc/hosts
# Your system has configured 'manage_etc_hosts' as True.
# As a result, if you wish for changes to this file to persist
# then you will need to either
# a.) make changes to the master file in /etc/cloud/templates/hosts.redhat.tmpl
# b.) change or remove the value of 'manage_etc_hosts' in
# /etc/cloud/cloud.cfg or cloud-config from user-data
#
# The following lines are desirable for IPv4 capable hosts
127.0.0.1 cn-tx-bj1-r8 cn-tx-bj1-r8
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4
# The following lines are desirable for IPv6 capable hosts
::1 cn-tx-bj1-r8 cn-tx-bj1-r8
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
[root@VM-32-113-centos ~]# hostnamectl set-hostname cn-tx-bj1-r8
[root@VM-32-113-centos ~]# hostnamectl status
Static hostname: cn-tx-bj1-r8
Icon name: computer-vm
Chassis: vm
Machine ID: 0ba7a84d83404f9db63783a17f5fb6b1
Boot ID: b4668c56ec7a486b9d0992f03d795309
Virtualization: kvm
Operating System: Red Hat Enterprise Linux 8.5 (Ootpa)
CPE OS Name: cpe:/o:redhat:enterprise_linux:8::baseos
Kernel: Linux 4.18.0-348.el8.x86_64
Architecture: x86-64配置
SELINUX
为permissive
模式,执行重启1
2
3
4
5
6
7
8
9
10
11
12
13
14[root@VM-32-113-centos ~]# vi /etc/selinux/config
[root@VM-32-113-centos ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted修改
SSH
端口非22
,并放通防火墙,配置fail2ban
保护sshd
服务1
2
3
4
5
6[root@cn-tx-bj1-r8 ~]# firewall-cmd --add-port=<rm>/tcp
success
[root@cn-tx-bj1-r8 ~]# firewall-cmd --runtime-to-permanent
success
[root@cn-tx-bj1-r8 ~]# firewall-cmd --list-ports
<rm>/tcp试了一下可以直接访问红帽的源,但毕竟更换了环境还是重新注册下吧,可以看出系统
UUID
没有变化,暂时不需要重新生成1
2
3
4
5
6
7
8
9
10[root@cn-tx-bj1-r8 ~]# subscription-manager register --username <rm> --password <rm>
This system is already registered. Use --force to override
[root@cn-tx-bj1-r8 ~]# subscription-manager register --username <rm> --password <rm> --force
Unregistering from: subscription.rhsm.redhat.com:443/subscription
The system with UUID 5ad1c54f-024a-4445-b670-4be086022637 has been unregistered
All local data removed
Registering to: subscription.rhsm.redhat.com:443/subscription
The system has been registered with ID: 82cad6a2-54c5-427b-8df5-ea230fec0ca4
The registered system name is: cn-tx-bj1-r8
[root@cn-tx-bj1-r8 ~]# subscription-manager attach --auto最后查看内存占用,
used
部分并没有比Debain
更省内存?1
2
3
4[root@cn-tx-bj1-r8 ~]# free -h
total used free shared buff/cache available
Mem: 1.8Gi 152Mi 1.2Gi 9.0Mi 383Mi 1.5Gi
Swap: 1.0Gi 0B 1.0Gi
此章节时间线#108271381980874897
0x04.后记
cn-py-dl-r8
→cn-tx-bj1-r8
终于搞定了,最后删除cn-py-dl-r8
#108271667122964721,完结撒花🎉🎉🎉
至此本文使命完成