第 1 步:更新您的 CentOS 7 / RHEL 7
在安装 Redis 之前确保您的系统已更新
sudo yum -y update
第 2 步:添加 REMI 存储库
Redis 的最新版本在 Remi 存储库中可用,通过执行命令添加它:
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
第 3 步:在 CentOS 7 / RHEL 7 上安装 Redis
添加存储库后,从存储库在 CentOS 7 / RHEL 7 上安装最新的 Redis。
sudo yum --enablerepo=remi install redis
从以下位置获取更多包裹详情:
$ rpm -qi redis
Name : redis
Version : 7.0.0
Release : 1.el7.remi
Architecture: x86_64
Install Date: Fri May 20 13:24:43 2022
Group : Applications/Databases
Size : 5339497
License : BSD
Signature : DSA/SHA1, Wed Apr 27 15:23:54 2022, Key ID 004e6f4700f97f56
Source RPM : redis-7.0.0-1.el7.remi.src.rpm
Build Date : Wed Apr 27 15:22:31 2022
Build Host : builder.remirepo.net
Relocations : (not relocatable)
Packager : Remi Collet
Vendor : Remi's RPM repository <https://rpms.remirepo.net/>
URL : http://redis.io
Bug URL : https://forum.remirepo.net/
Summary : A persistent key-value database
....
第三步:在 CentOS 7 / RHEL 7 上启动 Redis 服务
Redis 服务可以使用systemd 服务管理器在 CentOS 7 / RHEL 7 上启动。此外,启用该服务以在系统启动时启动。
sudo systemctl enable --now redis
第 4 步:为 Redis 服务启用网络侦听(可选)
为了让网络客户端连接到您的 Redis 服务器,它需要该服务侦听网络 IP 地址。
/etc/redis.conf 使用您喜欢的文本编辑器打开文件:
sudo vi /etc/redis.conf
然后将第61 bind 127.0.0.1行更改 为您的服务器 IP:
bind 172.21.10.11
要监听所有可用的接口,设置如下:
bind * -::*
配置 Redis 身份验证 –(可选但推荐)
AUTH <PASSWORD>在处理任何其他命令之前,为客户端配置 Redis 身份验证 。
requirepass <AuthPassword>
例子:
requirepass oobaiY8
为恢复设置持久存储
appendonly通过将值更改为 yes来设置持久性模式
appendonly yes
appendfilename "appendonly.aof"
修改后重启redis服务
sudo systemctl restart redis
查看redis服务状态:
$ systemctl status redis
● redis.service - Redis persistent key-value database
Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/redis.service.d
└─limit.conf
Active: active (running) since Fri 2022-05-20 13:25:22 UTC; 2min 56s ago
Main PID: 8847 (redis-server)
Status: "Ready to accept connections"
CGroup: /system.slice/redis.service
└─8847 /usr/bin/redis-server 127.0.0.1:6379
May 20 13:25:22 centos7.example.io systemd[1]: Starting Redis persistent key-value database...
May 20 13:25:22 centos7.example.io systemd[1]: Started Redis persistent key-value database.
ss您可以使用以下命令查看 Redis 服务使用的端口和 IP :
$ sudo ss -tunelp | grep 6379
tcp LISTEN 0 128 *:6379 *:* users:(("redis-server",pid=28163,fd=4)) uid:995 ino:305
如果您有活动的 firewalld 服务,请允许端口6379
sudo firewall-cmd --add-port=6379/tcp --permanent
sudo firewall-cmd --reload
第 5 步:测试与 Redis 服务器的连接
确认可以在本地连接redis:
$ redis-cli
127.0.0.1:6379>
测试验证:
127.0.0.1:6379> AUTH <AuthPassword>
OK
OK您应该在输出中收到。如果您输入了错误的密码,身份验证应该会失败:
127.0.0.1:6379> AUTH WrongPassword
(error) ERR invalid password
检查redis信息。
127.0.0.1:6379> INFO
这将输出一长串数据。您可以通过将 Section 作为参数传递来限制输出。例如
127.0.0.1:6379> INFO Server
# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7897e7d0e13773f
redis_mode:standalone
os:Linux 3.10.0-862.14.4.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:3640
run_id:ef36ca5ae9d561d8d3d3ea979cc8481eab0da874
tcp_port:6379
uptime_in_seconds:145
uptime_in_days:0
hz:10
lru_clock:433261
executable:/usr/bin/redis-server
config_file:/etc/redis.conf
第 6 步:执行 Redis 基准测试
针对本地 redis运行具有并行连接的基准测试,15总共10k请求,以测试其性能。
$ redis-benchmark -h 127.0.0.1 -p 6379 -n 10000 -c 15
# Sample output
................................................
====== LRANGE_600 (first 600 elements) ======
10000 requests completed in 0.15 seconds
15 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
67114.09 requests per second
====== MSET (10 keys) ======
10000 requests completed in 0.15 seconds
15 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
66666.66 requests per second
有关更多选项和示例,请使用:
$ redis-benchmark --help
您已在 CentOS 7 / RHEL 7 上成功安装 Redis。我们的下一个指南将介绍在 CentOS 7 / RHEL 7 上的 Redis 集群安装。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容