首页 > 代码库 > redis 集群部署--实例

redis 集群部署--实例

1 安装环境

jdk1.8.0  redis 3.0.6

双机主从,192.168.1.5主   192.168.1.6从

做redis缓存服务器 用sentinel监控redis实现HA


2 安装配置

首先安装jdk环境(略,请自行调整环境)

分别安装redis-master和redis-slave

yum install -y redis


配置redis-master 192.168.1.5

vim /etc/redis.conf

daemonize yes

pidfile /var/run/redis/redis.pid

port 6379

bind 192.168.1.5

logfile /var/log/redis/redis.log

maxmemory 2165625        #内存2G

maxmemory-policy volatile-lru   #内存紧张时用lru算法清除数据

appendonly yes          #开启AOF持久化

appendfilename appendonly.aof  

appendfsync everysec       #每秒钟写一次磁盘

no-appendfsync-on-rewrite yes   #日志重写,不追加命令

auto-aof-rewrite-percentage 100  #AOF超过一定大小,自动启动新重写

auto-aof-rewrite-min-size 64mb  #启动新重写的最小值


vim /etc/redis-sentinel.conf

port 26379

sentinel monitor mymaster 192.168.1.5 6379 1  #指定要监控的机器

sentinel down-after-milliseconds mymaster 5000 #判断down机时间5秒

sentinel failover-timeout mymaster 60000    #故障转移时间1分钟

sentinel parallel-syncs mymaster 1       #通过slave确认宕机


配置redis-slave 192.168.1.6

vim /etc/redis.conf

daemonize yes

pidfile /var/run/redis/redis.pid

port 6379

bind 192.168.1.6

slaveof 192.168.1.5 6379

loglevel notice

logfile /var/log/redis/redis.log

maxmemory 2165625

maxmemory-policy volatile-lru

appendonly yes

appendfilename appendonly.aof

appendfsync everysec

no-appendfsync-on-rewrite yes

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb


vim /etc/redis-sentinel.conf

port 26379

sentinel monitor mymaster 192.168.1.5 6379 1

sentinel down-after-milliseconds mymaster 5000

sentinel failover-timeout mymaster 60000

sentinel parallel-syncs mymaster 1


启动redis

/usr/bin/redis-server /etc/redis.conf          先主后从

接着启动sentinel

/usr/bin/redis-sentinel /etc/redis-sentinel.conf   先主后从


测试redis集群

登录redis-master192.168.1.5

/usr/bin/redis-cli -h 192.168.1.5 -p 6379       进入客户端命令

192.168.1.5:6379 >set test 123456

ok

192.168.1.5:6379 >get test

"123456"

登上slave做同样测试


停止redis服务(注意先后顺序)

先停止sentinel服务 

ps -ef |grep sentinel

kill -9 pid

接着停止slave

192.168.1.6:6379 >shutdown

最后停止master

192.168.1.5:6379 >shutdown


完成 




本文出自 “实用Linux知识技能分享” 博客,请务必保留此出处http://superleedo.blog.51cto.com/12164670/1891845

redis 集群部署--实例