centos8 redis 6.2.6源码安装+主从哨兵

centos8 redis 6.2.6源码安装+主从哨兵

单机安装

下载解压

cd /data
wget http://download.redis.io/releases/redis-6.2.6.tar.gz
tar xf redis-6.2.6.tar.gz
cd redis-6.2.6/

编译安装

make PREFIX=/usr/local/redis6 install

如果编译提示jemallo文件不存在,清空make缓存重新编译
make distclea
make clean

配置

mkdir /usr/local/redis6/conf

cp redis.conf /usr/local/redis6/conf/

mkdir -p /data/redis6/data
mkdir -p /data/redis6/logs

vi /usr/local/redis6/conf/redis.conf

#配置参数,其他默认
bind 0.0.0.0
protected-mode no
port 6379
daemonize yes
logfile "/data/redis6/logs/redis.log"
dir /data/redis6/data/
maxmemory 2048MB
io-threads 4
requirepass mh112233

配置systemd

vi /lib/systemd/system/redis6.service
[Unit]
Description=Redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis6/bin/redis-server /usr/local/redis6/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

服务启停及开机启动

systemctl daemon-reload 
systemctl start redis6
systemctl enable redis6

登录验证

ln -s /usr/local/redis6/bin/redis-cli /usr/bin/redis-cli
redis-cli -h 127.0.0.1 -p 6379 -a mh112233
set a 11
get a

主从同步

#从节点增加配置,ip指向主节点
replicaof 192.168.122.230 6379
#配置密码
masterauth mh112233

#检查主从同步状态
info replication

配置哨兵

cp sentinel.conf /usr/local/redis6/conf/
mkdir -p /data/redis6/data/sentinel

vi /usr/local/redis6/conf/sentinel.conf

#配置参数,其他默认
bind 0.0.0.0
protected-mode no
port 26379
daemonize yes
logfile "/data/redis6/logs/sentinel.log"
dir /data/redis6/data/sentinel/

#指定Redis主节点主机IP地址和端口,ip根据实际情况调整,mymaster这个名称随便取,下面配置时也需要指定这个名称,客户端连接时也会使用
#最后的2是指需要有2个以上sentinel节点认为redis主节点失效,才是真的失效,一般为(sentinel总数/2+1)
sentinel monitor mymaster 192.168.122.230 6379 2

#配置连接密码,此处的密码需要与 redis.conf里面配置的连接密码一致
sentinel auth-pass mymaster mh112233

哨兵注册systemd

vi /lib/systemd/system/sentinel.service
[Unit]
Description=Redis-sentinel
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis-sentinel.pid
ExecStart=/usr/local/redis6/bin/redis-sentinel /usr/local/redis6/conf/sentinel.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target


systemctl daemon-reload 
systemctl start sentinel
systemctl enable sentinel

#连接哨兵服务,检查状态
redis-cli -h 127.0.0.1 -p 26379
info sentinel
  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值