Centos7 安装redis

Centos7 安装redis

1) 下载redis源码包尝试安装

# 地址:http://download.redis.io/releases/
# 下载最新稳定版 (此链接目前最新的版本为6.0.8)
wget http://download.redis.io/releases/redis-stable.tar.gz
tar -xf redis-stable.tar.gz
cd redis-stable/
make

参考:https://www.q18idc.com/2020/08/01/centos/centos7-redis.html

2)make 过程中出现报错error

# 各路大神出招
# 报错原因:gcc的版本低,centos默认为4.8 最新的位9.3
yum -y install gcc
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
# scl 执行的命令作用范围是当前shell,退出和重启将失效
# 添加到系统配置文件
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile

3)设置开机自启动

# 将编译后的文件直接拷贝到/usr/local/redis
cp -r ~/workplace/src/redis-stable /usr/local/redis

cd /usr/local/redis
mkdir sbin
ln -s /usr/local/redis/src/redis-server ./sbin/redis-server
ln -s /usr/local/redis/src/redis-cli ./sbin/redis-cli

# 模仿其他应用的配置方式
vim /usr/lib/systemd/system/redis.service

添加如下内容:
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/sbin/redis-server /usr/local/redis/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target

# 创建软连接
ln -s /usr/lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants

4) 创建redis-cli的软连接

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

posted @ 2020-09-23 17:38  pigeast  阅读(165)  评论(0编辑  收藏  举报