CentOS 8 dnf module安装Redis6

最近在CentOS 8上安装了一个Redis,默认版本号是5,一开始没有在意版本号。但是Redis官方的RedisInsight工具一直提示升级版本,所以查了一下,发现CentOS8上的Redis居然有两个流,默认的是版本5,同时还有一个可选的版本6。这就涉及到了CentOS 8上默认的包管理工具dnf的另外一个用法dnf module。

module是特殊的包组,通常代表一个应用程序,一个语言运行时间,或一组工具。它们有一个或多个流,通常代表一个软件的主要版本,让你可以选择你想使用的软件包的版本。

  1. dnf module 知识点

1.1. module流的安装和发现

1.1.1. 列出软件包

系统可用的软件包可以通过通常的命令,如dnf search NAME,dnf list NAME,或使用dnf repoquery QUERY命令进行更复杂的查询来找到想要的软件包。然而,这些命令只列出来已经启用的模块流的模块包,可选流的软件包并不在其中。

1.1.2. 列出模块

要列出你的系统可用的模块,并查看哪些流是默认的或已经启用的,使用以下命令。

$ dnf module list

1.1.3. 安装软件包

软件包可以通过运行dnf install NAME命令按常规方式安装。任何传统的软件包,或者来自已启用模块的模块化软件包都可以通过这种方式安装。

来自其他模块流的包可以通过启用模块流,然后安装单个包,或者直接使用dnf module install。

1.1.4. 启用模块

要启用一个模块流并使其软件包可供安装,请运行以下命令

$ dnf module enable NAME:STREAM

例如,要使Node.js 8的软件包可用于安装,请运行。对于已经安装过一个版本,再执行启用会报错,文章后面会以redis6的实际安装来说明

$ dnf module enable nodejs:8

然后可以通过dnf install NAME命令来安装已启用的模块流中的包。

1.1.5. 安装模块

要安装一个模块,请使用以下命令之一。不指定流或配置文件会使 DNF 选择默认值。然而,并不是每个模块都有一个默认的流或默认的配置文件。在这种情况下,你需要明确指定流或配置文件。

$ dnf module install NAME
$ dnf module install NAME:STREAM
$ dnf module install NAME/PROFILE
$ dnf module install NAME:STREAM/PROFILE

例如,要安装Node.js 8运行时和MongoDB的默认流的客户端工具,运行。

$ dnf module install nodejs:8
$ dnf module install mongodb/client

1.1.6. 切换模块流

切换流是一个有风险的操作,软件包中可能并不总是支持,尤其是降级。

通过switch-to参数切换到一个与系统上已安装软件包所在流的不同流。

$ dnf module switch-to NAME:STREAM

例如,要从Node.js 8切换到Node.js 10,运行:

$ dnf module switch-to nodejs:10

一个例子,从Node.js 10切换到Node.js 8,运行:

$ dnf module switch-to nodejs:8
switch-to参数是切换流的推荐和首选方式。

switch-to参数包括多个需要执行的动作,以安全地切换到另一个模块流。在这个例子中,我们展示了一个从Node.js 8到Node.js 10的手动切换,没有运行switch-to参数。

$ dnf remove nodejs
$ dnf module reset nodejs:8
$ dnf module enable nodejs:10
$ dnf install nodejs
dnf module info NAME:STREAM命令有助于检查模块流中的RPM信息。

1.2. 更新系统

通过运行dnf update命令来更新系统会使所有软件包升级到它们的模块流所提供的最新版本。

1.3. 删除模块

一般来说,要删除安装在系统上的模块,使用以下命令:

$ dnf module remove MODULE:STREAM/PROFILE
  1. 通过dnf module操作将Redis5升级到Redis6

2.1. 查看redis模块

[root@localhost ~]# dnf module list redis
Last metadata expiration check: 2:25:26 ago on Fri 17 Mar 2023 05:05:08 PM CST.
CentOS Stream 8 - AppStream
Name                                            Stream                                            Profiles                                            Summary                                                                     
redis                                           5 [d][e]                                          common [d]                                          Redis persistent key-value database                                         
redis                                           6                                                 common [d]                                          Redis persistent key-value database                                         

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

2.2. 已安装redis5后再启用redis6模块,报错

提示需要删除已安装的模块并执行dnf module reset命令

[root@localhost yum.repos.d]#  dnf module enable redis:6
Last metadata expiration check: 0:13:21 ago on Fri 17 Mar 2023 05:05:08 PM CST.
Dependencies resolved.
The operation would result in switching of module 'redis' stream '5' to stream '6'
Error: It is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch.
It is recommended to rather remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. After you reset the module, you can install the other stream.

直接执行dnf module install也是一样的报错。

