今天服务器安装了redis。为了安全起见,设置访问redis-server的密码。1.找到redis.conf文件我们的服务器已经安装了redis,现在通过命令查看redis进程:[root@lnp~]#ps-aux|grepredisroot73740.00.01453127524?ssl16:370:00redis-server192.168.17.105:6379root106920.00.0112724984pts/7S+16:540:00grep--color=autoredis可以看到我们的redis-server的服务地址是192.168.17.105,端口为6379,external访问时需要指定对应的IP和端口:redis-cli-h192.168.17.105-p6379找到redis安装目录>whereisredisredis:/usr/local/redis我们可以看到这个目录下安装了redis,然后找到配置文件redis.conf>找到/usr/local/redis/-nameredis.conf/usr/local/redis/etc/redis.conf修改配置文件:vimredis.conf可以更改配置文件:#requirepassfoobaredrequirepass123指定密码123最后一步重新加载配置文件:redis-server/usr/local/redis/etc/redis.conf2.连接测试用密码访问-a:>redis-cli-h192.168.17.105-p6379-a123运行结果:[root@lnpetc]#redis-cliCouldnotconnecttoRedisat127.0.0.1:6379:ConnectionrefusedCouldnotconnecttoRedisat127.0.0.1:6379:连接被拒绝未连接>exit[root@lnpetc]#redis-cli-h192.168.17.105-p6379192.168.17.105:6379>keys*(error)NOAUTHAuthenticationrequired.192.168.17.105:6379>exit[root@lnpetc]#redis-cli-h192.168.17.105-p6379-a123警告:在命令行界面上使用带有“-a”选项的密码可能不安全。192.168.17.105:6379>keys*(emptylistorset)192.168.17.105:6379>exit
