下载并解压安装包
[root@localhost ~]# yum install -y gcc
[root@localhost ~]# wget https://download.redis.io/releases/redis-5.0.4.tar.gz
[root@localhost ~]# tar -zxvf redis-5.0.4.tar.gz
进入解压目录中,编译,安装
[root@localhost ~]# cd redis-5.0.4
[root@localhost ~]# make
[root@localhost ~]# make install PREFIX=/usr/local/redis
至此,到这里安装完成,启动即可。下面启动它:
[root@localhost ~]# cd /usr/local/redis/bin/
[root@localhost bin]# ./redis-server
上面这种启动方式是在前台启动了。
创建一个redis客户端的软链接,测试一下:
[root@localhost bin]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis-cli
[root@localhost ~]# redis-cli
127.0.0.1:6379> set name zhangsan
OK
127.0.0.1:6379> get name
"zhangsan"
前台启动一旦窗口关闭,就终止了。下面通过后台启动它:
# 拷贝一个配置文件
[root@localhost bin]# cp /usr/local/redis-5.0.4/redis.conf /usr/local/redis/bin/
# 编辑配置文件,把daemonize no改为daemonize yes
[root@localhost bin]# vim redis.conf
daemonize yes
# 启动服务
[root@localhost bin]# ./redis-server redis.conf
# 查看服务进程
[root@localhost bin]# ps -ef|grep redis
root 7954 5604 0 17:45 pts/1 00:00:00 grep --color=auto redis
root 21755 1 0 Aug30 ? 02:23:05 /usr/local/redis/bin/redis-server *:6379
现在,将它设置成开启启动:
# 编辑一个redis.service文件,添加下面内容
[root@localhost bin]# vim /etc/systemd/system/redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
# 让文件生效
[root@localhost bin]# systemctl daemon-reload
# 启动服务
[root@localhost bin]# systemctl start redis.service
# 开机启动
[root@localhost bin]# systemctl enable redis.service
另一种安装方式见:https://mp.weixin.qq.com/s/10sLAo2EWj0nyle3vKFljA
以上。