在 CentOS 上修改 Redis 端口,一般按下面步骤操作即可(以 Redis 通过 yum 安装 为例,源码安装类似)。
Redis 默认配置文件路径通常为:
/etc/redis.conf
或者(部分版本):
/etc/redis/redis.conf
使用 vim 编辑:
vim /etc/redis.conf
找到如下配置项:
port 6379
修改为你想要的端口,例如:
port 6380
✅ 端口范围建议:1024–65535,避免使用已被占用端口
如果你之前配置了 bind,确认是否需要调整:
bind 127.0.0.1
或允许远程:
bind 0.0.0.0
(视你的使用场景而定)
CentOS 7 / 8 使用 firewalld:
firewall-cmd --zone=public --add-port=6380/tcp --permanent
firewall-cmd --reload
查看是否生效:
firewall-cmd --list-ports
如果是 CentOS 6(iptables):
iptables -I INPUT -p tcp --dport 6380 -j ACCEPT
service iptables save
service iptables restart
systemctl restart redis
或(老版本):
service redis restart
netstat -lntp | grep redis
或
ss -lntp | grep redis
redis-cli -p 6380
连接成功后:
ping
返回:
PONG
redis-cli -h 127.0.0.1 -p 6380
port + pidfile + dir + logfile如果你告诉我:
我可以给你更精确的配置示例。