Redis5生产环境--主从哨兵集群

今天操作失误玩坏了一个主机,都没了 唉!!!
趁着热乎写一篇redis集群搭建吧
配置阿里云镜像:执行1,2,3步骤

安装Redis5

1, yum install wget
2, cd ~
3, mkdir soft
4, cd soft
5, wget    http://download.redis.io/releases/redis-5.0.5.tar.gz
6, tar xf    redis...tar.gz
7, cd redis-src
8, make 
9, #如果失败,安装gcc重新编译
....yum install gcc  
....make distclean
10, make
11, cd src   #已经生成了可执行程序了
12, cd ..
13, make install PREFIX=/opt/redis5
14, vi /etc/profile
...   export  REDIS_HOME=/opt/redis5
...   export PATH=$PATH:$REDIS_HOME/bin
..source /etc/profile
---------------------------------------
# 安装Redis实例, 主从集群为防止脑裂要安装2n+1台实例
1, cd /opt/redis-5.0.5/utils
2, ./install_server.sh  # 执行3次并选定端口号
# 安装程序生成/etc/init.d/6379.conf,6380.conf,6381.conf. 且脚本路径指向/etc/redis/6379.conf... 备份启动配置
3, 依次修改配置6379.conf 防止成需挂起,标准输出重定向到显示屏
   # By default Redis does not run as a daemon. Use 'yes' if you need it.
   # Note that Redis will write a pid file in /var/run/redis.pid when   daemonized.
   daemonize no
   # Specify the log file name. Also the empty string can be used to force
   # Redis to log on the standard output. Note that if you use standard
   # output for logging but daemonize, logs will be sent to /dev/null
   #logfile /var/log/redis_6379.log
4, 启动命令: service redis_6379 start/stop/stauts
5, ps -fe |  grep redis

主从启动

1, cd /etc/redis
主机启动命令:redis-server ./6379.conf
从机启动命令:redis-server ./6380.conf --REPLICAOF 127.0.0.1 6379
replicaop 127.0.0.1 6379   
从机启动命令:redis-server ./6381.conf --REPLICAOF 127.0.0.1 6379
replicaop 127.0.0.1 6379   ***replicaop表示追随的意思***
2, 远程登录要设置强密码,否则连不上
开放连接限制:bind 0.0.0.0 

哨兵启动

1, cp /opt/redis-5.0.5/sentinel.conf  /etc/redis目录下
2, cp /opt/redis-5.0.5/sentinel.conf 26379.conf
   cp /opt/redis-5.0.5/sentinel.conf 26380.conf
   cp /opt/redis-5.0.5/sentinel.conf 26381.conf
3, 修改脚本
   port 26379
   sentinel monitor mymaster 127.0.0.1 6379 2 
   port 26380
   sentinel monitor mymaster 127.0.0.1 6379 2 
   port 26381
   sentinel monitor mymaster 127.0.0.1 6379 2 

先启动哨兵在系统主从集群
启动命令:redis-server ./26379.conf --sentinel
启动命令:redis-server ./26380.conf --sentinel
启动命令:redis-server ./26381.conf --sentinel

Redis解决分布式脑裂模式

Redis5生产环境--主从哨兵集群_第1张图片

哨兵脚本配置说明:
------------------------------------------------------------------
#是否为守护进程
daemonize no

pidfile "/var/run/redis/redis-sentinel.pid"
logfile "/var/log/redis/redis-sentinel.log"
bind 127.0.0.1
port 26379

#工作目录
dir "/var/lib/redis"

#声明该哨兵的主库是mymaster,主库的ip和端口分别为127.0.0.1和6379
#最后一个2的含义是,在哨兵发生领导选举时,该哨兵需要获得2票才能成为leader
sentinel monitor mymaster 127.0.0.1 6379 2

#在mymaster宕机30秒后进行主观下线
sentinel down-after-milliseconds mymaster 30000

#指定在发生failover故障转移时最多可以有1个slave同时对新的master进行同步
sentinel parallel-syncs mymaster 1

#设置故障转移超时时间为180秒
#这个参数的意义比较复杂,详细可以参考官方的注释说明
sentinel failover-timeout mymaster 180000

#发现两个从节点
sentinel known-slave mymaster 127.0.0.1 6380
sentinel known-slave mymaster 127.0.0.1 6381

#epoch实现类似版本号的功能
sentinel current-epoch 0
-------------------------------------------------------

你可能感兴趣的:(Redis5生产环境--主从哨兵集群)