---
title: "redis-sentinel安装部署"
author: "zilongzilong"
date: "2016-12-03T23:32:30Z"
tags: []
categories: ["开源软件"]
slug: "redis-sentinel"
draft: false
lastmod: "2017-12-05T15:36:11Z"
id: 2342693
url: "https://aperise.iteye.com/blog/2342693"
---

redis 学习问题总结

### [http://aperise.iteye.com/blog/2310639](/blog/2310639)

ehcache memcached redis 缓存技术总结

### [http://aperise.iteye.com/blog/2296219](/blog/2296219)

redis-stat 离线安装

### [http://aperise.iteye.com/blog/2310254](/blog/2310254)

redis  cluster 非ruby方式启动

### [http://aperise.iteye.com/blog/2310254](/admin/blogs/2315810 "http://aperise.iteye.com/admin/blogs/2315810")

redis-sentinel安装部署

### [http://aperise.iteye.com/blog/2342693](/blog/2342693)

spring-data-redis使用

### [http://aperise.iteye.com/blog/2342615](/blog/2342615)

redis客户端redisson实战

### [http://blog.csdn.net/zilong\_zilong/article/details/78252037](http://blog.csdn.net/zilong_zilong/article/details/78252037)

redisson-2.10.4源代码分析

### [http://blog.csdn.net/zilong\_zilong/article/details/78609423](http://blog.csdn.net/zilong_zilong/article/details/78609423)

tcmalloc jemalloc libc选择

### [http://blog.csdn.net/u010994304/article/details/49906819](http://blog.csdn.net/u010994304/article/details/49906819)

# 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下生成如下文件：

![](http://dl2.iteye.com/upload/attachment/0121/7111/59174462-ef68-379d-98dd-8c5bd291d27b.png)

 

# 2.redis-sentinel部署

## 1）部署结构图如下

![](http://dl2.iteye.com/upload/attachment/0121/7115/7355f926-c812-3e61-8aed-6d6c7567287b.png)

## 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服务查看

![](http://dl2.iteye.com/upload/attachment/0121/7134/f1a70b07-422a-33a9-abd8-dea3c0b01d20.png)  
   
![](http://dl2.iteye.com/upload/attachment/0121/7140/3ea9f202-b6a3-3453-b909-313265b96ea6.png)  
     **红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器，不需要自己指定，sentinel发现后自己会更新sentinel.conf配置文件**

 

## 5）节点二redis服务和sentinel服务查看

![](http://dl2.iteye.com/upload/attachment/0121/7136/57be7898-14d8-33d4-9ff2-105b50872039.png)  
   
![](http://dl2.iteye.com/upload/attachment/0121/7142/9d0614a4-5fca-39cc-84b9-0f039bbf57d7.png)  
     **红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器，不需要自己指定，sentinel发现后自己会更新sentinel.conf配置文件**

 

## 6）节点三redis服务和sentinel服务查看

![](http://dl2.iteye.com/upload/attachment/0121/7138/e27644cc-09b1-31dc-abd7-f5d0de360af1.png)  
   
![](http://dl2.iteye.com/upload/attachment/0121/7144/1568bbe1-a54f-3c09-bab9-b3c40159d641.png)  
     **红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器，不需要自己指定，sentinel发现后自己会更新sentinel.conf配置文件**

 

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

    **3.1 redis-stat命令介绍**

          **安装参见博客 [redis-stat安装](/blog/2310254 "http://aperise.iteye.com/blog/2310254")**

 

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

     **启动后截图如下：**

**![](http://dl2.iteye.com/upload/attachment/0121/8517/31bdf68e-29a1-399f-866e-e3a829551c99.png)**  
   
**![](http://dl2.iteye.com/upload/attachment/0121/8519/a0155d97-c756-32a5-9666-f8305fbcf42b.png)**