Redis 集群搭建 哨兵模式搭建

文章目录

Redis version 6.0.5 集群搭建

下载文件

复制代码
下载 命令 url 可找官网  复制
wget http://download.redis.io/releases/redis-6.0.5.tar.gz

环境安装

复制代码
yum install gcc-c++
yum install cpp 
yum install binutils
yum install glibc 
yum install glibc-kernheaders
yum install glibc-common
yum install glibc-devel
yum install gcc
yum install make
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

解压

复制代码
创建redis文件夹
cd /home
mkdir redis
cd redis
解压 
tar -zxvf redis-6.0.5.tar.gz
重命名
mv redis-6.0.5 redis-1
复制 
cp -r redis-1 redis-2
cp -r redis-1 redis-3 

编译

复制代码
cd /home/redis/redis-1
每一个redis执行下行命令
scl enable devtoolset-9 bash
如果以以下编译安装 的命令失败 基本上是因为 环境安装问题 可以直接百度 相关更全面的安装环境
make MALLOC=lib
make install

配置文件

复制代码
master redis.conf  配置

vim /home/redis/redis-1/redis.conf
bind 0.0.0.0
protected-mode yes
port 16379
supervised no
pidfile "/home/redis/pid/16379.pid"
loglevel notice
logfile "/home/redis/log/16379.log"
databases 16
dir "/home/redis/data"
dbfilename dump16379.rdb
appendonly yes  # 开启 aof  默认不开启 
appendfilename "appendonly_16379.aof"
daemonize yes

master sentinel.conf 配置
bind 0.0.0.0
port 26379
pidfile /home/redis/pid/-sentinel-26379.pid
logfile "/home/redis/log/sentinel-26379.log"
下面配置的ip 配置公网ip port 配置  master redis.conf  配置中的port
sentinel monitor mymaster ip 16379 2

slave redis.conf

bind 0.0.0.0
port 16380
daemonize yes
pidfile "/home/redis/pid/16380.pid"
logfile "/home/redis/log/16380.log"
dir "/home/redis/data"
appendonly yes  # 开启 aof  默认不开启 
appendfilename "appendonly_16380.aof"
slaveof masterIp masterPort

slave sentinel.conf 配置

bind 0.0.0.0
port 26380
daemonize yes
pidfile "/home/redis/pid/sentinel-26380.pid"
logfile "/home/redis/log/sentinel-26380.log"
下面配置的ip 配置公网ip port 配置  master redis.conf  配置中的port
sentinel monitor mymaster MasterIP MasterPort 2

启动

复制代码
启动脚本

#!/bin/bash

# 启动 Redis-Server
echo "Star Redis-Server ..."


redis-1/src/redis-server redis-1/redis.conf &

# sleep 1 睡眠1秒
# sleep 1s 睡眠1秒
# sleep 1m 睡眠1分
# sleep 1h 睡眠1小时
sleep 3

redis-2/src/redis-server redis-2/redis.conf &
redis-3/src/redis-server redis-3/redis.conf &

# 启动 Redis-Sentinel
echo "Star Redis-Sentinel ..."

redis-1/src/redis-sentinel redis-1/sentinel.conf &
redis-2/src/redis-sentinel redis-2/sentinel.conf &
redis-3/src/redis-sentinel redis-3/sentinel.conf &

关闭

复制代码
关闭脚本

#!/bin/bash
# 停止 Redis-Server
echo "Shutdown Redis-Sentinel ..."
redis-1/src/redis-cli -h 公网ip -p 16379 shutdown
redis-2/src/redis-cli -h 公网ip -p 16380 shutdown
redis-3/src/redis-cli -h 公网ip -p 16381 shutdown
# 停止 Redis-Server
echo "Shutdown Redis-Server ..."
redis-1/src/redis-cli -h  公网ip -p 26379 -a 123456 shutdown
redis-2/src/redis-cli -h  公网ip -p 26380 -a 123456 shutdown
redis-3/src/redis-cli -h  公网ip -p 26381 -a 123456 shutdown

密码设置

复制代码
# 两台机器一台master,一台slave,两个sentinel
#master修改
#1. redis.conf
requirepass 123456        #添加密码
#2. sentinel.conf
sentinel auth-pass mymaster 123456     #连接master密码
#slave修改
#1. redis.conf
masterauth 123456    #连接master密码
slaveof 10.100.134.109 6379  #slaveof表示该机器是slave,后边ip为master地址和端口
#2. sentinel.conf
sentinel auth-pass mymaster 123456     #连接master密码,这个配置一定要在sentinel monitor 配置之后
相关推荐
AlfredZhao11 小时前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户97183563346617 小时前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪19 小时前
linux 拷贝文件或目录到指定的位置
linux
摇滚侠1 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
bush41 天前
嵌入式linux学习记录十四、术语
linux·嵌入式
载数而行5201 天前
Linux 11 动态监控指令top
linux
小小工匠1 天前
Redis - 事务机制:能实现 ACID 属性吗
数据结构·redis·性能优化·并发·持久化
不会C语言的男孩2 天前
Linux 系统编程 · 第 8 章:进程基础
linux·c语言
古城小栈2 天前
Unix 与 Linux 异同小叙
linux·服务器·unix
凡人叶枫2 天前
Effective C++ 条款42:了解 typename 的双重意义
java·linux·服务器·c++