? 安装源码包
- [root@40 ~]# tar -xf redis/redis-4.0.8.tar.gz -C .
- [root@40 ~]# cd redis-4.0.8/
- [root@40 redis-4.0.8]# yum -y install gcc gcc-c++
- [root@40 redis-4.0.8]# make && make install
- [root@40 redis-4.0.8]# ./utils/install_server.sh
- [root@40 redis-4.0.8]# vim /etc/redis/6379.conf
- 70 bind 192.168.4.40 #修改 ip
- 93 port 6040 #修改端口
- [root@40 redis-4.0.8]# ln -s /etc/init.d/redis_6379 /sbin/
- [root@40 redis-4.0.8]# redis_6379 stop
- [root@40 redis-4.0.8]# redis_6379 start
- [root@40 ~]# ss -antulp | grep redis
- tcp LISTEN 0 128 192.168.4.40:6040 : users:(("redis-server",pid=4846,fd=6))
此时用脚本关闭 redis 会报如下错误
[root@40 ~]# redis_6379 -stop
Please use start, stop, restart or status as first argument
解决方法 1:[root@40 ~]# redis-cli -h 192.168.4.40 -p 6040 shutdown
解决方法 2: 需要更改脚本文件
- [root@40 ~]# vim /etc/init.d/redis_6379
- 8 REDISPORT="6040"
- 43 $CLIEXEC -h 192.168.4.40 -p $REDISPORT shutdown
设置完毕后就可以使用脚步关了
如:
- [root@40 ~]# ss -antulp | grep redis
- tcp LISTEN 0 128 192.168.4.40:6040 : users:(("redis-server",pid=4846,fd=6))
关闭 redis
[root@40 ~]# redis_6379 stop
Stopping ...
Redis stopped
设置连接密码
1. 修改配置文件
- [root@40 ~]# vim /etc/redis/6379.conf
- 501 requirepass 123446(密码)
设置秘密后我们用脚本关闭文件会出现如下报错
[root@40 ~]# redis_6379 stop
Stopping ...
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
...........
解决方法 1:
[root@40 ~]# redis-cli -h 192.168.4.40 -p 6040 -a 123446 shutdown
解决方法 2: 修改脚本文件
- 43 $CLIEXEC -h 192.168.4.40 -p $REDISPORT -a 123446 shutdown
- [root@40 ~]# redis_6379 stop
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
来源: http://www.bubuko.com/infodetail-2690924.html