[root@localhost ~]# dnf module install redis:6
Last metadata expiration check: 2:26:02 ago on Fri 17 Mar 2023 05:05:08 PM CST.
Dependencies resolved.
The operation would result in switching of module 'redis' stream '5' to stream '6'
Error: It is not possible to switch enabled streams of a module unless explicitly enabled via configuration option module_stream_switch.
It is recommended to rather remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. After you reset the module, you can install the other stream.

2.3. 重置模块流

由于redis5中已经有业务数据,没办法先删除再安装,所以直接执行dnf module reset redis重置模块信息。

[root@localhost ~]# dnf module reset redis
Last metadata expiration check: 0:40:31 ago on Fri 17 Mar 2023 08:39:32 PM CST.
Dependencies resolved.
==================================================================================================================================================================================================================================
 Package                                                Architecture                                          Version                                                Repository                                              Size
==================================================================================================================================================================================================================================
Resetting modules:
 redis                                                                                                                                                                                                                           

Transaction Summary
==================================================================================================================================================================================================================================

Is this ok [y/N]: y
Complete!

再次执行查看模块信息,发现redis5的模块已经不显示enable标识了。

[root@localhost ~]# dnf module list redis
Last metadata expiration check: 0:40:53 ago on Fri 17 Mar 2023 08:39:32 PM CST.
CentOS Stream 8 - AppStream
Name                                            Stream                                           Profiles                                             Summary                                                                     
redis                                           5 [d]                                            common [d]                                           Redis persistent key-value database                                         
redis                                           6                                                common [d]                                           Redis persistent key-value database                                         

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

2.4. 执行redis6的模块安装

[root@localhost ~]# dnf module install redis:6
Last metadata expiration check: 0:41:09 ago on Fri 17 Mar 2023 08:39:32 PM CST.
Dependencies resolved.
==================================================================================================================================================================================================================================
 Package                                      Architecture                                  Version                                                                        Repository                                        Size
==================================================================================================================================================================================================================================
Upgrading:
 redis                                        x86_64                                        6.2.7-1.module_el8.7.0+1144+ab2666e8                                           appstream                                        1.2 M
Installing module profiles:
 redis/common                                                                                                                                                                                                                    
Enabling module streams:
 redis                                                                                      6                                                                                                                                    

Transaction Summary
==================================================================================================================================================================================================================================
Upgrade  1 Package

Total download size: 1.2 M
Is this ok [y/N]: y
Downloading Packages:
redis-6.2.7-1.module_el8.7.0+1144+ab2666e8.x86_64.rpm                                                                                                                                             6.0 MB/s | 1.2 MB     00:00    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                             741 kB/s | 1.2 MB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                          1/1 
  Running scriptlet: redis-6.2.7-1.module_el8.7.0+1144+ab2666e8.x86_64                                                                                                                                                        1/1 
  Running scriptlet: redis-6.2.7-1.module_el8.7.0+1144+ab2666e8.x86_64                                                                                                                                                        1/2 
  Upgrading        : redis-6.2.7-1.module_el8.7.0+1144+ab2666e8.x86_64                                                                                                                                                        1/2 
warning: /etc/redis.conf created as /etc/redis.conf.rpmnew

  Running scriptlet: redis-6.2.7-1.module_el8.7.0+1144+ab2666e8.x86_64                                                                                                                                                        1/2 
  Running scriptlet: redis-5.0.3-5.module_el8.4.0+955+7126e393.x86_64                                                                                                                                                         2/2 
  Cleanup          : redis-5.0.3-5.module_el8.4.0+955+7126e393.x86_64                                                                                                                                                         2/2 
  Running scriptlet: redis-5.0.3-5.module_el8.4.0+955+7126e393.x86_64                                                                                                                                                         2/2 
  Verifying        : redis-6.2.7-1.module_el8.7.0+1144+ab2666e8.x86_64                                                                                                                                                        1/2 
  Verifying        : redis-5.0.3-5.module_el8.4.0+955+7126e393.x86_64                                                                                                                                                         2/2 

Upgraded:
  redis-6.2.7-1.module_el8.7.0+1144+ab2666e8.x86_64                                                                                                                                                                               

Complete!

从安装日志看,和普通dnf update没什么区别。

安装完之后再看模块信息,redis6模块已经启用,并且显示了安装标识位。

[root@localhost ~]# dnf module list redis
Last metadata expiration check: 0:41:35 ago on Fri 17 Mar 2023 08:39:32 PM CST.
CentOS Stream 8 - AppStream
Name                                           Stream                                          Profiles                                                Summary                                                                    
redis                                          5 [d]                                           common [d]                                              Redis persistent key-value database                                        
redis                                          6 [e]                                           common [d] [i]                                          Redis persistent key-value database                                        

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

剩下的就是合并redis.conf.rpmnew和redis.conf文件,重启redis即可。

猜你喜欢

转载自blog.csdn.net/xieshaohu/article/details/129628823