在这里我们搭建的是一个1主3从的redis+3个哨兵集群的环境,由于是在一台物理机上,所有我们用端口区分。

物理机IP:192.168.0.12

主节点master端口:6301

从节点slave1端口:6315

从节点slave2端口:6316

从节点slave3端口:6317

哨兵sentinel1端口:26301

哨兵sentinel2端口:26302

哨兵sentinel3端口:26303

一、下载安装

$ wget http://download.redis.io/releases/redis-3.0.0.tar.gz

$ tar xzf redis-3.0.0.tar.gz

$ cd redis-3.0.0

$ make

二、复制文件

cp redis-benchmark redis-cli redis-server redis-sentinel /usr/bin/ #这个倒是很有用,这样就不用再执行时加上./了,而且可以在任何地方执行

三、设置内存分配策略(可选,根据服务器的实际情况进行设置)

/proc/sys/vm/overcommit_memory

可选值:0、1、2。

0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。

1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。

2, 表示内核允许分配超过所有物理内存和交换空间总和的内存

四、开启redis端口,修改防火墙配置文件

    vi /etc/sysconfig/iptables 

加入端口配置

    -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT 

重新加载规则

    service iptables restart 

五、配置redis.config文件

1、主节点master的配置文件redis_master_6301.config:

# Redis configuration file example

################################## INCLUDES ###################################

# include /path/to/local.conf

# include /path/to/other.conf

################################ GENERAL  #####################################

daemonize yes

pidfile ./run/redis_slaver1_6315.pid

port 6301

tcp-backlog 511

# bind 192.168.1.100 10.0.0.1

# bind 127.0.0.1

# unixsocket /tmp/redis.sock

# unixsocketperm 700

timeout 0

tcp-keepalive 0

loglevel notice

logfile
"./run/logs/log_master_6301.log"

databases 16

################################ SNAPSHOTTING  ################################

save ""

# save 900 1

# save 300 10

# save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum no

dbfilename dump_6301.rdb

dir ./run/data

################################# REPLICATION #################################

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

# repl-ping-slave-period 10

# repl-timeout 60

repl-disable-tcp-nodelay no

# repl-backlog-size 1mb

# repl-backlog-ttl 3600

slave-priority 100

# min-slaves-to-write 3

# min-slaves-max-lag 10

################################## SECURITY ###################################

# rename-command CONFIG ""

################################### LIMITS ####################################

# maxclients 10000

# maxmemory <bytes>

# maxmemory-policy noeviction

# maxmemory-samples 5

############################## APPEND ONLY MODE ###############################

appendonly no

appendfilename "appendonly_6301.aof"

appendfsync no

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

################################ LUA SCRIPTING  ###############################

lua-time-limit 5000

################################ REDIS CLUSTER  ###############################

# cluster-enabled yes

# cluster-config-file nodes-6379.conf

# cluster-node-timeout 15000

# cluster-slave-validity-factor 10

# cluster-migration-barrier 1

# cluster-require-full-coverage yes

################################## SLOW LOG ###################################

slowlog-log-slower-than 10000

slowlog-max-len 128

################################ LATENCY MONITOR ##############################

latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################

notify-keyspace-events ""

############################### ADVANCED CONFIG ###############################

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

2、从节点slave1的配置文件redis_slave_6315.config:

# Redis configuration file example

################################## INCLUDES ###################################

# include /path/to/local.conf

# include /path/to/other.conf

################################ GENERAL  #####################################

daemonize yes

pidfile ./run/redis_slaver1_6315.pid

port 6315

tcp-backlog 511

# bind 192.168.1.100 10.0.0.1

# bind 127.0.0.1

# unixsocket /tmp/redis.sock

# unixsocketperm 700

timeout 0

tcp-keepalive 0

loglevel notice

logfile "./run/logs/log_slaver1_6315.log"

databases 16

################################ SNAPSHOTTING  ################################

save ""

# save 900 1

# save 300 10

# save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum no

dbfilename dump_6315.rdb

dir ./run/data

################################# REPLICATION #################################

slaveof 192.168.0.12 6301

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

# repl-ping-slave-period 10

# repl-timeout 60

repl-disable-tcp-nodelay no

# repl-backlog-size 1mb

# repl-backlog-ttl 3600

slave-priority 80

# min-slaves-to-write 3

# min-slaves-max-lag 10

################################## SECURITY ###################################

# rename-command CONFIG ""

################################### LIMITS ####################################

# maxclients 10000

# maxmemory <bytes>

# maxmemory-policy noeviction

# maxmemory-samples 5

############################## APPEND ONLY MODE ###############################

appendonly no

appendfilename "appendonly_6315.aof"

appendfsync no

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

################################ LUA SCRIPTING  ###############################

lua-time-limit 5000

################################ REDIS CLUSTER  ###############################

# cluster-enabled yes

# cluster-config-file nodes-6379.conf

# cluster-node-timeout 15000

# cluster-slave-validity-factor 10

# cluster-migration-barrier 1

# cluster-require-full-coverage yes

################################## SLOW LOG ###################################

