欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Redis Sentinel安装、配置和部署

程序员文章站 2022-06-12 14:51:00
...


 转载请注明出处哈:http://carlosfu.iteye.com/blog/2240426


 
实际中,多个sentinel、master、slave不应该在一台机器
 

   

一、准备redis(下载、编译、安装、配置目录、数据目录)

1. 下载、编译、安装

cd /opt/soft
wget http://download.redis.io/releases/redis-3.0.6.tar.gz
tar xzf redis-3.0.6.tar.gz
cd redis-3.0.6
make
make install

 

2. 配置目录、数据目录

cd /opt/soft/redis-3.0.6
mkdir -p data
mkdir -p conf

 

3.建立软链接:

ln -s /opt/soft/redis-3.0.6 /opt/soft/redis

 

 

二、配置、启动Redis节点(本例子以1主2从,3个sentinel组成Redis Sentinel结构)

Redis Sentinel安装、配置和部署
            
    
    博客分类: redis  

 

(1) 配置redis节点,在conf目录下添加3个(7000,7001,7002)redis-${port}.conf作为3个Redis节点的配置文件

      其中7000是主,7001,7002是从

   

   master的配置文件(7000)

port 7000
daemonize yes
pidfile /var/run/redis-7000.pid
logfile "7000.log"
dbfilename "dump-7000.rdb"
appendonly yes
appendfilename "appendonly-7000.aof"
dir "/opt/soft/redis/data/"

 

   生成两个slave的配置文件(7001,7002)

sed 's/7000/7001/g' redis-7000.conf > redis-7001.conf
echo "slaveof 10.10.53.159 7000" >> redis-7001.conf

sed 's/7000/7002/g' redis-7000.conf > redis-7002.conf
echo "slaveof 10.10.53.159 7000" >> redis-7002.conf

  

 

(2) 启动3个节点。

redis-server /opt/soft/redis/conf/redis-7000.conf
redis-server /opt/soft/redis/conf/redis-7001.conf
redis-server /opt/soft/redis/conf/redis-7002.conf

 

 

 

查看节点是否都已经启动:

[@zw_53_162 conf]# ps -ef | grep redis
root     31869     1  0 22:59 ?        00:00:00 redis-server *:7000         
root     31875     1  0 22:59 ?        00:00:00 redis-server *:7001         
root     31885     1  0 22:59 ?        00:00:00 redis-server *:7002 

 

 

查看主从关系:

[@zw_53_162 conf]# redis-cli -p 7000 info replication
# Replication
role:master
connected_slaves:2
slave0:ip=10.10.53.159,port=7001,state=online,offset=15,lag=1
slave1:ip=10.10.53.159,port=7002,state=online,offset=15,lag=1
master_repl_offset:15
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:14

 

 

三、启动sentinel节点:

    (1). 启动3个sentinel节点(26379,26380,26381),配置如下:

     redis-sentinel-26379.conf

   

port 26379
daemonize yes
pidfile /var/run/redis-26379.pid
logfile "26379.log"
dir /opt/soft/redis/data
sentinel monitor mymaster 10.10.53.159 7000 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000

 

  

   redis-sentinel-26380.conf, redis-sentinel-26381.conf

sed 's/26379/26380/g' redis-sentinel-26379.conf > redis-sentinel-26380.conf
sed 's/26379/26381/g' redis-sentinel-26379.conf > redis-sentinel-26381.conf

   

(2) 启动3个sentinel节点。

redis-sentinel /opt/soft/redis/conf/redis-sentinel-26379.conf
redis-sentinel /opt/soft/redis/conf/redis-sentinel-26380.conf
redis-sentinel /opt/soft/redis/conf/redis-sentinel-26381.conf

 

 

查看节点是否都已经启动:

[@zw_53_162 conf]# ps -ef | grep redis-sentinel
root      2949     1  0 23:09 ?        00:00:00 redis-sentinel *:26379 [sentinel]       
root      2955     1  0 23:09 ?        00:00:00 redis-sentinel *:26380 [sentinel]       
root      2961     1  0 23:09 ?        00:00:00 redis-sentinel *:26381 [sentinel]

 

sentinel的info信息查询:

[@zw_53_162 config]# redis-cli -p 26379 info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
master0:name=mymaster,status=ok,address=10.10.53.159:7000,slaves=2,sentinels=3

 

    

 

 

 

  • Redis Sentinel安装、配置和部署
            
    
    博客分类: redis  
  • 大小: 53 KB