我试着使用升级工具将CentOS 6.5升级到CentOS 7
背景
CentOS 6的支持已于2020年11月30日结束。由于正在运行的项目需要升级版本,因此我尝试了一个名为CentOS Upgrade Tool的工具。
请注意!
如果您从上述链接跳转过去,您会发现…
上面标有“目前无法使用”。
似乎在CentOS 6.7以上的情况下,有些软件包的版本比CentOS 7的同一软件包更高,导致无法正常更新。
如果你有机会尝试,请注意…
当然的做法是在新建的CentOS 7(8嗎。。。我們先保留)上創建一個服務器,並添加所需的軟件包,然後進行數據遷移。
只是,由於預算和時間表等成年人的情況(?),如果需要在同一個服務器上進行升級,那麼我們應該知道有一個稱為升級工具的存在。这也是一个好主意。
升级的过程
-
- 安装升级工具
-
- 执行升级验证工具
-
- 确认和处理验证结果
-
- 执行升级工具
-
- 重新启动CentOS
- 确认版本升级
升级吧!
我们将按照上述流程继续进行工作!在开始工作前,请不要忘记备份…
1. 安装升级工具
将升级工具的存储库添加到 yum.repos.d 以安装。
# vi /etc/yum.repos.d/upgradetool.repo
(新規作成)
[upg]
name=CentOS-$releasever - Upgrade Tool
baseurl=https://buildlogs.centos.org/centos/6/upg/x86_64/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
安装。
# yum install redhat-upgrade-tool preupgrade-assistant-contents
Loaded plugins: fastestmirror, presto
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
错误…
由于CentOS 6在2020年11月30日停止支持,因此从镜像列表中删除了该服务器。
请注释掉以下配置中的mirrorlist行,并添加baseurl。
(必要时也可以更改[updates]和[extras]的配置。)
# cp -p /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bu
# vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os (※←コメントアウト)
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
baseurl=http://vault.centos.org/6.5/os/$basearch/ (※←追加)
重新安装。
# yum install redhat-upgrade-tool preupgrade-assistant-contents
Loaded plugins: fastestmirror, presto
Determining fastest mirrors
base | 3.7 kB 00:00
Not using downloaded repomd.xml because it is older than what we have:
Current : Fri Oct 24 22:59:03 2014
Downloaded: Thu Nov 28 07:08:25 2013
extras | 2.9 kB 00:00
Not using downloaded repomd.xml because it is older than what we have:
Current : Thu May 21 00:34:00 2015
Downloaded: Fri Nov 7 01:15:00 2014
updates | 2.9 kB 00:00
Not using downloaded repomd.xml because it is older than what we have:
Current : Thu Jul 2 21:22:31 2015
Downloaded: Fri Nov 7 01:20:59 2014
(途中は省略。。。)
Error Downloading Packages:
libxml2-2.7.6-17.el6_6.1.x86_64: failure: Packages/libxml2-2.7.6-17.el6_6.1.x86_64.rpm from updates: [Errno 256] No more mirrors to try.
openscap-1.0.8-1.0.1.el6.centos.1.x86_64: failure: Packages/openscap-1.0.8-1.0.1.el6.centos.1.x86_64.rpm from base: [Errno 256] No more mirrors to try.
yum-3.2.29-60.el6.centos.noarch: failure: Packages/yum-3.2.29-60.el6.centos.noarch.rpm from base: [Errno 256] No more mirrors to try.
libxml2-devel-2.7.6-17.el6_6.1.x86_64: failure: Packages/libxml2-devel-2.7.6-17.el6_6.1.x86_64.rpm from updates: [Errno 256] No more mirrors to try.
又出错了…
好像当我查看仓库时,下载的最新版本被认为是旧的。
我会备份当前存储的 yum 缓存。
# mv /var/cache/yum/x86_64 /tmp/
我将再次重新安装。
# yum install redhat-upgrade-tool preupgrade-assistant-contents
Loaded plugins: fastestmirror, presto
Determining fastest mirrors
base | 3.7 kB 00:00
base/primary_db | 4.4 MB 00:03
extras | 2.9 kB 00:00
extras/primary_db | 19 kB 00:00
updates | 2.9 kB 00:00
updates/primary_db | 5.9 MB 00:03
upg | 1.9 kB 00:00
upg/primary_db | 14 kB 00:00
(途中は省略。。。)
Installed:
preupgrade-assistant-contents.noarch 0:0.5.14-1.el6.centos redhat-upgrade-tool.noarch 1:0.7.22-3.el6.centos
Dependency Installed:
libgcrypt-devel.x86_64 0:1.4.5-11.el6_4 libgpg-error-devel.x86_64 0:1.7-4.el6 libxml2-devel.x86_64 0:2.7.6-14.el6_5.2 libxslt.x86_64 0:1.1.26-2.el6_3.1 libxslt-devel.x86_64 0:1.1.26-2.el6_3.1
openscap.x86_64 0:1.0.8-1.0.1.el6.centos.1 pcre-devel.x86_64 0:7.8-6.el6 preupgrade-assistant.x86_64 0:1.0.2-36.0.1.el6.centos zlib-devel.x86_64 0:1.2.3-29.el6
Dependency Updated:
libxml2.x86_64 0:2.7.6-14.el6_5.2 yum.noarch 0:3.2.29-43.el6.centos
Complete!
大功告成!
2. 运行升级验证工具
执行升级验证工具。
# preupg -s CentOS6_7
Preupg tool doesn't do the actual upgrade.
Please ensure you have backed up your system and/or data in the event of a failed upgrade
that would require a full re-install of the system from installation media.
Do you want to continue? y/n
y
Gathering logs used by preupgrade assistant:
(途中は省略。。。)
Tarball with results is stored here /root/preupgrade-results/preupg_results-201214042319.tar.gz .
The latest assessment is stored in directory /root/preupgrade .
Summary information:
We found some potential in-place upgrade risks.
Read the file /root/preupgrade/result.html for more details.
Upload results to UI by command:
e.g. preupg -u http://127.0.0.1:8099/submit/ -r /root/preupgrade-results/preupg_results-*.tar.gz .
一切问题都没有,顺利完成!
3. 确认和处理验证结果
我会确认検証結果是否已输出到 /root/preupgrade/result.html,并按要求阅读。
We have detected that you are using SELinux.
There were changes in policies which require to apply custom command before upgrade process.
In order to have working SELinux on CentOS 7, you <b>HAVE TO</b> run command prior to running redhat-upgrade-tool:semodule -r sandbox
请执行以下命令以执行升级。
# semodule -r sandbox
执行升级工具
在这一步,我们已经准备好进行升级了。
现在开始执行升级。
# redhat-upgrade-tool-cli --network 7 --cleanup-post --instrepo=http://vault.centos.org/centos/7.2.1511/os/x86_64/ --addrepo=CentOS7=http://mirror.centos.org/centos/7/os/x86_64/
setting up repos...
CentOS7 | 3.6 kB 00:00
CentOS7/primary_db | 6.1 MB 00:00
base | 3.7 kB 00:00
base/primary_db | 4.4 MB 00:03
cmdline-instrepo | 3.6 kB 00:00
cmdline-instrepo/primary_db | 5.3 MB 00:03
extras | 2.9 kB 00:00
extras/primary_db | 19 kB 00:00
updates | 2.9 kB 00:00
updates/primary_db | 5.9 MB 00:03
upg | 1.9 kB 00:00
upg/primary_db | 14 kB 00:00
zabbix | 951 B 00:00
zabbix/primary | 25 kB 00:00
zabbix-non-supported | 951 B 00:00
zabbix-non-supported/primary | 3.8 kB 00:00
.treeinfo | 1.1 kB 00:00
Preupgrade assistant risk check found risks for this upgrade.
You can run preupg --riskcheck --verbose to view these risks.
Addressing high risk issues is required before the in-place upgrade
and ignoring these risks may result in a broken upgrade and unsupported upgrade.
Please backup your data.
(途中は省略。。。)
testing upgrade transaction
rpm transaction 100% [========================================================]
rpm install 100% [========================================================]
setting up system for upgrade
Finished. Reboot to start upgrade.
胜利!!!!!!
5. CentOS的重新启动
为了应用CentOS 7,我们将重新启动。
但是,重新启动后的CentOS 7使用systemctl而不是service来启动进程,所以sshd无法启动。
我们将在重新启动后配置sshd以使其启动。
# vi /etc/rc.d/rc.local
(最後に追加)
systemctl enable sshd && systemctl start sshd.service
# chmod +x /etc/rc.d/rc.local
重新启动!
# reboot
Broadcast message from hoge
(/dev/pts/0) at 14:31 ...
The system is going down for reboot NOW!
6. 确认升级
当您重新启动后,我们将确认CentOS的版本。
$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
确实是 CentOS 7 了!!
“犒劳”
从这里开始,将进入项目特定的讨论。如果有任何相关的内容,请随意提出。
调整时区
默认情况下,时区设置为UTC(协调世界时),因此我将其更改为JST(日本标准时间)。
# timedatectl set-timezone Asia/Tokyo
# date
2020年 12月 14日 月曜日 14:38:04 JST
Zabbix代理自动启动。
升级后,自动启动的zabbix-agent停止了自动启动。
在启动时似乎没有在/var/run/目录下创建zabbix文件夹。
我已经设置了在启动时自动创建/var/run/zabbix文件夹。
vi /etc/tmpfiles.d/zabbix.conf
(新規追加)
#Type Path Mode UID GID Age Argument
d /var/run/zabbix 0755 zabbix zabbix -
NTP的时间同步
升级后,自动启动的NTP服务无法进行与其他服务器的时间同步处理。
在手动停止/启动NTP服务的情况下,可以进行同步。
查看NTP服务启动时的日志。
■自動起動時
12 Oct 07:43:11 ntpd[332]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
12 Oct 07:43:11 ntpd[332]: Listen and drop on 1 v6wildcard :: UDP 123
12 Oct 07:43:11 ntpd[332]: Listen normally on 2 lo 127.0.0.1 UDP 123
12 Oct 07:43:11 ntpd[332]: Listen normally on 3 lo ::1 UDP 123
12 Oct 07:43:11 ntpd[332]: Listening on routing socket on fd #20 for interface updates
12 Oct 07:43:11 ntpd[332]: Deferring DNS for mta01 1
12 Oct 07:43:11 ntpd[332]: Deferring DNS for mta02 1
12 Oct 07:43:11 ntpd[332]: 0.0.0.0 c016 06 restart
12 Oct 07:43:11 ntpd[332]: 0.0.0.0 c012 02 freq_set ntpd 31.109 PPM
12 Oct 07:43:11 ntpd[338]: signal_no_reset: signal 17 had flags 4000000
12 Oct 07:43:13 ntpd[338]: host name not found: mta01
12 Oct 07:43:13 ntpd[338]: host name not found: mta02
12 Oct 07:43:17 ntpd[332]: Listen normally on 4 eth0 10.0.xxx.xxx UDP 123
12 Oct 07:43:17 ntpd[332]: Listen normally on 5 eth0 fe80::4d2:72ff:fede:783b UDP 123
12 Oct 07:43:17 ntpd[332]: new interface(s) found: waking up resolver
■手動起動時
12 Oct 10:00:15 ntpd[2777]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
12 Oct 10:00:15 ntpd[2777]: Listen and drop on 1 v6wildcard :: UDP 123
12 Oct 10:00:15 ntpd[2777]: Listen normally on 2 lo 127.0.0.1 UDP 123
12 Oct 10:00:15 ntpd[2777]: Listen normally on 3 eth0 10.0.xxx.xxx UDP 123
12 Oct 10:00:15 ntpd[2777]: Listen normally on 4 lo ::1 UDP 123
12 Oct 10:00:15 ntpd[2777]: Listen normally on 5 eth0 fe80::4d2:72ff:fede:783b UDP 123
12 Oct 10:00:15 ntpd[2777]: Listening on routing socket on fd #22 for interface updates
嗯。。。
由于自动启动时输出”Deferring DNS for mta01″,看起来同步目标服务器不可见。
似乎在自动启动时,eth0 的识别稍微有点延迟。这可能是原因吗?
让我们查看 /usr/lib/systemd/system/ntpd.service 的设置。
# vi /usr/lib/systemd/system/ntpd.service
[Unit]
Description=Network Time Service
After=syslog.target ntpdate.service sntp.service
[Service]
Type=forking
EnvironmentFile=-/etc/sysconfig/ntpd
ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS
PrivateTmp=true
[Install]
WantedBy=multi-user.target
在[Unit]的After配置中添加network.target。
# vi /usr/lib/systemd/system/ntpd.service
[Unit]
Description=Network Time Service
After=syslog.target network.target ntpdate.service sntp.service
↑(追加)
[Service]
Type=forking
EnvironmentFile=-/etc/sysconfig/ntpd
ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS
PrivateTmp=true
[Install]
WantedBy=multi-user.target
更新更改。
# systemctl daemon-reload
现在,在自动启动时,时间同步处理可以正常执行。
14 Oct 18:31:40 ntpd[583]: ntp_io: estimated max descriptors: 1024, initial socket boundary: 16
14 Oct 18:31:40 ntpd[583]: Listen and drop on 0 v4wildcard 0.0.0.0 UDP 123
14 Oct 18:31:40 ntpd[583]: Listen and drop on 1 v6wildcard :: UDP 123
14 Oct 18:31:40 ntpd[583]: Listen normally on 2 lo 127.0.0.1 UDP 123
14 Oct 18:31:40 ntpd[583]: Listen normally on 3 eth0 10.0.111.115 UDP 123
14 Oct 18:31:40 ntpd[583]: Listening on routing socket on fd #20 for interface updates
结束了。