赞
踩
简介
环境
wget http://download.redis.io/releases/redis-4.0.9.tar.gz -O /redis-4.0.9.tar.gz
cd /
进入资源目录
tar xzf redis-4.0.9.tar.gz
解压缩安装包
cd /redis-4.0.9/
进入安装包所在目录
make
编译安装
mkdir /etc/redis
cp /redis-4.0.9/redis.conf /etc/redis/6379.conf
cp /redis-4.0.9/utils/redis_init_script /etc/init.d/redis
vim /etc/init.d/redis 6 # chkconfig: 2345 10 90 7 # description: Start and Stop redis 12 #EXEC=/usr/local/bin/redis-server 13 EXEC=/redis-4.0.9/src/redis-server 14 #CLIEXEC=/usr/local/bin/redis-cli 15 CLIEXEC=/redis-4.0.9/src/redis-cli 23 if [ -f $PIDFILE ] 24 then 25 echo "$PIDFILE exists, process is already running or crashed" 26 else 27 echo "Starting Redis server..." 28 #$EXEC $CONF 29 $EXEC $CONF & 30 31 fi
chmod +x /etc/init.d/redis
chkconfig --add redis
chkconfig --list
redis 0:关 1:关 2:开 3:开 4:开 5:开 6:关
chkconfig redis on
systemctl daemon-reload
systemctl start redis
master1 192.168.145.11
vim /etc/redis/6379.conf
bind 127.0.0.1
bind 0.0.0.0
protected-mode yes
protected-mode no
systemctl restart redis
重启
slave1 192.168.145.12
vim /etc/redis/6379.conf
slaveof 192.168.145.11 6379
bind 0.0.0.0
protected-mode no
systemctl restart redis
vim /etc/redis/6379.conf
slaveof 192.168.145.11 6379
bind 0.0.0.0
protected-mode no
systemctl restart redis
测试
服务状态
/redis-4.0.9/src/redis-cli
登录redis客户端
info replication
查看复制状态
master
[root@master ~]# /redis-4.0.9/src/redis-cli 127.0.0.1:6379> info replication # Replication role:master connected_slaves:2 slave0:ip=192.168.145.12,port=6379,state=online,offset=280,lag=1 slave1:ip=192.168.145.13,port=6379,state=online,offset=280,lag=1 master_replid:54a4066c4ca51148adb6e273e37265aa1401a941 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:280 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:280 - slave [root@slave~]# /redis-4.0.9/src/redis-cli 127.0.0.1:6379> info replication # Replication role:slave master_host:192.168.145.11 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_repl_offset:182 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:54a4066c4ca51148adb6e273e37265aa1401a941 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:182 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:15 repl_backlog_histlen:168 127.0.0.1:6379> 127.0.0.1:6379> get abc "hahahahah"
简介
sentinel介绍
作用
Redis Sentinel Redis-Sentinel是Redis官方推荐的高可用性(HA)解决方案。实际上这意味着你可以使用Sentinel模式创建一个可以不用人为干预而应对各种故障的Redis部署。
作用:
1):Master状态检测
2):如果Master异常,则会进行Master-Slave切换,将其中一个Slave作为Master,将之前的Master作为Slave
3):Master-Slave切换后,master_redis.conf、slave_redis.conf和sentinel.conf的内容都会发生改变,即master_redis.conf中会多一行slaveof的配置,sentinel.conf的监控目标会随之调换
工作方式
主观下线和客观下线
环境
步骤
1.每台机器上修改redis主配置文件设置:bind 0.0.0.0(略)
2.每台机器上修改sentinel配置文件:添加如下配置
vim /redis-4.0.9/sentinel.conf
sentinel monitor mymaster 192.168.145.11 6379 2
sentinel down-after-milliseconds mymaster 3000
sentinel failover-timeout mymaster 10000
protected-mode no
cd /redis-4.0.9
./src/redis-sentinel sentinel.conf
4.关闭主服务器,观察从服务器改变状态
systemctl stop redis
观察三台服务器返回信息。会显示新主人信息。
36596:X 13 Aug 08:11:01.260 # -odown master mymaster 192.168.145.11 6379
36596:X 13 Aug 08:11:01.260 # +failover-end master mymaster 192.168.145.11 6379
36596:X 13 Aug 08:11:01.260 # +switch-master mymaster 192.168.145.11 6379 192.168.145.13 6379
36596:X 13 Aug 08:11:01.260 * +slave slave 192.168.145.12:6379 192.168.145.12 6379 @ mymaster 192.168.145.13 6379
36596:X 13 Aug 08:11:01.260 * +slave slave 192.168.145.11:6379 192.168.145.11 6379 @ mymaster 192.168.145.13 6379
36596:X 13 Aug 08:11:04.275 # +sdown slave 192.168.145.11:6379 192.168.145.11 6379 @ mymaster 192.168.145.13 6379
新主服务器上观察状态转换
/redis-4.0.9/src/redis-cli
info replication
观察状态由主转从
redis相关工具(了解)
find /redis-4.0.9/src -type f -executable
./redis-benchmark //用于进行redis性能测试的工具
./redis-check-dump //用于修复出问题的dump.rdb文件
./redis-cli //redis的客户端
./redis-server //redis的服务端
./redis-check-aof //用于修复出问题的AOF文件
./redis-sentinel //用于集群管理
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。