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 配置之后
相关推荐
神秘的土鸡2 分钟前
Linux中使用Docker容器构建Tomcat容器完整教程
linux·运维·服务器·docker·容器·tomcat
TravisBytes36 分钟前
linux 系统是如何收发数据包
linux·运维·服务器
芊言芊语1 小时前
分布式缓存服务Redis版解析与配置方式
redis·分布式·缓存
攻城狮的梦2 小时前
redis集群模式连接
数据库·redis·缓存
ice___Cpu2 小时前
Linux 基本使用和 web 程序部署 ( 8000 字 Linux 入门 )
linux·运维·前端
z202305082 小时前
linux 之0号进程、1号进程、2号进程
linux·运维·服务器
狐心kitsune3 小时前
erlang学习:Linux常用命令1
linux·学习·erlang
DREAM依旧4 小时前
《深入了解 Linux 操作系统》
linux
阿赭ochre4 小时前
Linux环境变量&&进程地址空间
linux·服务器
Iceberg_wWzZ4 小时前
数据结构(Day14)
linux·c语言·数据结构·算法