解决Redis开启远程访问及密码问题
redis开启远程访问及密码,具体介绍如下所示:
一、开启远程访问
1.开放端口
firewall-cmd --zone=public --add-port=6379 firewall-cmd --zone=public --add-port=6379 --permanent
2.查看已开放端口
firewall-cmd --list-port
3.修改配置文件
vim redis.conf
将bind 127.0.0.1 注释或者改为bind 0.0.0.0
将protected-mode yes
改为protected-mode no;
二、设置密码
找到 # requirepass foobared
将注释去掉,修改foobared 为自己想要的密码,如 requirepass 123456
之后重启即可
systemctl restart redis
ps:redis启动报错解决
报错
redis_6379.service - lsb: start and stop redis_6379
loaded: loaded (/etc/rc.d/init.d/redis_6379; bad; vendor preset: disabled)
active: active (exited) since wed 2019-09-18 15:40:08 cst; 7s ago
docs: man:systemd-sysv-generator(8)
process: 22652 execstop=/etc/rc.d/init.d/redis_6379 stop (code=exited, status=0/success)
process: 22692 execstart=/etc/rc.d/init.d/redis_6379 start (code=exited, status=0/success)
sep 18 15:40:08 ythzcpt-csmh systemd[1]: starting lsb: start and stop redis_6379...
sep 18 15:40:08 ythzcpt-csmh redis_6379[22692]: /var/run/redis_6379.pid exists, process is already running or crashed
sep 18 15:40:08 ythzcpt-csmh systemd[1]: started lsb: start and stop redis_6379.
>删除pid文件
cd /var/run mv redis_6379.pid redis_6379.pid_bak
>删除dump.rdb(内存快照)文件
cd /var/lib/redis/6379 mv dump.rdb dump.rdb_bak
>之后查看是否还有redis服务启动
ps -ef |grep redis kill -9
>之后重启即可
总结
以上所述是小编给大家介绍的解决redis开启远程访问及密码问题,希望对大家有所帮助