在 CentOS 上启动 Redis 并加载配置文件,通常有以下几种方式,按使用场景说明:
yum install epel-release -y
yum install redis -y
默认配置文件路径:
/etc/redis.conf
常见修改项:
bind 0.0.0.0 # 允许远程连接
protected-mode no # 关闭保护模式(测试用)
requirepass 123456 # 设置密码
daemonize yes # 后台运行
systemctl start redis
systemctl enable redis
systemctl status redis
redis-server /etc/redis.conf
redis-server /etc/redis.conf --daemonize yes
redis-cli
如果设置了密码:
redis-cli -a 123456
例如新配置:
cp /etc/redis.conf /etc/redis-6380.conf
vim /etc/redis-6380.conf
修改:
port 6380
pidfile /var/run/redis_6380.pid
logfile /var/log/redis/redis-6380.log
启动:
redis-server /etc/redis-6380.conf
journalctl -xe
cat /var/log/redis/redis.log
netstat -lntp | grep 6379
systemctl + /etc/redis.confredis-server 指定配置文件如果你是 CentOS 6 或 源码安装 Redis,我也可以给你对应方式。