Linux redis 安装配置及密码设置

1、下载redis

wget http://download.redis.io/releases/redis-4.0.2.tar.gz
tar xzf redis-4.0.2.tar.gz
cd redis-4.0.2

2、编译安装

make && make install

3、独立命令和配置(可省略)

mkdir /usr/local/redis
cp /usr/local/src/redis-4.0.2/redis.conf /usr/local/redis/
cp /usr/local/src/redis-4.0.2/src/redis-cli /usr/local/redis/
cp /usr/local/src/redis-4.0.2/src/redis-server /usr/local/redis/

4、配置redis.conf

vim /usr/local/redis/redis.conf

将daemonize no 修改为 daemonize yes。作用是使redis后台运行,否则启动redis服务端时会报报警告,导致redis客服端连接不上

5、启动redis服务端

/usr/local/redis/redis-server redis.conf

显示:
24400:C 23 Oct 10:40:25.466 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
24400:C 23 Oct 10:40:25.466 # Redis version=4.0.2, bits=64, commit=565f20a0, modified=0, pid=24400, just started
24400:C 23 Oct 10:40:25.466 # Configuration loaded

说明启动成功

6、启动redis客户端

/usr/local/redis/redis-cli
127.0.0.1:6379>

此时你的redis已经启动成功

设置密码:

1、进入客户端设置密码

127.0.0.1:6379> config set requirepass your_password

此时密码已经设置成功

2、查看密码

127.0.0.1:6379> config get requirepass
(error) NOAUTH Authentication required.

3、此时需要密码验证

127.0.0.1:6379> auth 'your_password'

以后每次登陆redis客户端时,验证一下密码就可以了

/usr/local/redis/redis-cli -h 127.0.0.1 -p 6379 -a 'your_password'

或者

/usr/local/redis/redis-cli
127.0.0.1:6379> auth 'your_password'

你可能感兴趣的:(linux)