一身转战三千里,一剑曾当百万师。这篇文章主要讲述Redis哨兵模式部署相关的知识,希望能为你提供帮助。
1.Redis编译安装(三台)以下操作在三台主机同样操作
1.1 安装依赖包yum -y install gcc gcc-c++ libstdc++-devel
1.2 上传redis二进制包tar zxvf redis-5.0.14.tar.gz -C /data
1.3 编译redis,生成redis可执行文件cd /data/redis ;
mv redis-5.0.14/* .
make MALLOC=libc
2. 创建redis配置文件(三台)创建数据目录
mkdir -p /data/redis/cluster/redis.conf
修改权限
chown -R redis:redis /data/redis
创建配置文件
2.1 第一台cat >
/data/redis/cluster/redis.conf<
<
EOF
bind 10.1.2.121
port 6379
daemonize yes
pidfile "
/var/run/redis.pid"
logfile "
/data/redis/cluster/redis.log"
dir "
/data/redis/cluster/redis"
masterauth glstbrMrVE
requirepass "
glstbrMrVE"
appendonly yes
maxmemory 7gb
EOF
2.2 第二台cat >
/data/redis/cluster/redis.conf <
<
EOF
bind 10.1.2.122
port 6379
daemonize yes
pidfile "
/var/run/redis.pid"
logfile "
/data/redis/cluster/redis.log"
dir "
/data/redis/cluster/redis"
masterauth "
glstbrMrVE"
requirepass "
glstbrMrVE"
appendonly yes
maxmemory 7gb
EOF
2.3 第三台cat >
/data/redis/cluster/redis.conf <
<
EOF
bind 10.1.2.123
port 6379
daemonize yes
pidfile "
/var/run/redis.pid"
logfile "
/data/redis/cluster/redis.log"
dir "
/data/redis/cluster/redis"
masterauth "
glstbrMrVE"
requirepass "
glstbrMrVE"
appendonly yes
maxmemory 7gb
EOF
2.4 拷贝redis-server、redis-cli、redis-sentinel可执行文件cpsrc/redis-server /usr/bin/
cp src/redis-cli /usr/bin/
cp src/redis-sentinel /usr/bin/
chmod +x /usr/bin/redis-server
chmod +x /usr/bin/redis-cli
chmod +x /usr/bin/redis-sentinel
chown -R redis:redis /data/redis
2.5 配置自启动配置文件(三台)
2.5.1 第一台
cat >
/usr/lib/systemd/system/redis.service <
<
EOF
[Unit]
Description=Redis
After=network.target
【Redis哨兵模式部署】[Service]
Type=forking
PIDFile=/var/run/redis.pid
ExecStart=/usr/bin/redis-server /data/redis/cluster/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/redis-cli -h 10.1.2.121 -p 6379 shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
2.5.2 第二台
cat >
/usr/lib/systemd/system/redis.service <
<
EOF
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis.pid
ExecStart=/usr/bin/redis-server /data/redis/cluster/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/redis-cli -h 10.1.2.122 -p 6379 shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
2.5.3 第三台
cat >
/usr/lib/systemd/system/redis.service <
<
EOF
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis.pid
ExecStart=/usr/bin/redis-server /data/redis/cluster/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/bin/redis-cli -h 10.1.2.123 -p 6379 shutdown
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
2.5.4 添加启动项及启动(三台)
Systemctl daemon-reload
Systemctl enable redis
Systemctl start redis
2.配置哨兵模式注意事项
创建集群之前需要保证其他节点都正常安装和配置单机redis
2.1 配置哨兵配置文件(三台)
2.1.1 第一台
cat >
/data/redis/sentinel.conf <
<
EOF
daemonize yes
bind 10.1.2.121
port 26379
logfile "
/data/redis/logs/sentinel.log"
dir "
/data/redis/sentinel"
sentinel myid e2f7c688a4285e6b72d8e2e02d1f6a2f0611ea0e
sentinel deny-scripts-reconfig yes
sentinel monitor master 10.1.2.123 6379 2
sentinel down-after-milliseconds master 5000
sentinel failover-timeout master 15000
sentinel parallel-syncs master 2
sentinel auth-pass master glstbrMrVE
EOF
2.1.2 第二台
cat >
/data/redis/sentinel.conf <
<
EOF
daemonize yes
bind 10.1.2.122
port 26379
logfile "
/data/redis/logs/sentinel.log"
dir "
/data/redis/sentinel"
sentinel myid 3e89710158cbfcd99938946cb07e41216a034584
sentinel deny-scripts-reconfig yes
sentinel monitor master 10.1.2.123 6379 2
sentinel down-after-milliseconds master 5000
sentinel failover-timeout master 15000
sentinel parallel-syncs master 2
EOF
2.1.3 第三台
cat >
/data/redis/sentinel.conf <
<
EOF
daemonize yes
bind 10.1.2.123
port 26379
logfile "
/data/redis/logs/sentinel.log"
dir "
/data/redis/sentinel"
sentinel myid 9caba6da81a5452fc7269de27841042fcdfe92ef
sentinel deny-scripts-reconfig yes
sentinel monitor master 10.1.2.123 6379 2
sentinel down-after-milliseconds master 5000
sentinel failover-timeout master 15000
sentinel parallel-syncs master 2
EOF
2.2配置哨兵启动项(三台)
2.2.1 第一台
cat >
/usr/lib/systemd/system/sentinel.service <
<
EOF
[Unit]
Description=Redis Sentinel
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/bin/redis-sentinel /data/redis/sentinel.conf --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
[Install]
WantedBy=multi-user.target
EOF
2.2.2第二台和第三台同样配置
2.2.3 配置启动项和启动哨兵(三台)
Systemctl enable sentinel
Systemctl start sentinel
3.验证集群
3.1 登陆主节点redis-cli-h 10.1.2.123 -p 6379 -a glstbrMrVE
执行以下语句
10.1.2.123:6379>
info replication
如图:
文章图片
3.2 登陆从节点redis-cli -h 10.1.2.121-p 6379-a glstbrMrVE
0.1.2.121:6379> info replication
如图:
文章图片
推荐阅读
- 小白用c语言编写七大排序(上)方法(?为了让和笔者一样的小白能看懂,笔者注释了很多))
- zabbix5.0自定义web监控
- SpringBoot中的Schedule定时任务#yyds干货盘点#
- webterminal开源堡垒机
- #yyds干货盘点#为了完成小姐姐安排的打分系统,又熬了一个小时的夜补充视图与模板
- 用 3000 字告诉大家,我们为什么要学习 Springboot()
- #yyds干货盘点# C#+Access+asp.net教学计划管理系统
- 带你读AI论文丨RAID2020 Cyber Threat Intelligence Modeling GCN
- oeasy教您玩转vim - 88 - # 自动命令autocmd