二进制部署redis

2023-12-19  本文已影响0人  自由如风才是少年的梦

下载源码包

https://download.redis.io/releases/?_gl=1*fez57b*_ga*MjExMjEzMDA0Ni4xNjc3MDMyOTQ4*_ga_8BKGRQKRPV*MTY4MzMzNzU2My41LjEuMTY4MzMzNzU3Ny40Ni4wLjA.

基础环境

yum install -y  gcc tcl

解压

tar xf redis-6.0.8.tar.gz 

编译

cd redis-6.0.8
make 
PREFIX=/data/redis make  install
make install
cp ./src/redis-trib.rb /usr/local/bin/

这里可能会编译报错:

server.c:5492:176: 错误:‘struct redisServer’没有名为‘maxmemory’的成员

gcc版本问题

解决方法:

#升级到 5.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命令启用只是临时的,退出xshell或者重启就会恢复到原来的gcc版本。
#如果要长期生效的话,执行如下:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

创建目录

mkdir -p /data/redis/{data,log,conf}

配置文件

上传配置文件redis.conf

vim /data/redis/conf/redis.conf

参数解释

#禁掉bind(允许非本地访问)
#bind 127.0.0.1
#端口
port 6379
#设置密码
requirepass Gjxx!wyc.com
#pid文件路径
pidfile /data/redis/log/redis.pid
#日志位置
logfile /data/redis/log/redis.log
#备份名字
dbfilename "cluster-dump.rdb"
#data路径
dir /data/redis/data/

使用systemctl管理redis

vim /etc/systemd/system/redis.service
[Unit]
Description=Redis
After=network.target

[Service]
Type=simple
ExecStart=/data/redis/bin/redis-server /data/redis/conf/redis.conf  --daemonize no
ExecStop=/data/redis/bin/redis-cli -p 6379 -a Gjxx!wyc.com shutdown

[Install]
WantedBy=multi-user.target

刷新配置

systemctl daemon-reload

启动

启动(重启):
systemctl start(restart) redis
停止:
systemctl stop redis
开机自启动:
systemctl enable redis 

验证

redis-cli -h 127.0.0.1 -p 6379 -a 'Gjxx!wyc.com'
127.0.0.1:6379> set hello word
OK
127.0.0.1:6379> get hello
"word"

完成!

上一篇 下一篇

猜你喜欢

热点阅读