centos7 安装redis

1.下载redis安装包并解压

tar -zxvf redis-5.0.3.tar.gz

2.yum安装gcc依赖

yum install gcc

3.编译安装

cd redis-5.0.3

make

4.创建redis目录

mkdir -p /usr/local/redis

5.将redis.conf、redis-cli、redis-server复制到创建的目录

cp ./redis-server /usr/local/redis/
cp ./redis-cli /usr/local/redis/
cd ..
cp redis.conf /usr/local/redis/

6.编辑redis.conf配置文件

cd /usr/local/redis/
vim redis.conf

7.将daemonize参数改为yse,表示redis服务在后台运行

centos7 安装redis_第1张图片

8.将requirepass参数前面注释去掉,并设置密码

centos7 安装redis_第2张图片

9.添加开机启动项

vim /etc/systemd/system/redis-server.service

粘贴以下类容

[Unit]
Description=The redis-server Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/redis-server /usr/local/redis/redis.conf         
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target
systemctl enable redis-server.service
systemctl daemon-reload 
systemctl start redis-server.service 


10.创建软连接

ln -s /usr/local/redis/redis-cli /usr/bin/redis

11.连接访问redis

[hbzh@localhost redis]$ redis
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.

如果报认证错误则需要认证,密码就是配置文件设置的密码

auth '密码'

centos7 安装redis_第3张图片

至此redis已安装完成,可以正常访问了

你可能感兴趣的:(redis)