redis-sentinel安装部署

redis-sentinel安装部署

1.redis安装

    1)必要的linux库安装

yum install gcc
yum install tcl

     2)下载、解压、编译和安装redis

#创建redis用户和组
groupadd redis
useradd -g redis redis
#修改用户密码
passwd redis

#使用root账户切换到redis目录
cd /home/redis
#下载redis源码redis-3.2.0.tar.gz
wget http://download.redis.io/releases/redis-3.2.0.tar.gz
#解压redis-3.2.0.tar.gz
tar -zxvf redis-3.2.0.tar.gz
#编译和安装
cd /home/redis/redis-3.2.0
make
make install

    3) 安装完成后会在系统目录/usr/local/bin下生成如下文件:

redis-sentinel安装部署

2.redis-sentinel部署

    1)部署结构图如下

redis-sentinel安装部署


    2)3台redis节点部署并启动

        节点一192.168.173.23上做如下配置:

#1.切换到redis用户
su - redis

#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/

#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
    bind 192.168.173.23
    port 6382
    #开启redis守护进程
    daemonize yes
    #指定进程文件存放目录
    pidfile /home/redis/sentinel-cluster/pids/redis.pid
    #指定日志文件存放目录
    logfile "/home/redis/sentinel-cluster/logs/redis.log"
   data /home/redis/sentinel-cluster/data/
    dbfilename dump.rdb
    appendonly yes
    appendfilename "appendonly.aof"
    #主库认证密码
    masterauth abcd_123456
    #客户端连接密码
    requirepass abcd_123456

        节点一192.168.173.23上启动redis服务:

#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/redis.conf

        节点二192.168.173.24上做如下配置:

#1.切换到redis用户
su - redis

#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/

#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
    bind 192.168.173.24
    port 6382
    #开启redis守护进程
    daemonize yes
    #指定进程文件存放目录
    pidfile /home/redis/sentinel-cluster/pids/redis.pid
    #指定日志文件存放目录
    logfile "/home/redis/sentinel-cluster/logs/redis.log"
    data /home/redis/sentinel-cluster/data/
    dbfilename dump.rdb
    appendonly yes
    appendfilename "appendonly.aof"
    #主库认证密码
    masterauth abcd_123456
    #客户端连接密码
    requirepass abcd_123456
    #指定本节点是节点一的从节点
    slaveof 192.168.173.23 6382

         节点二192.168.173.24上启动redis服务:

#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/redis.conf

        节点三192.168.173.25上做如下配置:

#1.切换到redis用户
su - redis

#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/

#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
    bind 192.168.173.25
    port 6382
    #开启redis守护进程
    daemonize yes
    #指定进程文件存放目录
    pidfile /home/redis/sentinel-cluster/pids/redis.pid
    #指定日志文件存放目录
    logfile "/home/redis/sentinel-cluster/logs/redis.log"
    data /home/redis/sentinel-cluster/data/
    dbfilename dump.rdb
    appendonly yes
    appendfilename "appendonly.aof"
    #主库认证密码
    masterauth abcd_123456
    #客户端连接密码
    requirepass abcd_123456
    #指定本节点是节点一的从节点
    slaveof 192.168.173.23 6382

         节点三192.168.173.25上启动redis服务:

#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/redis.conf

    3)3台sentinel服务部署

        节点一192.168.173.23上sentinel部署如下:

#创建sentinel配置文件sentinel.conf并修改配置
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.23
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456

        节点一192.168.173.23上启动sentinel服务

#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel

        节点二192.168.173.24上sentinel部署如下:

#创建sentinel配置文件sentinel.conf并修改配置
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.24
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456

        节点二192.168.173.24上启动sentinel服务

#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel

        节点三192.168.173.25上sentinel部署如下:

#创建sentinel配置文件sentinel.conf并修改配置
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.25
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456

        节点三192.168.173.25上启动sentinel服务

#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel

    4)节点一redis服务和sentinel服务查看

redis-sentinel安装部署
 
redis-sentinel安装部署
     红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器,不需要自己指定,sentinel发现后自己会更新sentinel.conf配置文件

    5)节点二redis服务和sentinel服务查看

redis-sentinel安装部署
 
redis-sentinel安装部署
     红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器,不需要自己指定,sentinel发现后自己会更新sentinel.conf配置文件

    6)节点三redis服务和sentinel服务查看

redis-sentinel安装部署
 
redis-sentinel安装部署
     红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器,不需要自己指定,sentinel发现后自己会更新sentinel.conf配置文件

3.redis-sentinel部署方式下redis-stat启动

    3.1 redis-stat命令介绍

          安装参见博客 redis-stat安装

 
cd /home/redis/redis-stat-0.4.13/bin
./redis-stat --help
usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]
-a, --auth=PASSWORD Password
-v, --verbose Show more info
--style=STYLE Output style: unicode|ascii
--no-color Suppress ANSI color codes
--csv[=CSV_FILE] Print or save the result in CSV
--es=ELASTICSEARCH_URL Send results to ElasticSearch: [http://]HOST[:PORT][/INDEX]
--server[=PORT] Launch redis-stat web server (default port: 63790)
--daemon Daemonize redis-stat. Must be used with --server option.
--version Show version
--help Show this message

 

    3.2 redis-stat启动

linux上启动 
cd /home/redis/redis-stat-0.4.13/bin
./redis-stat 192.168.173.23:6382 192.168.173.24:6382 192.168.173.25:6382 --server --daemon -a abcd_123456

     启动后截图如下:


redis-sentinel安装部署
 
redis-sentinel安装部署

总结:

依次启动命令:

redis-server /home/redis/sentinel-cluster/conf/redis.conf

redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel

redis-cli -h 192.168.13.62 -p 26382 -a abcd_123456 info replication

=============================================================================

redis Creating Server TCP listening socket Address already in use(tomcat也已一样)

先杀掉进程

①找到该进程;

找到redis-server 的进程 (Process Status)

输入命令:

[java] view plain copy

ps -ef | grep -i redis  

[java] view plain copy

root      3086     1  0 Apr24 ?        00:00:07 ./bin/redis-server *:6379        

root      3531  3467  0 01:00 pts/0    00:00:00 grep -i redis  

进程号为 3086 即为redis服务器

②杀死该进程;

使用kill 命令

输入命令:

[java] view plain copy

kill -9 3086  

③然后重新启动redis服务器。

输入命令:

[java] view plain copy

./redis-server  

java使用的时候:

服务启动报找不到主监听

根据sentinel  这个文件来sentinel monitor redis-sentinel 192.168.13.62 6382 2

im.hs.server.redis.sentinel.masterName=redis-sentinel(名字一致)

mymaster  ----   redis-sentinel  要填写

命令:

im.hs.server.redis.sentinel1.host=192.168.13.62

im.hs.server.redis.sentinel1.port=26382

#sentinel2\u7684IP\u548C\u7AEF\u53E3  

im.hs.server.redis.sentinel2.host=192.168.13.63

im.hs.server.redis.sentinel2.port=26382

#sentinel\u7684\u9274\u6743\u5BC6\u7801  

im.hs.server.redis.sentinel.masterName=redis-sentinel

连接sentinel的redis直接操作单个redis,自动同步

redis-cli -h 192.168.13.62 -p 6382

AUTH abcd_123456

keys

flushdb

参考:

相关推荐