slowlog-log-slower-than 10000

slowlog-max-len 128

################################ LATENCY MONITOR ##############################

latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################

notify-keyspace-events ""

############################### ADVANCED CONFIG ###############################

hash-max-ziplist-entries 512

hash-max-ziplist-value 64

list-max-ziplist-entries 512

list-max-ziplist-value 64

set-max-intset-entries 512

zset-max-ziplist-entries 128

zset-max-ziplist-value 64

hll-sparse-max-bytes 3000

activerehashing yes

client-output-buffer-limit normal 0 0 0

client-output-buffer-limit slave 256mb 64mb 60

client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

3、从节点slave2的配置文件redis_slave_6316.config:

与上面slave1配置文件需要修改的地方

pidfile ./run/redis_slaver1_6316.pid

port 6316

logfile "./run/logs/log_slaver1_6316.log"

dbfilename dump_6316.rdb

appendfilename "appendonly_6316.aof"

4、从节点slave3的配置文件redis_slave_6317.config:

与上面slave1配置文件需要修改的地方

pidfile ./run/redis_slaver1_6317.pid

port 6317

logfile "./run/logs/log_slaver1_6317.log"

dbfilename dump_6317.rdb

appendfilename "appendonly_6317.aof"

5、哨兵sentinel1的配置文件sentinel_26301.config:

# Example sentinel.conf

port 26301

# sentinel announce-ip 1.2.3.4

dir ./run/tmp

sentinel monitor master1 192.168.0.12 6301 2

# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd

# sentinel down-after-milliseconds <master-name> <milliseconds>

sentinel down-after-milliseconds master1 30000

sentinel parallel-syncs master1 1

sentinel failover-timeout master1 180000

# sentinel notification-script mymaster /var/redis/notify.sh

# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh

# sentinel can-failover master1 yes

logfile "/redis-3.0.0/run/logs/sentinellog_m1_26301.log"

6、哨兵sentinel2的配置文件sentinel_26302.config:

# Example sentinel.conf

port 26302

# sentinel announce-ip 1.2.3.4

dir ./run/tmp

sentinel monitor master1 192.168.0.12 6301 2

# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd

# sentinel down-after-milliseconds <master-name> <milliseconds>

sentinel down-after-milliseconds master1 30000

sentinel parallel-syncs master1 1

sentinel failover-timeout master1 180000

# sentinel notification-script mymaster /var/redis/notify.sh

# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh

# sentinel can-failover master1 yes

logfile "/redis-3.0.0/run/logs/sentinellog_m1_26302.log"

7、哨兵sentinel3的配置文件sentinel_26303.config:

# Example sentinel.conf

port 26303

# sentinel announce-ip 1.2.3.4

dir ./run/tmp

sentinel monitor master1 192.168.0.12 6301 2

# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd

# sentinel down-after-milliseconds <master-name> <milliseconds>

sentinel down-after-milliseconds master1 30000

sentinel parallel-syncs master1 1

sentinel failover-timeout master1 180000

# sentinel notification-script mymaster /var/redis/notify.sh

# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh

# sentinel can-failover master1 yes

logfile "/redis-3.0.0/run/logs/sentinellog_m1_26303.log"

六、启动redis和哨兵服务

注意:第一次要先启动redis主服务、从服务,然后才能启动哨兵服务

1、进入redis安装目录的根目录

2、启动redis主节点

[root@localhost redis-3.0.0]# redis-server redis_master_6301.config &

3、启动redis从节点

[root@localhost redis-3.0.0]# redis-server redis_slave_6315.config &

[root@localhost redis-3.0.0]# redis-server redis_slave_6316.config &

[root@localhost redis-3.0.0]# redis-server redis_slave_6317.config &

4、启动哨兵

[root@localhost redis-3.0.0]# redis-sentinel sentinel_26301.config &

[root@localhost redis-3.0.0]# redis-sentinel sentinel_26302.config &

[root@localhost redis-3.0.0]# redis-sentinel sentinel_26303.config &



到目前为止整个redis+sentinel的安装搭建环境就算完成



七、一些常用命令

进入redis的安装目录

启动redis-server:

./redis-server redis_6305.conf &

启动redis-sentinel 

./redis-sentinel sentinel_6301.config

./redis-server sentinel_6316.conf --sentinel &

查看某个端口信息:

./redis-cli -p 6301 info

./redis-cli -p 6301 info Replication

./redis-cli -p 6301 info Sentinel

查看某个主机上的信息redis信息

./redis-cli -h 10.16.41.52 -p 6316 info

./redis-cli -h 10.16.41.52 -p 6316 info Replication

./redis-cli -h 10.16.41.52 -p 6316 info Sentinel

关闭本机redis服务

./redis-cli -p 6379 shutdown

关闭远程主机redis服务

./redis-cli -h 192.168.9.18 -p 6379 shutdown

客户端连接本机

./redis-cli -p 6301

客户端连接远程机

./redis-cli -h 10.16.41.53 -p 6301

切换连接

ssh app@10.16.41.52



