Linux(CentOS)环境下安装Redis 5
安装Redis
从Redis官网下载最新版本的redis。
1 | sudo wget http://download.redis.io/releases/redis-5.0.8.tar.gz |
如需安装 Redis 4 版本,可参考 Linux(CentOS)环境安装Redis 4
新建redis安装目录
1 | sudo mkdir /usr/local/redis |
解压Redis
1 | sudo tar -zxvf redis-5.0.8.tar.gz -C /usr/local/redis |
编译Redis
先安装gcc
1 | $ sudo yum install gcc-c++ |
编译
1 | cd /usr/local/redis/redis-5.0.8/ |
安装
把redis安装在目录/usr/local/redis/redis-5.0.8/
中,如果不写 PREFIX 参数,即默认安装在/usr/local/bin
下面
1 | cd src/ |
1 | make test |
安装tcl
1 | sudo yum install tcl |
1 | sudo make test |
安装完成后,在目录 /usr/local/redis/redis-5.0.8
下面会出现一个 bin 目录
1 | ll bin/ |
启动Redis服务
1 | bin/redis-server |
通过客户端连接redis服务
1 | bin/redis-cli |
如果通过非127.0.0.1连接,会报如下错误:
1 | bin/redis-cli -h 192.168.229.130 |
1 | (error) DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside. |
修改配置文件
1 | sudo vi redis.conf |
修改 bind 参数
1 | bind 0.0.0.0 |
重启 redis 服务
通过 -h
指定redis服务的地址
1 | bin/redis-cli -h 192.168.229.130 |
运行完成以后,如果需要关闭redis服务
1 | 127.0.0.1:6379> SHUTDOWN SAVE |