时间:2020-11-20 18:12:29 | 栏目: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
>之后重启即可
总结