##Redis 密码配置
默认的redis是没有配置密码的,因此为了安全保证我们需要配置相应的密码,redis配置密码也很简单
依然是修改redis.conf,但是这里我们已经修改为6379.conf了,将# requirepass foobared修改为requirepass xxxxxx(你的密码)
[root@nic-redis ~]# vi /etc/redis/6379.conf
修改好后
[root@nic-redis ~]# service redisd stop
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
[root@nic-redis ~]# service redisd start
Starting Redis server...
3659:C 16 Sep 22:11:31.768 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
3659:C 16 Sep 22:11:31.769 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=3659, just started
3659:C 16 Sep 22:11:31.769 # Configuration loaded
[root@nic-redis ~]# red
red redis-check-rdb redis-server
redis-benchmark redis-cli redis-trib.rb
redis-check-aof redis-sentinel redland-db-upgrade
[root@nic-redis ~]# redis-cli
127.0.0.1:6379> key *
(error) ERR unknown command `key`, with args beginning with: `*`,
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379>
这样就完成了redis的密码配置,当然有了密码了在命令行关闭redis就不一样了没法直接通过service redisd stop关闭了会出现以下情况
[root@nic-redis ~]# service redisd stop
Stopping ...
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
这时候可以通过另外的方法来关闭
[root@nic-redis ~]# redis-cli -a 123456 shutdown
这样就能顺利的关闭redis了
##Redis 远程访问配置
首先我们在服务器上访问设置一下
[root@nic-redis ~]# redis-cli
127.0.0.1:6379> keys color
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> keys color
(empty list or set)
127.0.0.1:6379> set color red
OK
127.0.0.1:6379> get color
"red"
127.0.0.1:6379>
同样的修改一下redis.conf配置文件
[root@nic-redis ~]# vi /etc/redis/6379.conf
将#bind 127.0.0.1修改为bind 0.0.0.0,意思就是允许从任意地址访问redis,当然也可以限定多个ip地址访问,多个地址之间用空格分隔,这样我们就能通过远程来访问redis了。下一步我将写一篇文章来介绍通过spring data redis实现对redis的操作