CentOS7 安装Redis
有两种安装方法,一种是EPEL安装,一种是手动编译安装。手动编译安装坑比较多,建议大家使用EPEL安装。
1、安装EPEL仓库
sudo yum install epel-release -y
2、安装Redis
sudo yum install redis -y
3、启动Redis服务
sudo systemctl start redis
4、设置开机自启动
sudo systemctl enable redis
5、检查运行状态
sudo 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 四 2025-04-03 10:15:20 CST; 1h 43min ago
Main PID: 22231 (redis-server)
CGroup: /system.slice/redis.service
└─22231 /usr/bin/redis-server 0.0.0.0:6379
4月 03 10:15:20 VM-0-5-centos systemd[1]: Starting Redis persistent key-value database...
4月 03 10:15:20 VM-0-5-centos systemd[1]: Started Redis persistent key-value database.
6、测试Redis
redis-cli ping
# 正常会返回 "PONG"
7、修改配置文件
默认的配置文件路径在 /etc/redis.conf
sudo vi /etc/redis.conf
修改配置文件中的 requirepass 和 bind 增加访问密码和监听范围
requirepass xxxxxx
...
bind 0.0.0.0
8、重启服务
sudo systemctl restart redis
通过以上步骤,Redis 即可在 CentOS 7 上正常运行。