Centos7 安装redis-6.0.6

1.关闭防火墙:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)


2.配置编译环境:

yum -y install gcc
yum -y install epel-release

3.下载:

wget http://download.redis.io/releases/redis-6.0.6.tar.gz

4.解压

tar xzf redis-6.0.6.tar.gz

5.进入对应redis根目录编译安装(指定目录):

make && make PREFIX=/usr/local/redis install 

Centos7 安装可能会有一个问题

# 查看gcc版本是否在5.3以上,centos7.6默认安装4.8.5
gcc -v
# 升级gcc到5.3及以上,如下:
升级到gcc 9.3:
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或重启就会恢复原系统gcc版本。
如果要长期使用gcc 9.3的话:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
这样退出shell重新打开就是新版的gcc了
以下其他版本同理,修改devtoolset版本号即可。

其他

# 编译出错时,清除编译生成的文件
make distclean
# 编译安装到指定目录下
make PREFIX=/usr/local/redis install 
# 卸载
make uninstal

配置启动

进入到安装的目录/data/redis-6.0.6下 将源码中的redis.conf文件 复制到redis6的bin目录下并修改配置

cp /data/redis-6.0.6/redis.conf /usr/local/redis/bin

vim /usr/local/redis/bin/redis.conf
#daemonize no 改为yes,开启后台运行,默认是前台运行
daemonize yes
#把这一行注释,监听所有IP
#bind 127.0.0.1
#protected-mode yes 如果改为no,则是关闭保护模式,这种模式下不能配置系统服务,建议还是开启
protected-mode yes
#requirpass,保护模式开启的时候要配置密码或者bind ip
requirepass 123456
#修改本参数,指定数据目录
dir /opt/redis6/data
#修改本参数,指定日志目录
logfile /opt//redis6/redis_6379.log

编写启动脚本

vim /lib/systemd/system/redis.service

[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

使用systemctl命令

# 重载服务
systemctl daemon-reload
# 启动
systemctl start redis
# 重启
systemctl restart redis    
# 停止
systemctl stop redis
# 开机自启
systemctl enable redis
# 查看状态
systemctl status redis
# 关闭开机启动
systemctl disable redis

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值