1、yum install安装redis源码安装所需工具
yum -y install gcc automake autoconf libtool make vim wget
2、下载并解压redis安装包
# 目录切换
cd /usr/local
# 下载redis源码
wget http://download.redis.io/releases/redis-7.0.10.tar.gz
# 解压redis源码
tar -zvxf redis-7.0.10.tar.gz
3、进入解压包并执行编译
# 进入解压包
cd redis-7.0.10
# 执行编译
make
4、执行安装并指定安装目录
make install PREFIX=/usr/local/redis
5、启动服务
前台启动
/usr/local/redis/bin/redis-server
后台启动
# 把redis解压包配置文件拷贝一份到安装目录下
cp /usr/local/redis-7.0.10/redis.conf /usr/local/redis/bin/
修改 redis.conf 文件,把 daemonize no 改为 daemonize yes
/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
6、设置开机启动
添加开机启动服务
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
设置开机启动
# 重新加载配置
systemctl daemon-reload
# 重启redis服务
systemctl restart redis.service
# 设置开机就启动redis服务
systemctl enable redis.service
# redis-cli客户端设置软连接
ln -s /usr/local/redis/bin/redis-cli /usr/bin/redis
7、redis服务操作命令
# 启动redis服务
systemctl start redis.service
# 停止redis服务
systemctl stop redis.service
# 重新启动服务
systemctl restart redis.service
# 查看服务当前状态
systemctl status redis.service
# 设置开机自启动
systemctl enable redis.service
# 停止开机自启动
systemctl disable redis.service
</div>