今天服務器安裝了redis,爲了安全設置一下訪問redis-server的密碼。
咱們服務器已經安裝了redis,如今經過命令查看下redis的進程:redis
[root@lnp ~]# ps -aux|grep redis root 7374 0.0 0.0 145312 7524 ? Ssl 16:37 0:00 redis-server 192.168.17.105:6379 root 10692 0.0 0.0 112724 984 pts/7 S+ 16:54 0:00 grep --color=auto redis
能夠看到咱們的redis-server
的服務地址爲192.168.17.105
,端口爲6379
,對外訪問的時候須要指定對應的IP和端口:vim
redis-cli -h 192.168.17.105 -p 6379
查找redis安裝目錄安全
> whereis redis redis: /usr/local/redis
咱們能夠看到redis在該目錄下安裝,而後找到配置文件redis.conf
服務器
> find /usr/local/redis/ -name redis.conf /usr/local/redis/etc/redis.conf
修改配置文件:測試
vim redis.conf
改該配置文件便可:ui
# requirepass foobared requirepass 123 指定密碼123
最後一步,從新加載配置文件便可:code
redis-server /usr/local/redis/etc/redis.conf
經過密碼-a
訪問:server
> redis-cli -h 192.168.17.105 -p 6379 -a 123
運行結果:進程
[root@lnp etc]# redis-cli Could not connect to Redis at 127.0.0.1:6379: Connection refused Could not connect to Redis at 127.0.0.1:6379: Connection refused not connected> exit [root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379 192.168.17.105:6379> keys * (error) NOAUTH Authentication required. 192.168.17.105:6379> exit [root@lnp etc]# redis-cli -h 192.168.17.105 -p 6379 -a 123 Warning: Using a password with '-a' option on the command line interface may not be safe. 192.168.17.105:6379> keys * (empty list or set) 192.168.17.105:6379> exit