3.1 问题
对Redis服务器192.168.4.50做如下配置:
端口号 6350
IP地址 192.168.4.50
连接密码 123456
测试配置
3.2 步骤
实现此案例需要按照如下步骤进行。
步骤一:修改主配置文件
1)修改配置文件
[root@host50 utils]# cp /etc/redis/6379.conf /root/6379.conf
//可以先备份一份,防止修改错误没法还原
[root@host50 utils]# /etc/init.d/redis_6379 stop
[root@host50 utils]# vim /etc/redis/6379.conf
...
bind 192.168.4.50 //设置服务使用的ip
port 6350 //更改端口号
requirepass 123456 //设置密码
:wq
2)修改启动脚本
[root@host50 ~]# vim +43 /etc/init.d/redis_6379
$CLIEXEC -h 192.168.4.50 -p 6350 -a 123456 shutdown
:wq
3)启动服务
[root@host50 ~]# /etc/init.d/redis_6379 start
Starting Redis server...
[root@host50 ~]#
[root@host50 ~]# netstat -utnlp | grep redis-server
tcp 0 0 192.168.4.50:6350 0.0.0.0:* LISTEN 11523/redis-server
[root@host50 ~]#
4)测试配置
访问服务存取数据
[root@host50 ~]# redis-cli -h 192.168.4.50 -p 6350 -a 123456 //访问服务
192.168.4.50:6350> ping
PONG
192.168.4.50:6350> keys *
(empty list or set)
192.168.4.50:6350>
192.168.4.50:6350> set x 99
OK
192.168.4.50:6350>
192.168.4.50:6350> exit
[root@host50 ~]#