「CentOS」- 安装与升级

组成

系统内核 Linux Kernel

How to Upgrade the Linux Kernel on CentOS 7 | PhoenixNAP KB
How to Upgrade the Linux Kernel on CentOS 7
How to set default boot kernel on Linux ( CentOS / RHEL 7 )

# 升级系统
yum update -y

# 添加 ELRepo 仓库
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh https://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm

# 查看可用内核版本
yum list available --disablerepo='*' --enablerepo=elrepo-kernel

# 安装新内核
yum remove -y kernel-headers kernel-tools kernel-tools-libs
yum --enablerepo="elrepo-kernel" install -y kernel-ml kernel-ml-devel \
    kernel-ml-headers kernel-ml-tools kernel-ml-tools-libs kernel-ml-tools-libs-devel

# 重新启动系统,并手动选择内核版本,验证功能
# 略……

# 设置默认内核版本
grub2-set-default 0
grub2-mkconfig -o /boot/grub2/grub.cfg
reboot

网络管理 NetworkManager

在 CentOS 7.x 中,使用 NetworkManager 管理网络。现在官方保证 NetworkMangaer 稳定可用,我们就紧跟步伐。将来无论 NetworkManager 是否被其他工具替代,都不太可能回到直接修改配置文件的管理方式。

闪屏组件 Plymouth

WIP

性质

内核模块管理

CentOS 7.4 | Products & Services/Product Documentation/Red Hat Enterprise Linux/7.4/Kernel Administration Guide

# 以 virtio-net.ko 模块为例
cat > /etc/modules-load.d/virtio-net.conf <<EOF
# Load virtio-net.ko at boot
virtio-net
EOF

CentOS 6.5 | Remember to load your kernel modules at boot | How to load modules on boot CentOS 6.x

# 以 Bonding 模块为例:
cat > /etc/sysconfig/modules/bonding.modules <<EOF
#!/bin/sh
exec /sbin/modprobe bonding 2>&1
EOF

chmod 755 /etc/sysconfig/modules/bonding.modules

时区设置 Check and Set Timezone

该部分将记录常见 Linux 发行的时区查看设置方法。

CentOS 6.x(通用方法)
Setup Timezone and NTP on CentOS 6
How to check which timezone in Linux?

查看当前时区,如下输出表示当前市区为 Asia/Shanghai:

# date '+%Z %z'
CST +0800

设置时区:

ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

# 2025-11-14 现在,多使用 systemd timedatectl 进行时区设置。

构建

版本命名

CentOS Wiki/FAQ/General/How does CentOS versioning work?
Wikipedia/CentOS

Since minor versions of CentOS are point in time releases of a major branch, starting with CentOS-7, we are now using a date code in our minor versions. So you will see CentOS-7 (1406) or CentOS-7 (1503) as a version. This way anyone can know, from the release, when it happened. In the above examples, the minor versions 1406 means June 2014 and 1503 means March 2015. In older major branches of CentOS, such as CentOS-6, we numbered things differently.

7.0-1406
7.1-1503
7.2-1511
7.3-1611
7.4-1708
7.5-1804
7.6-1810
7.7-1908
7.8-2003
7.9-2009

根据 Wikipedia/CentOS 页面,其版本后面的四位数为相关 RHEL 的发布日期。

版本选择

https://vault.centos.org/

安装方法

Instructions for installing CentOS 7.6.1810 on various architectures

应用

场景 | 常用设置 and 常用工具

# 取消「You have mail in /var/spool/mail/root」提示
echo 'unset MAILCHECK'  >> ~/.bashrc

# 调整 PS1 变量
cat >> ~/.bashrc  <<EOF
export PS1="\e[01;31m\u@\h \w\e[00m""\e[34;1m\e[0m""\n""prod-master # "

# 常用命令别名
alias ll='ls -l -a --color'
alias ls='ls -a --color'
EOF

# 重新登录一下
exec su - root

# 每次安装完 CentOS 之后,执行如下命令:
yum install -y epel-release                                                    \
    && yum install -y yum-cron yum-utils yum-cron                              \
    && yum install -y sysstat procps-ng psmisc bash-completion tmux vim rsync wget

升级 CentOS 6.5 到 CentOS 7 版本

Upgrade Centos 6 to Centos 7
Index of /centos/6/upg/old/x86_64/Packages
Upgrading CentOS 6 to 7
Pre Upgrade Assistant fails to generate a results.html
Upgrade from CentOS 6 to CentOS 7
Upgrading CentOS 6.5 to CentOS 7.2
Upgrading CentOS 6 to CentOS 7

以前升级系统的时候,只能通过重新安装。但是经过社区不断的努力,现在可以通过命令行直接升级当前系统。

注意事项

目前 CentOS 尚未发布任何有关升级 CentOS 6 的官方文件,因此不建议在生产环境中进行此升级。如果你想尝试开发,可以按照如下简单的步骤操作。

这是从别的博文中收到的警告:不要使用此方法升级「CentOS 6.7」或更高版本的系统。因为在「CentOS 6.7」中的多个系统关键软件包的版本号,比它们在「CentOS 7」中的版本号更高,因此这些软件包无法正确升级。这会导致系统损坏,并且几个系统工具无法正常工作。你将无法登录或使用网络。此外「CentOS 6.6」现在升级也会失败,升级时出现错误“Downloading failed: invalid data in .treeinfo: No section: ‘checksums’”,只能在「CentOS 6.5」上完成。

#1 更新系统

将系统中的包更新到最新的版本:

yum update -y

#2 升级助手

升级助手不用于升级,它是升级检查工具。用于检查在升级过程中潜在的问题。

安装并执行升级助手:

#!/bin/sh

# 配置源
cat <<UA >> /etc/yum.repos.d/upgrade.repo
[upgrade]
name=upgrade
baseurl=https://buildlogs.centos.org/centos/6/upg/old/x86_64/
enabled=1
gpgcheck=0
UA

# 对 openscap 进行降级
# 因为一个错误:https://centos.org/forums/viewtopic.php?t=59763
yum erase openscap
yum -y install https://buildlogs.centos.org/centos/6/upg/x86_64/Packages/openscap-1.0.8-1.0.1.el6.centos.x86_64.rpm

# 安装升级助手
yum -y install redhat-upgrade-tool preupgrade-assistant-*

# 执行检查
preupg --text

从升级助手中可以找到所有将受此升级影响的包和应用程序。如果你觉得没有关系,那么可以继续下一步。

#3 执行升级

执行升级:

#!/bin/sh

# 如果链接无效,则访问 http://centos.excellmedia.net/ 找到对应的文件,修改链接即可
# rpm --import http://centos.excellmedia.net/7.6.1810/os/x86_64/RPM-GPG-KEY-CentOS-7
# redhat-upgrade-tool --network 7.6 --force --instrepo http://centos.excellmedia.net/7.6.1810/os/x86_64/
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
centos-upgrade-tool-cli --network 7 --instrepo=http://mirror.centos.org/centos/7/os/x86_64

# 上述命令执行结束后,需要在重启后进行安装
reboot

#4 验证版本

最后一步是验证系统的版本:

#!/bin/sh

cat /etc/redhat-release

常见错误汇总

Downloading failed: invalid data in .treeinfo: No section: ‘checksums’
参见本文开始时的注意事项。

YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
YumRepo Error: All mirror URLs are not using ftp, http[s] or file

注释掉中的mirrorlist选项,并启用baseurl选项。