CentOS7安装和使用redis

1.上传文件到服务器
2.解压压缩包

tar -zxvf redis-4.0.2.tar.gz 

3.移动文件夹到/user/local/redis

mv redis-4.0.2 /usr/local/redis

4.进入redis文件夹编译和安装

cd redis 
make #编译
make install #安装

5.修改配置文件

vi redis.conf
#修改绑定地址,将本地ip修改为0.0.0.0
bind 0.0.0.0
#将redis服务设为一个独立线程
daemonize yes
#设置密码
requirepass 123456

6.进入utils文件夹,安装redis服务

cd utils/
#执行安装脚本
./install_server.sh
#选择配置
Please select the redis port for this instance: [6379] 
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf] /usr/local/redis/redis.conf
Please select the redis log file name [/var/log/redis_6379.log] /usr/local/redis/redis.log
Please select the data directory for this instance [/var/lib/redis/6379] /usr/local/redis/data
Please select the redis executable path [/usr/local/bin/redis-server] 

7.启动服务

systemctl stop redis_6379 #停止服务
systemctl start redis_6379 #启动服务
systemctl status redis_6379 #查看服务状态

8.通过redis-cli使用redis

redis-cli
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> get key1
(nil)
127.0.0.1:6379> set key1 123
OK
127.0.0.1:6379> get key1
"123"
127.0.0.1:6379> exit

你可能感兴趣的:(CentOS7安装和使用redis)