Redis 集群搭建 哨兵模式搭建

文章目录

  • Redis version 6.0.5 集群搭建
    • 下载文件
    • 环境安装
    • 解压
    • 编译
    • 配置文件
    • 启动
    • 关闭
    • 密码设置

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 配置之后

你可能感兴趣的:(分布式理论&中间件搭建,缓存,Linux,linux,redis)