Rocky Linux 9 默认不包含 Redis,但可以通过 EPEL(Extra Packages for Enterprise Linux) 仓库安装。
sudo dnf install epel-release -y
sudo dnf install redis -y
sudo systemctl enable --now redis
sudo systemctl status redis
如果看到 active (running)
,说明 Redis 已成功运行。
redis-cli ping
如果返回 PONG
,说明 Redis 正常运行。
如果希望安装 最新版 Redis,可以手动编译安装。
sudo dnf install gcc make tcl -y
wget https://download.redis.io/redis-stable.tar.gztar -xzf redis-stable.tar.gzcd redis-stable
make -j$(nproc)sudo make install
sudo mkdir /etc/redissudo cp redis.conf /etc/redis/redis.conf
sudo nano /etc/systemd/system/redis.service
粘贴以下内容:
[Unit]Description=Redis In-Memory Data StoreAfter=network.target[Service]User=redisGroup=redisExecStart=/usr/local/bin/redis-server /etc/redis/redis.confExecStop=/usr/local/bin/redis-cli shutdownRestart=always[Install]WantedBy=multi-user.target
sudo adduser --system --group --no-create-home redissudo chown -R redis:redis /etc/redis
sudo systemctl daemon-reloadsudo systemctl enable --now redissudo systemctl status redis
编辑 /etc/redis/redis.conf
:
sudo nano /etc/redis/redis.conf
找到并修改:
bind 0.0.0.0protected-mode no
重启 Redis:
sudo systemctl restart redis
在 redis.conf
中取消注释并修改:
requirepass yourpassword
重启 Redis:
sudo systemctl restart redis
sudo firewall-cmd --add-port=6379/tcp --permanentsudo firewall-cmd --reload
方法 | 适用场景 | 版本控制 | 管理方式 |
---|---|---|---|
EPEL 安装 | 快速部署,适合生产环境 | 版本较旧(如 6.x) | systemctl |
源码编译 | 需要最新版 Redis | 可自定义版本 | systemctl |
✅ 推荐使用 EPEL 安装(简单稳定)
✅ 需要最新版时选择源码编译
如果遇到问题,可以检查日志:
sudo journalctl -u redis -f