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

相关推荐

  1. centos8 redis 6.2.6安装+主从哨兵

    2023-12-05 15:48:05       40 阅读
  2. redis哨兵高可用-

    2023-12-05 15:48:05       43 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-05 15:48:05       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-05 15:48:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-05 15:48:05       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-05 15:48:05       20 阅读

热门阅读

  1. Android 手机屏幕适配方式和原理

    2023-12-05 15:48:05       39 阅读
  2. 基于遗传算法求解带容量的VRP问题的MATLAB源码

    2023-12-05 15:48:05       37 阅读
  3. layui下拉框jQuery动态修改选中并展示

    2023-12-05 15:48:05       46 阅读
  4. 深度学习(二):pytorch基础知识

    2023-12-05 15:48:05       24 阅读