1.官网下载redis
[root@localhost ~]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz
2.解压文件
[root@localhost ~]# tar -zxvf redis-5.0.5.tar.gz
3.进入解压目录,编译
[root@localhost ~]# cd redis-5.0.5
[root@localhost redis-5.0.5]# make
4.启动redis-server 服务 【后台守护进行执行】
[root@localhost redis-5.0.5]# pwd
/root/redis-5.0.5
[root@localhost redis-5.0.5]# cd src/
[root@localhost src]# ./redis-server &
5.进入redis客户端
[root@localhost src]# pwd
/root/redis-5.0.5/src
[root@localhost src]# ./redis-cli
127.0.0.1:6379> keys *
(empty list or set)
6.设置redis密码
1.redis命令方式设置(该方法在重启Redis后密码将失效)
[root@localhost src]# ./redis-cli
127.0.0.1:6379> config set requirepass 123456ok
OK
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379>
#从上面可以看到密码设置成功,同时一旦密码设置成功,刚刚建立的连接将不能进行任何权限操作
使用-a 密码 登录redis
[root@localhost src]# ./redis-cli -h 127.0.0.1 -p 6379 -a 123456ok
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
(empty list or set)
2.通过Redis配置文件redis.conf进行设置密码(注意:该方法设置密码后需要重启Redis才生效):
[root@localhost src]# find / -name redis.conf
/root/redis-5.0.5/redis.conf
[root@localhost src]# vim /root/redis-5.0.5/redis.conf
重启redis:
[root@localhost src]# ps -ef|grep redis
root 8208 2629 0 02:21 pts/1 00:00:00 ./redis-server *:6379
root 8373 2629 0 02:25 pts/1 00:00:00 grep --color=auto redis
[root@localhost src]# kill -9 8208
#使用配置文件redis.conf【使用密码的时候需要添加配置文件路径、或修改配置的时候都需要加载配置文件】
[root@localhost src]# ./redis-server /root/redis-5.0.5/redis.conf
重新连接redis客户端
#没有输入密码
[root@localhost src]# ./redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
#输入密码
[root@localhost src]# ./redis-cli -h 127.0.0.1 -p 6379 -a 123456ok
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
1) "name"
2) "name1"
7.外部需要连接redis的时候
注意需要修改监听的地址(redis.conf配置文件):
8.现在想要将日志打印到文件中可以修改 (redis.conf配置文件)