1、安装环境
由于Redis是C语言编写的,所以需要在服务器上安装Redis之前需要确保系统已安装了gcc。以下是安装gcc的命令:
yum install -y gcc
2、安装步骤
1)下载并解压安装包
[root@localhost home]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz
[root@localhost home]# tar -zxvf redis-5.0.3.tar.gz
2)编译安装
[root@localhost home]# cd redis-5.0.3
[root@localhost redis-5.0.3]# make
[root@localhost redis-5.0.3]# make install PREFIX=/usr/local/redis
3)编辑Redis配置文件(移动至Redis可执行程序的同一路径)
修改 redis.conf 文件,把 daemonize no 改为 daemonize yes(支持后台启动)
4)配置Systemd管理
[root@localhost home]# vi /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
5)设置开机自启动
[root@localhost home]# systemctl daemon-reload
[root@localhost home]# systemctl start redis.service
[root@localhost home]# systemctl enable redis.service
6)创建redis软链接
[root@localhost ~]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis
7)测试
[root@localhost bin]# redis
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
至此redis可以很好地在服务器上使用了