在 CentOS 上启动 Redis,常见有以下几种方式,按使用场景说明(适合 CentOS 7/8、Rocky、Alma 等):
rpm -qa | grep redis
# 或
which redis-server
如果未安装:
yum install -y redis
# CentOS 8 / Rocky
dnf install -y redis
systemctl start redis
设置开机自启:
systemctl enable redis
查看状态:
systemctl status redis
systemctl stop redis
systemctl restart redis
redis-server
redis-server /etc/redis.conf
配置文件中需要包含:
daemonize yes
vim /etc/redis.conf
常见修改项:
bind 0.0.0.0
port 6379
daemonize yes
requirepass yourpassword
redis-server /etc/redis.conf
ps -ef | grep redis
redis-cli
ping
# 返回 PONG 表示成功
如果设置了密码:
redis-cli -a yourpassword
firewall-cmd --add-port=6379/tcp --permanent
firewall-cmd --reload
查看日志:
journalctl -u redis -xe
# 或
tail -f /var/log/redis/redis.log
netstat -tunlp | grep 6379
systemctl start redis
systemctl enable redis
systemctl status redis
如果你用的是 CentOS 6、Docker、源码安装 Redis,或需要 主从 / 集群配置,可以告诉我,我可以给你更详细的方案。