linux升级

linux升级

前言

公司有一台服务器,目前比较老,分配给我做了我的研发环境,由于内核版本低,很多东西不能装,所以我研究下一怎么来升级内核,适配我的产品

使用uname命令查找Linux内核

uname是用于获取系统信息的Linux命令。您也可以使用它来确定您使用的是32位还是64位系统。

[root@bogon ~]# uname -r
#这意味着您正在运行Linux内核3.10.0-327,或者更笼统地说,您正在运行Linux内核版本3.10
3.10.0-327.el7.x86_64

内核版本说明:

  • 3 –内核版本
  • 10 –重大修订
  • 0 –轻微修订
  • 327 –错误修复

您还可以将uname命令与-a选项一起使用。 如果需要,这将提供更多的系统信息

[root@bogon ~]# uname -a
Linux bogon 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

输出说明:

  • Linux –内核名称。 如果在BSD或macOS上运行相同的命令,结果将有所不同。
  • linux –主机名
  • 3.10.0-327.el7.x86_64 –内核版本(我们刚刚说过了)
  • #1 SMP Thu Nov 19 22:10:57 UTC 2015 – 这意味着CentOS编译了3.10.0-327.el7.x86_64 19次。最后的编译时间戳也在那里。
  • x86_64 –机器架构
  • x86_64 –处理器架构
  • x86_64 –操作系统体系结构(您可以在64位处理器上运行32位OS)
  • GNU/Linux –操作系统(不,它不会显示发行名称)

使用hostnamectl命令查看

[root@bogon ~]# hostnamectl
   Static hostname: localhost.localdomain
Transient hostname: bogon
         Icon name: computer-desktop
           Chassis: desktop
        Machine ID: fe5e736a33394bef9547be17bec516b7
           Boot ID: 733ec0bc5781412cb6bd7733220fcd96
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-327.el7.x86_64
      Architecture: x86-64

可以看到系统的版本是:CentOS Linux 7 (Core)

升级系统内核

一般来说,只有从https://www.kernel.org/ 下载并编译安装的内核才是官方内核,可以看出目前的稳定版版本为6.1.4

不过,大多数 Linux 发行版提供自行维护的内核,可以通过 yum 或 rpm 等包管理系统升级。
ELRepo是一个为Linux提供驱动程序和内核映像的存储库,这里的升级方案就是采用ELRepo提供的内核通道。
ELRepo官网:http://elrepo.org/tiki/tiki-index.php

#查看 yum 中可升级的内核版本
yum list kernel --showduplicates
#如果list中有需要的版本可以直接执行 update 升级,多数是没有的,所以要按以下步骤操作

#导入ELRepo软件仓库的公共秘钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

#Centos7系统安装ELRepo
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm
#Centos8系统安装ELRepo
yum install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm

#查看ELRepo提供的内核版本
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available

可提供的内核升级版本:

kernel-lt:表示longterm,即长期支持的内核;当前为5.4.
kernel-ml:表示mainline,即当前主线的内核;当前为6.1.

#安装主线内核
$ yum --enablerepo=elrepo-kernel install kernel-ml.x86_64

#查看系统可用内核,并设置启动项
$ sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
0 : CentOS Linux (6.1.4-1.el7.elrepo.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-fe5e736a33394bef9547be17bec516b7) 7 (Core)

#指定开机启动内核版本
$ grub2-set-default 0 或者 grub2-set-default 'CentOS Linux (5.17.1-1.el7.elrepo.x86_64) 7 (Core)'

#生成 grub 配置文件
$ grub2-mkconfig -o /boot/grub2/grub.cfg

#重启系统,验证
$ reboot
$ uname -a
Linux localhost 6.1.4-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jan  4 18:17:10 EST 2023 x86_64 x86_64 x86_64 GNU/Linux

centos 7.2升级系统为7.9

内核升级完了,接下来看系统

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

系统是7.2版本,准备升级到最新的7.9版本即可

yum clean all
yum update

init 6

问题

CentOS 7 could not retrieve mirrorlist http:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum install epel-release
yum makecache
yum install container-selinux
posted @ 2023-01-11 16:35  小学程序员  阅读(197)  评论(0编辑  收藏  举报