当前位置: 首页 > 工具软件 > crystal-redis > 使用案例 >

centOS 使用 yum 安装 Redis

彭仲卿
2023-12-01

源码包安装的方式我就不多说了,教程很多。下面主要说一下怎么通过 yum 来进行更方便快捷的安装 redis。

1、检查是否有 redis yum 源
yum install redis(一般都会失败的,因为官方的源很滞后)

[root@master packages]# yum install redis
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                              | 3.6 kB  00:00:00     
crystal                                                                                                                           | 2.9 kB  00:00:00     
docker-ce-stable                                                                                                                  | 3.5 kB  00:00:00     
extras                                                                                                                            | 2.9 kB  00:00:00     
jenkins                                                                                                                           | 2.9 kB  00:00:00     
updates                                                                                                                           | 2.9 kB  00:00:00     
jenkins/primary_db                                                                                                                |  35 kB  00:00:02     
No package redis available.
Error: Nothing to do

2、下载 fedora 的 epel 仓库

EPEL 的全称叫 Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL之后,就相当于添加了一个第三方源。EPEL则为服务器版本提供大量的rpm包,而且大多数rpm包在官方 repository 中是找不到的

yum install epel-release (安装成功后再执行 yum install redis)
[root@master packages]# yum install epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-11 will be installed
--> Finished Dependency Resolution

...

Install  1 Package

Total download size: 15 k
Installed size: 24 k
Is this ok [y/d/N]: y
Downloading packages:
epel-release-7-11.noarch.rpm                                                                                                      |  15 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-11.noarch                                                                                                              1/1 
  Verifying  : epel-release-7-11.noarch                                                                                                              1/1 

Installed:
  epel-release.noarch 0:7-11                                                                                                                             

Complete!

3、安装 redis 数据库

yum install redis
[root@master packages]# yum install redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                                              | 7.1 kB  00:00:00     
 * base: mirrors.aliyun.com
 * epel: mirrors.bfsu.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
epel                                                                                                                              | 4.7 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                                                                                       |  95 kB  00:00:00     
(2/3): epel/x86_64/updateinfo                                                                                                     | 1.0 MB  00:00:01     
epel/x86_64/primary_db         FAILED                                                                                  ]   87 B/s | 1.2 MB  22:53:16 ETA 

...

Importing GPG key 0x352C64E5:
 Userid     : "Fedora EPEL (7) <epel@fedoraproject.org>"
 Fingerprint: 91e9 7d7c 4a5e 96f1 7f3e 888f 6a2f aea2 352c 64e5
 Package    : epel-release-7-11.noarch (@extras)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : jemalloc-3.6.0-1.el7.x86_64                                                                                                           1/2 
  Installing : redis-3.2.12-2.el7.x86_64                                                                                                             2/2 
  Verifying  : redis-3.2.12-2.el7.x86_64                                                                                                             1/2 
  Verifying  : jemalloc-3.6.0-1.el7.x86_64                                                                                                           2/2 

Installed:
  redis.x86_64 0:3.2.12-2.el7                                                                                                                            

Dependency Installed:
  jemalloc.x86_64 0:3.6.0-1.el7                                                                                                                          

Complete!

4、安装完毕后,使用下面的命令启动 redis 服务

# redis 的启动、停止和状态查看
[root@master packages]# service redis start
Redirecting to /bin/systemctl start redis.service
[root@master packages]# service redis stop
Redirecting to /bin/systemctl stop redis.service
[root@master packages]# service redis status
Redirecting to /bin/systemctl status redis.service
● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: inactive (dead)

Nov 04 21:29:54 master systemd[1]: Starting Redis persistent key-value database...
Nov 04 21:29:54 master systemd[1]: Started Redis persistent key-value database.
Nov 04 21:30:03 master systemd[1]: Stopping Redis persistent key-value database...
Nov 04 21:30:03 master systemd[1]: Stopped Redis persistent key-value database.

5、设置开机启动

[root@master packages]# chkconfig redis on
Note: Forwarding request to 'systemctl enable redis.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

6、进入 redis 服务

[root@master packages]# which redis-server
/usr/bin/redis-server
[root@master packages]# which redis-cli
/usr/bin/redis-cli


[root@master packages]# redis-cli
127.0.0.1:6379> set key value [EX seconds] [PX milliseconds] [NX|XX]
127.0.0.1:6379> set mykey hello
OK
127.0.0.1:6379> get mykey
"hello"
127.0.0.1:6379> 

 

 类似资料: