一、 升級背景原因
公司因業務需要購買了一台工作站,預裝的是win10系統,公司需要centos7.8系統,則進行系統的更改,但是在更改安裝系統時無法直接安裝centos7.8系統,經過多番嘗試確定只能安裝centos6.8系統,最后只能安裝后再進行升級!
二、 升級過程
首先在安裝的centos6.8系統執行yum update –y升級到6.10,再開始升級到7.2,再升級到7.8就ok啦!
1.首先下載yum源,
wget –O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
2.更新源
#vim /etc/yum.repos.d/upgrade.repo
[upgrade]
name=upgrade
baseurl=https://buildlogs.centos.org/centos/6/upg/x86_64/
enable=1
gpgcheck=0
3. 卸載6.x自帶的較新的助手,並安裝老版,否則會報錯。(我的版本中沒有可卸載的安裝包)
#yum erase openscap -y
#以下無法連接
#yum install http://dev.centos.org/centos/6/upg/x86_64/Packages/openscap-1.0.8-1.0.1.el6.centos.x86_64.rpm -y
#以下兩個連接都有效
yum install ftp://ftp.pbone.net/mirror/ftp.scientificlinux.org/linux/scientific/6.5/x86_64/updates/fastbugs/openscap-1.0.8-1.el6_5.x86_64.rpm -y
yum install https://buildlogs.centos.org/centos/6/upg/x86_64/Packages/openscap-1.0.8-1.0.1.el6.centos.x86_64.rpm -y
4. 安裝升級系統助手
#利用到upgrade.repo源
#yum install redhat-upgrade-tool preupgrade-assistant-contents -y
5.檢測是否可以升級
#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:
All installed packages : 01/11 ...finished (time 00:00s)
All changed files : 02/11 ...finished (time 01:56s)
Changed config files : 03/11 ...finished (time 00:00s)
All users : 04/11 ...finished (time 00:00s)
All groups : 05/11 ...finished (time 00:00s)
RedHat signed packages : 10/11 ...finished (time 00:00s)
CentOS signed packages : 11/11 ...finished (time 00:00s)
......
Tarball with results is stored here /root/preupgrade-results/preupg_results-200304120406.tar.gz .
The latest assessment is stored in directory /root/preupgrade .
Summary information:
We found some critical issues. In-place upgrade is not advised.
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 .
6.導入CentOS7的key
#rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
7.開始升級
#嘗試過多個系統版本,均無法升級。
#centos-upgrade-tool-cli --network 7 --instrepo=http://vault.centos.org/centos/7.2.1511/os/x86_64/ --force
setting up repos...
cmdline-instrepo
cmdline-instrepo/primary_db
No upgrade available for the following repos: base extras updates upgrade.treeinfo
preupgrade-assistant risk check found EXTREME risks for this upgrade.
Run preupg --riskcheck --verbose to view these risks.
Continuing with this upgrade is not recommended.
然后使用清華大學的源就沒問題了
centos-upgrade-tool-cli --network 7 --instrepo=https://mirrors.tuna.tsinghua.edu.cn/centos-vault/7.2.1511/os/x86_64/ --force
也可以下載鏡像升級,
上傳Centos7.2-DVD.iso文件
執行升級操作
centos-upgrade-tool-cli --iso=/path/centos7.2-dvd.iso --force
結束后進行重啟
setting up repos...
.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.
...
...
(276/277): zlib-1.2.7-17.el7.x86_64.rpm | 90 kB 00:00
(277/277): zlib-devel-1.2.7-17.el7.x86_64.rpm | 50 kB 00:00
testing upgrade transaction
rpm transaction 100% [======================================================================================================================================================]
rpm install 100% [==========================================================================================================================================================]
setting up system for upgrade
Finished. Reboot to start upgrade.
重啟后查看升級后的系統版本
cat /etc/redhat-release
#CentOS Linux release 7.2.1511 (Core)
配置Centos7.4的yum源地址(可不做)
執行升級命令即可
yum upgrade 和 yum update -y
三、 升級后的問題處理
檔升級完重啟后,發現無法進行ssh連接,
ssh: connect to host x.x.x.x port 22: Connection refused
好吧,不是還可以登錄 web 的終端,接上顯示器后發現網卡和yum源都不好使,登錄上,看到確實升級到了 CentOS 7 了,查看 sshd 服務情況,確實服務沒啟動:
# systemctl status sshd
- ● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since 三 2017-03-15 15:05:33 CST; 24s ago
Docs: man:sshd(8)
man:sshd_config(5)
Process: 1788 ExecStart=/usr/sbin/sshd $OPTIONS (code=exited, status=127)
Main PID: 1696 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/sshd.service
├─1710 sshd: root@pts/0
├─1712 -bash
└─1789 systemctl status sshd
3月 15 15:05:33 allen05ren systemd[1]: sshd.service: control process exited, code=exited status=127
3月 15 15:05:33 allen05ren systemd[1]: Failed to start OpenSSH server daemon.
3月 15 15:05:33 allen05ren systemd[1]: Unit sshd.service entered failed state.
3月 15 15:05:33 allen05ren systemd[1]: sshd.service failed.
那就啟動一下看看,發現啟動不了,那就重新安裝一下 ssh 服務,發現 yum 用不了:
# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
libsasl2.so.2: cannot open shared object file: No such file or directory
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.5 (default, Nov 20 2015, 02:00:19)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)]
If you cannot solve this problem yourself, please go to
the yum faq at:
http://yum.baseurl.org/wiki/Faq
不行就重新安裝一下 yum 看看,看看 rpm 安裝了什么版本的 yum,好吧 rpm 也用不了:
# rpm -qa|grep yum
grep: error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory
搜索引擎搜索,發現只要做個軟連接就可以了:
# ls -l /usr/lib64/libsasl2.so*
lrwxrwxrwx 1 root root 17 3月 15 14:14 /usr/lib64/libsasl2.so -> libsasl2.so.3.0.0
lrwxrwxrwx 1 root root 17 3月 15 14:12 /usr/lib64/libsasl2.so.3 -> libsasl2.so.3.0.0
-rwxr-xr-x 1 root root 121296 11月 21 2015 /usr/lib64/libsasl2.so.3.0.0
# ln -s /usr/lib64/libsasl2.so.3.0.0 /usr/lib64/libsasl2.so.2
# yum
Loaded plugins: fastestmirror
You need to give some command
Usage: yum [options] COMMAND
List of Commands:
check Check for problems in the rpmdb
check-update Check for available package updates
clean Remove cached data
deplist List a package's dependencies
libpcre.so.0 也軟連接一下,都恢復正常了:
# ls -l /usr/lib64/libpcre.so*
lrwxrwxrwx 1 root root 16 3月 15 14:13 /usr/lib64/libpcre.so -> libpcre.so.1.2.0
lrwxrwxrwx 1 root root 16 3月 15 14:12 /usr/lib64/libpcre.so.1 -> libpcre.so.1.2.0
-rwxr-xr-x 1 root root 398272 11月 20 2015 /usr/lib64/libpcre.so.1.2.0
# ln -s /usr/lib64/libpcre.so.1.2.0 /usr/lib64/libpcre.so.0
# rpm -qa|grep yum
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-plugin-fastestmirror-1.1.31-34.el7.noarch
yum-3.4.3-132.el7.centos.0.1.noarch
發現再啟動 ssh 服務也可以正常啟動了,可以愉快地連接了。
整個升級過程差不多就告一段落了,再繼續升級或做一些收尾的工作,比如上面升級時提示存在的哪些問題,然后再執行:
#查看殘留的 CentOS 6.x 的文件包
rpm -qa | grep -i el6
查看一下殘留的 CentOS 6.x 的文件包,不用的就卸載或卸載后重新安裝 CentOS 7.x 的版本,這里就又遇到一個問題:grep 包還是 CentOS 6.x 的版本(雖然不影響使用)且版本號比當前 CentOS 7.x 的版本的版本還高,並且有大量其他包依賴此包,這時候就可以使用 yum 的軟件包降版本命令:
yum downgrade grep
1
yum update 更新過程中報錯
Finished Dependency Resolution
Error: Package: nettle-3.2-2.el6.x86_64 (epel)
Requires: libgmp.so.3()(64bit)
Error: Package: gnutls-3.3.26-9.el7.x86_64 (base)
Requires: libnettle.so.4()(64bit)
Removing: nettle-2.7.1-4.el7.x86_64 (installed)
libnettle.so.4()(64bit)
Updated By: nettle-3.2-2.el6.x86_64 (epel)
~libnettle.so.6()(64bit)
Available: nettle-2.7.1-8.el7.x86_64 (base)
libnettle.so.4()(64bit)
Error: Package: gnutls-3.3.26-9.el7.x86_64 (base)
Requires: libhogweed.so.2()(64bit)
Removing: nettle-2.7.1-4.el7.x86_64 (installed)
libhogweed.so.2()(64bit)
Updated By: nettle-3.2-2.el6.x86_64 (epel)
~libhogweed.so.4()(64bit)
Available: nettle-2.7.1-8.el7.x86_64 (base)
libhogweed.so.2()(64bit)
You could try using --skip-broken to work around the problem
** Found 28 pre-existing rpmdb problem(s), 'yum check' output follows:
cloog-ppl-0.15.7-1.2.el6.x86_64 has missing requires of libgmp.so.3()(64bit)
elfutils-libs-0.163-3.el7.x86_64 has missing requires of elfutils-libelf(x86-64) = ('0', '0.163', '3.el7')
libgcj-4.4.7-18.el6.x86_64 has missing requires of libgmp.so.3()(64bit)
libkadm5-1.10.3-65.el6.x86_64 has missing requires of krb5-libs(x86-64) = ('0', '1.10.3', '65.el6')
libkadm5-1.10.3-65.el6.x86_64 has missing requires of libkdb5.so.6()(64bit)
libkadm5-1.10.3-65.el6.x86_64 has missing requires of libkdb5.so.6(kdb5_6_MIT)(64bit)
ppl-0.10.2-11.el6.x86_64 has missing requires of libgmp.so.3()(64bit)
python-argparse-1.2.1-2.1.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-backports-ssl_match_hostname-3.4.0.2-5.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-crypto-2.6.1-2.el6.x86_64 has missing requires of libpython2.6.so.1.0()(64bit)
python-crypto-2.6.1-2.el6.x86_64 has missing requires of python(abi) = ('0', '2.6', None)
python-futures-3.0.3-1.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-jinja2-2.7.3-1.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-msgpack-0.4.6-1.el6.x86_64 has missing requires of libpython2.6.so.1.0()(64bit)
python-msgpack-0.4.6-1.el6.x86_64 has missing requires of python(abi) = ('0', '2.6', None)
python-requests-2.6.0-4.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-requests-2.6.0-4.el6.noarch has missing requires of python-ordereddict >= ('0', '1.1', None)
python-tornado-4.2.1-1.el6.x86_64 has missing requires of libpython2.6.so.1.0()(64bit)
python-tornado-4.2.1-1.el6.x86_64 has missing requires of python(abi) = ('0', '2.6', None)
python-urllib3-1.10.2-3.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-urllib3-1.10.2-3.el6.noarch has missing requires of python-ordereddict
python-zmq-14.5.0-2.el6.x86_64 has missing requires of libpython2.6.so.1.0()(64bit)
python-zmq-14.5.0-2.el6.x86_64 has missing requires of python(abi) = ('0', '2.6', None)
1:redhat-upgrade-tool-0.7.22-3.el6.centos.noarch has missing requires of preupgrade-assistant >= ('0', '1.0.2', '4')
1:redhat-upgrade-tool-0.7.22-3.el6.centos.noarch has missing requires of python(abi) = ('0', '2.6', None)
salt-2016.3.4-1.el6.noarch has missing requires of /usr/bin/python2.6
salt-2016.3.4-1.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
salt-minion-2016.3.4-1.el6.noarch has missing requires of /usr/bin/python2.6
這是由於EPEL版本不對導致的,依次執行下面的命令就好了
yum remove epel-release
yum --enablerepo=extras install epel-release
yum clean all
執行完上面的命令后有可能還會報下面的錯
** Found 28 pre-existing rpmdb problem(s), 'yum check' output follows:
cloog-ppl-0.15.7-1.2.el6.x86_64 has missing requires of libgmp.so.3()(64bit)
elfutils-libs-0.163-3.el7.x86_64 has missing requires of elfutils-libelf(x86-64) = ('0', '0.163', '3.el7')
libgcj-4.4.7-18.el6.x86_64 has missing requires of libgmp.so.3()(64bit)
libkadm5-1.10.3-65.el6.x86_64 has missing requires of krb5-libs(x86-64) = ('0', '1.10.3', '65.el6')
libkadm5-1.10.3-65.el6.x86_64 has missing requires of libkdb5.so.6()(64bit)
libkadm5-1.10.3-65.el6.x86_64 has missing requires of libkdb5.so.6(kdb5_6_MIT)(64bit)
ppl-0.10.2-11.el6.x86_64 has missing requires of libgmp.so.3()(64bit)
python-argparse-1.2.1-2.1.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-backports-ssl_match_hostname-3.4.0.2-5.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-crypto-2.6.1-2.el6.x86_64 has missing requires of libpython2.6.so.1.0()(64bit)
python-crypto-2.6.1-2.el6.x86_64 has missing requires of python(abi) = ('0', '2.6', None)
python-futures-3.0.3-1.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-jinja2-2.7.3-1.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-msgpack-0.4.6-1.el6.x86_64 has missing requires of libpython2.6.so.1.0()(64bit)
python-msgpack-0.4.6-1.el6.x86_64 has missing requires of python(abi) = ('0', '2.6', None)
python-requests-2.6.0-4.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-requests-2.6.0-4.el6.noarch has missing requires of python-ordereddict >= ('0', '1.1', None)
python-tornado-4.2.1-1.el6.x86_64 has missing requires of libpython2.6.so.1.0()(64bit)
python-tornado-4.2.1-1.el6.x86_64 has missing requires of python(abi) = ('0', '2.6', None)
python-urllib3-1.10.2-3.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
python-urllib3-1.10.2-3.el6.noarch has missing requires of python-ordereddict
python-zmq-14.5.0-2.el6.x86_64 has missing requires of libpython2.6.so.1.0()(64bit)
python-zmq-14.5.0-2.el6.x86_64 has missing requires of python(abi) = ('0', '2.6', None)
1:redhat-upgrade-tool-0.7.22-3.el6.centos.noarch has missing requires of preupgrade-assistant >= ('0', '1.0.2', '4')
1:redhat-upgrade-tool-0.7.22-3.el6.centos.noarch has missing requires of python(abi) = ('0', '2.6', None)
salt-2016.3.4-1.el6.noarch has missing requires of /usr/bin/python2.6
salt-2016.3.4-1.el6.noarch has missing requires of python(abi) = ('0', '2.6', None)
salt-minion-2016.3.4-1.el6.noarch has missing requires of /usr/bin/python2.6
這是由於python相關的包不對導致的可以先卸載上面的python包,然后在重裝就好了
#卸載python-urllib3
yum remove python-urllib3 -y
#安裝python-urllib3
yum install python-urllib3 -y
我的沒有這個包;
百度了一圈,有的說是安裝包沖突導致的;然后卸載掉沖突的包再執行就OK啦!
比如:yum -y remove grub2-common* openldap
注意:當卸載掉openldap后,出現了yum、sshd奔潰的問題;
yum命令后出現libldap-2.4.so.2: cannot open shared object file
# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
libldap-2.4.so.2: cannot open shared object file: No such file or directory
Please install a package which provides this module, or
verify that the module is installed correctly.
解決方案:
下載如下一些包(我的系統是centos7的),辛虧提前安裝了wget,通外網;要不然就慘了
# rpm -ivh --force --nodeps openldap-2.4.23-32.el6_4.1.x86_64.rpm
warning: openldap-2.4.23-32.el6_4.1.x86_64.rpm: Header V4 DSA/SHA1 Signature, key ID 192a7d7d: NOKEY
Preparing... ########################################### [100%]
1:openldap ########################################### [100%]
然后yum就好使了!
最后一個問題是:
網卡啟動失敗,但是ip地址獲取正常
Failed to start LSB: Bring up/down networking.
解決方案:
造成網卡不能使用的原因是,系統后MAC地址已經更改但是在系統內部的配置文件還沒有更,這就導致了真實的MAC地址與配置文件中的MAC地址不一致。
第一種辦法直接關閉NetworManager
systemctl stop NetworkManager centos7系統沒啟動這個服務
第二種辦法修改配置文件
/etc/udev/rules.d/70-persistent-net.rules只要70-persistent-net.rules配置文件中的MAC地址與ifcfg-xxx的MAC地址相同就可以了。但是我打開70-persistent-net.rules配置文件發現配置文件全是注釋,然后就直接在ifcfg-xxx文件中添加了HWADDR=MAC 對應的MAC地址。
修改完配置文件后發現還是提示錯誤。
vim /etc/udev/rules.d/70-persistent-net.rules 網卡中添加了也不好使
第三種辦法
使用這一條命令將清除協議地址,盡然還是不管用,無奈之下重啟系統,發現重啟后網絡服務恢復正常。
ip addr flush dev ens33/eth0 這個方法是可以成功解決問題的
Failed to start LSB: Bring up/down networking 的報錯就是因為升級后真實的MAC地址與配置文件的MAC地址不相符造成的,使用以上三種辦法試着解決。最后不要忘了重啟系統。
四、 參考文檔
https://blog.51cto.com/sky9896/2475359
https://blog.csdn.net/you227/article/details/79140913
https://www.jianshu.com/p/e44b274efb83
白駒過隙,當看到比你優秀的人比你還努力的時候,你也會越來越優秀,相信越努力越幸運!