使用命令关闭RDB持久化:在客户端执行127.0.0.1:6316> config set save ""

Redis+Sentinel安装与配置的更多相关文章

  1. Redis、Redis+sentinel安装(Ubuntu 14.04下Redis安装及简单测试)

    Ubuntu下Redis安装两种安装方式: 1.apt-get方式 步骤: 以root权限登录,切换到/usr目录下. 接下来输入命令,apt-get install redis-server,如图: ...

  2. [Linux]Linux下redis的安装及配置.

    在上一篇[Linux] linux下安装配置 zookeeper/redis/solr/tomcat/IK分词器 详细实例. 我们已经将redis所需tar包拷贝到了linux下的root 根目录下, ...

  3. Redis的安装、配置 --转载

    原文地址:http://blog.sina.com.cn/s/blog_505bf9af0101ehhp.html redis的安装.配置 安装步骤如下:下载redis安装包:$ cd /opt/ap ...

  4. Redis:安装、配置、操作和简单代码实例(C语言Client端)

    Redis:安装.配置.操作和简单代码实例(C语言Client端) - hj19870806的专栏 - 博客频道 - CSDN.NET Redis:安装.配置.操作和简单代码实例(C语言Client端 ...

  5. mac与centos下redis的安装与配置

    前言 最近在用redis,下面简单写一下mac和centos下redis的安装与配置方法. 安装 mac下面 安装命令:brew intall redis 运行命令:brew services sta ...

  6. 最新版redis的安装及配置 linux系统

    1.redis下载 官网地址:https://redis.io/download 百度云地址:链接:http://pan.baidu.com/s/1c1Hu2gK 密码:h17z 2.解压 [root ...

  7. c#连接Redis Redis的安装与配置

    Redis是一个不错的缓存数据库,读取数据速度效率都很不错.今天大家共同研究下redis的用法.结合网上的资料和自己的摸索,先来看下安装与配置把. 咱们主要看在WINDOWS上怎样使用REDIS数据库 ...

  8. centos6.8下redis的安装和配置

    centos6.8下redis的安装和配置 下载.安装 在redis官网可以获取到最新版本的redis 进入/usr/local/目录,执行如下命令 wget http://download.redi ...

  9. linux下redis的安装及配置启动

    linux下redis的安装及配置启动 标签: redisnosql 2014-10-24 14:04 19732人阅读 评论(0) 收藏 举报  分类: 数据与性能(41)  wget http:/ ...

随机推荐

  1. quartz定时任务表达式案例

    表示式 说明 "0 0 12 * * ? " 每天12点运行 "0 15 10 ? * *" 每天10:15运行 "0 15 10 * * ?&quo ...

  2. openstack部署glance

    一.建立glance数据库并且给权限设置第三方登录 mysql -uroot -p0330 CREATE DATABASE glance; GRANT ALL PRIVILEGES ON glance ...

  3. express服务端

    1. 使用 Node.js + Express 开发服务端 2. 使用 Node.js + Express+MySQL 实现简单的增删改查 3. 初识NodeJS服务端开发(Express+MySQL ...

  4. SQL Server 中 ROWLOCK 行级锁

    一.ROWLOCK的使用 1.ROWLOCK行级锁确保,在用户取得被更新的行,到该行进行更新,这段时间内不被其它用户所修改.因而行级锁即可保证数据的一致性,又能提高数据操作的并发性. 2.ROWLOC ...

  5. SQL易错锦集

    1.LIMIT 语句 分页查询是最常用的场景之一,但也通常也是最容易出问题的地方.比如对于下面简单的语句,一般 DBA 想到的办法是在 type, name, create_time 字段上加组合索引 ...

  6. JAVA语言课堂测试01源代码(学生成绩管理系统)

    package 考试; /*信1807-8 * 20183798 * 向瑜 */ import java.util.Scanner; //ScoreInformation 类 class ScoreI ...

  7. 【并行计算-CUDA开发】CUDA线程、线程块、线程束、流多处理器、流处理器、网格概念的深入理解

    GPU的硬件结构,也不是具体的硬件结构,就是与CUDA相关的几个概念:thread,block,grid,warp,sp,sm. sp: 最基本的处理单元,streaming processor  最 ...

  8. 【科普杂谈】IP地址子网划分

    1.学习子网前的准备知识-什么是数制 现场讲解版 二进制和十进制的关系   二进制和十六进制的关系  16进制的每个位是2进制的4位 F=1111  二进制转16进制,按上面4位一组分开转 2.IP地 ...

  9. Linux三剑客之grep常用参数详细总结

    三剑客grep总结 grep  : Linux三剑客老三      过滤需要的内容 参数: grep一般常用参数: -a :在二进制文件中,以文本文件的方式搜索数据 -c :计算找到 ’ 搜索字符串 ...

  10. krpano下全屏后弹窗失效问题解决方法

    原因 krpano 自身的全屏仅全屏自身,以外的html效果将无法显示 解决方法 把全屏按钮换成浏览器自身的全屏效果 解决步骤 vtourskin.xml <layer name="n ...