阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

通过Keepalived实现Redis双机

105次阅读
没有评论

共计 17463 个字符,预计需要花费 44 分钟才能阅读完成。

Redis 是一个高性能的 kv 数据库,我们用 Redis 构建了一套消息系统。

Redis 架构为 Master Slave 结构,通过 keepalived 进行状态检查,故障迁移,达到高可用的目的。

下载 keepalived

#wget http://www.keepalived.org/software/keepalived-1.2.9.tar.gz

编译安装 keepalived,编译时需要指定内核目录,否则 Use IPVS Framework 为 NO。

#./configure --prefix=/usr/local/keepalived \
--with-kernel-dir=/usr/src/kernels/3.9.10-100.fc17.x86_64 \
--enable-snmp \
--enable-sha1

配置 keepalived 信息如下图:

通过 Keepalived 实现 Redis 双机

编译与安装:

#make && make install

结果报错了,重新指定配置参数,去掉 –with-kernel-dir

配置信息如下图:

通过 Keepalived 实现 Redis 双机

在次编译安装,OK,顺利通过安装成功!

现在可以将 /usr/local/keepalived 下相应文件拷贝到系统对应目录

通过 Keepalived 实现 Redis 双机

配置 keepalived

在配置 keepalived.conf 配置文件之前先备份一份 keepalived.conf 文件后在进行配置

#cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

在 Master 机器配置 keepalived

[root@node3 etc]# more /etc/keepalived/keepalived.conf
global_defs {
   notification_email {admin@qixing318.com}
   notification_email_from keepalived@node3
   router_id node3
}

vrrp_instance mes_Redis {
    state MASTER
    interface eth0
    garp_master_delay 10
    smtp_alert
    virtual_router_id 3
    priority 100
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {192.168.172.100}
}

在 Slave 机器配置 keepalived

[root@node4 etc]# more /etc/keepalived/keepalived.conf
global_defs {
   notification_email {admin@qixing318.com}
   notification_email_from keepalived@node4
   router_id node4
}

vrrp_instance mes_Redis {
    state BACKUP
    interface eth0
    garp_master_delay 10
    smtp_alert
    virtual_router_id 3
    priority 90
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {192.168.172.100}
}

配置防火墙

打开 Master 和 Slave 机器上的防火墙

[root@node3 ~]# more /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9022 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
-A INPUT -p 112 -j ACCEPT
-A INPUT -p 255 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
[root@node3 ~]# iptables-restore /etc/sysconfig/iptables

 

Keepalived 的详细介绍 :请点这里
Keepalived 的下载地址 :请点这里

推荐阅读:

CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm

Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm

Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm

Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm

启动 Keepalived 服务

启动 Master 和 Slave 机器上的 keepalived 服务

#service keepalived start

查看 vip 是否生效并看日志信息是否有报错

[root@node3 keepalived]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:23:7d:33:2f:32 brd ff:ff:ff:ff:ff:ff
    inet 192.168.172.3/24 brd 192.168.172.255 scope global eth0
    inet 192.168.172.100/32 scope global eth0
    inet6 fe80::223:7dff:fe33:2f32/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 00:23:7d:33:2f:4c brd ff:ff:ff:ff:ff:ff

查看系统日志

[root@node3 keepalived]# tail /var/log/nodes
Nov 11 18:02:32 node3 Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
Nov 11 18:02:32 node3 Keepalived_healthcheckers: Opening file '/etc/keepalived/keepalived.conf'.
Nov 11 18:02:32 node3 Keepalived_healthcheckers: Configuration is using : 7114 Bytes
Nov 11 18:02:32 node3 Keepalived_vrrp: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Nov 11 18:02:32 node3 Keepalived_healthcheckers: Using LinkWatch kernel netlink reflector...
Nov 11 18:02:33 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Transition to MASTER STATE
Nov 11 18:02:34 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Entering MASTER STATE
Nov 11 18:02:34 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) setting protocol VIPs.
Nov 11 18:02:34 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Sending gratuitous ARPs on eth0 for 192.168.172.100
Nov 11 18:02:44 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Sending gratuitous ARPs on eth0 for 192.168.172.100

在网络中其它机器 ping vip

这时 keepalived 就实现了基本功能了,下面来配置 redis 服务。

Redis 实现 Master-Slave 架构,Master 只使用内存存储数据,对外提供读写服务,Slave 仅作为 Standby,进行数据持久化。

配置 Redis Master 并启动,Master 采用内存工作的方式。

[root@node3 etc]# more redis.master.conf 
daemonize yes
port 6379
#bind 10.25.28.18
pidfile /tmp/redis.pid
loglevel verbose 
logfile /data/logs/redis/redis_master.log 
timeout 300
databases 16
vm-enabled no
maxmemory-policy volatile-ttl
slave-serve-stale-data yes
appendonly no
appendfsync everysec
no-appendfsync-on-rewrite yes
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
activerehashing yes
[root@node3 etc]# /usr/local/redis/bin/redis-server /etc/redis/redis.master.conf

配置 Redis Slave 并启动

[root@node4 etc]# more redis.slave.conf 
daemonize yes
port 6379
#bind 10.25.28.18
slaveof 192.168.172.3 6379
pidfile /tmp/redis.pid
loglevel verbose 
logfile /data/logs/redis/redis_slave.log 
dir /data/redis
timeout 300
databases 16
vm-enabled no
maxmemory-policy volatile-ttl
rdbcompression yes
slave-serve-stale-data yes
appendonly yes
appendfsync everysec
no-appendfsync-on-rewrite yes
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entr
[root@node4 etc]# /usr/local/redis/bin/redis-server /etc/redis/redis.slave.conf

进行测试

测试数据同步

在 Master 上插入一些测试数据

[root@node3 etc]# redis-cli 
redis 127.0.0.1:6379> set foo bar
OK
redis 127.0.0.1:6379> get foo
"bar"

然后在 Slave 上获取测试数据

[root@node4 etc]# redis-cli 
redis 127.0.0.1:6379> get foo
"bar"

配置状态检查

配置 keepalived 对 Redis 进行状态检查

在 Redis Master 上配置如下,修改 keepalived.conf

[root@node3 redis]# more /etc/keepalived/keepalived.conf
global_defs {
   notification_email {admin@qixing318.com}
   notification_email_from keepalived@node3
   router_id node3
}

vrrp_script chk_redis {
    script "/etc/keepalived/redis/redis_check.sh"
    interval 1 
}

vrrp_instance mes_Redis {
    state MASTER
    interface eth0
    garp_master_delay 10
    smtp_alert
    virtual_router_id 3
    priority 100
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {192.168.172.100}
    track_script {chk_redis}
    notify_master /etc/keepalived/redis/master.sh
    notify_backup /etc/keepalived/redis/backup.sh
    notify_fault  /etc/keepalived/redis/fault.sh
    notify_stop   /etc/keepalived/redis/stop.sh
}

创建以下脚本:

[root@node3 redis]# pwd
/etc/keepalived/redis
[root@node3 redis]# ll
total 16
-rwxr-xr-x 1 root root 442 Nov 12 10:03 backup.sh
-rwxr-xr-x 1 root root 280 Nov 12 10:01 fault.sh
-rwxr-xr-x 1 root root 564 Nov 12 10:03 master.sh
-rwxr-xr-x 1 root root 149 Nov 12 09:24 redis_check.sh
[root@node3 redis]# more *
::::::::::::::
backup.sh
::::::::::::::
#!/bin/sh

KLOG=/data/logs/redis/keepalived-state.log

RLOG=/data/logs/redis/redis-state.log
echo "[backup]" >> $KLOG
date >> $KLOG
echo "----------" >> $KLOG

echo "[backup]" >> $RLOG
date >> $RLOG
echo "being slave...." >> $RLOG 2>&1
echo "run slaveof cmd ..." >> $RLOG
echo SLAVEOF 192.168.172.4 6379 | /usr/local/redis/bin/redis-cli >>$RLOG  2>&1
echo "run sync cmd ..." >> $RLOG
echo SYNC | /usr/local/redis/bin/redis-cli >> $RLOG 2>&1 
::::::::::::::
fault.sh
::::::::::::::
#!/bin/sh

KLOG=/data/logs/redis/keepalived-state.log
echo "[fault]" >> $KLOG
date >> $KLOG
echo "----------" >> $KLOG

[root@CentOSV1 redis]# more stop.sh 
#!/bin/sh

KLOG=/data/logs/redis/keepalived-state.log
echo "[stop]" >> $KLOG
date >> $KLOG
echo "----------" >> $KLOG
::::::::::::::
master.sh
::::::::::::::
#!/bin/sh

KLOG=/data/logs/redis/keepalived-state.log

RLOG=/data/logs/redis/redis-state.log
echo "[master]" >> $KLOG
date >> $KLOG
echo "----------" >> $KLOG

echo "[master]" >> $RLOG
date >> $RLOG
echo "being master...." >> $RLOG 2>&1
echo "run slaveof cmd ..." >> $RLOG
echo SLAVEOF 192.168.172.4 6379 | /usr/local/redis/bin/redis-cli >>$RLOG  2>&1
sleep 1
echo "run sync cmd ..." >> $RLOG
echo SYNC | /usr/local/redis/bin/redis-cli >>$RLOG 2>&1
sleep 1
echo "run slaveof no one cmd ..." >> $RLOG
echo SLAVEOF NO ONE | /usr/local/redis/bin/redis-cli >>$RLOG 2>&1
::::::::::::::
redis_check.sh
::::::::::::::
#!/bin/sh
alive=`/usr/local/redis/bin/redis-cli PING`
if ["$alive" == "PONG"]; then
  echo "OK"
  exit 0
fi
  #echo "$alive"
  echo "NG"
  exit 1

在 Redis Slave 机器上配置如下:

[root@node4 keepalived]# vi /etc/keepalived/keepalived.conf

global_defs {
   notification_email {admin@qixing318.com}
   notification_email_from keepalived@node4
   router_id node4
}

vrrp_script chk_redis {
    script "/etc/keepalived/redis/redis_check.sh"
    interval 1
}

vrrp_instance mes_Redis {
    state BACKUP
    interface eth0
    garp_master_delay 10
    smtp_alert
    virtual_router_id 3
    priority 90
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {192.168.172.100}
    track_script {chk_redis}
    notify_master /etc/keepalived/redis/master.sh
    notify_backup /etc/keepalived/redis/backup.sh
    notify_fault  /etc/keepalived/redis/fault.sh
    notify_stop   /etc/keepalived/redis/stop.sh
}

创建脚本如下:

[root@node4 redis]# cd /etc/keepalived/redis/
[root@node4 redis]# ls
backup.sh  fault.sh  master.sh  redis_check.sh
[root@node4 redis]# more *
::::::::::::::
backup.sh
::::::::::::::
#!/bin/sh
KLOG=/data/logs/redis/keepalived-state.log
RLOG=/data/logs/redis/redis-state.log
echo "[backup]" >> $KLOG
date >> $KLOG
echo "----------" >> $KLOG
echo "[backup]" >> $RLOG
date >> $RLOG
sleep 10
echo "being slave...." >> $RLOG 2>&1
echo "run slaveof cmd ..." >> $RLOG
echo SLAVEOF 192.168.172.3 6379 | /usr/local/redis/bin/redis-cli >>$RLOG  2>&1
echo "run sync cmd ..." >> $RLOG
echo SYNC | /usr/local/redis/bin/redis-cli >> $RLOG 2>&1 
::::::::::::::
fault.sh
::::::::::::::
#!/bin/sh
KLOG=/data/logs/redis/keepalived-state.log
echo "[fault]" >> $KLOG
date >> $KLOG
echo "----------" >> $KLOG

[root@CentosV1 redis]# more stop.sh 
#!/bin/sh
KLOG=/data/logs/redis/keepalived-state.log
echo "[stop]" >> $KLOG
date >> $KLOG
echo "----------" >> $KLOG
::::::::::::::
master.sh
::::::::::::::
#!/bin/sh

KLOG=/data/logs/redis/keepalived-state.log

RLOG=/data/logs/redis/redis-state.log
echo "[master]" >> $KLOG
date >> $KLOG
echo "----------" >> $KLOG

echo "[master]" >> $RLOG
date >> $RLOG
echo "being master...." >> $RLOG 2>&1
echo "run slaveof cmd ..." >> $RLOG
echo SLAVEOF 192.168.172.3 6379 | /usr/local/redis/bin/redis-cli >>$RLOG  2>&1
sleep 1
echo "run sync cmd ..." >> $RLOG
echo SYNC | /usr/local/redis/bin/redis-cli >>$RLOG 2>&1
sleep 1
echo "run slaveof no one cmd ..." >> $RLOG
echo SLAVEOF NO ONE | /usr/local/redis/bin/redis-cli >>$RLOG 2>&1
::::::::::::::
redis_check.sh
::::::::::::::
#!/bin/sh
alive=`/usr/local/redis/bin/redis-cli PING`
if ["$alive" == "PONG"]; then
  echo "OK"
  exit 0
fi
  #echo "$alive"
  echo "NG"
  exit 1

Redis 是一个高性能的 kv 数据库,我们用 Redis 构建了一套消息系统。

Redis 架构为 Master Slave 结构,通过 keepalived 进行状态检查,故障迁移,达到高可用的目的。

下载 keepalived

#wget http://www.keepalived.org/software/keepalived-1.2.9.tar.gz

编译安装 keepalived,编译时需要指定内核目录,否则 Use IPVS Framework 为 NO。

#./configure --prefix=/usr/local/keepalived \
--with-kernel-dir=/usr/src/kernels/3.9.10-100.fc17.x86_64 \
--enable-snmp \
--enable-sha1

配置 keepalived 信息如下图:

通过 Keepalived 实现 Redis 双机

编译与安装:

#make && make install

结果报错了,重新指定配置参数,去掉 –with-kernel-dir

配置信息如下图:

通过 Keepalived 实现 Redis 双机

在次编译安装,OK,顺利通过安装成功!

现在可以将 /usr/local/keepalived 下相应文件拷贝到系统对应目录

通过 Keepalived 实现 Redis 双机

配置 keepalived

在配置 keepalived.conf 配置文件之前先备份一份 keepalived.conf 文件后在进行配置

#cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak

在 Master 机器配置 keepalived

[root@node3 etc]# more /etc/keepalived/keepalived.conf
global_defs {
   notification_email {admin@qixing318.com}
   notification_email_from keepalived@node3
   router_id node3
}

vrrp_instance mes_Redis {
    state MASTER
    interface eth0
    garp_master_delay 10
    smtp_alert
    virtual_router_id 3
    priority 100
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {192.168.172.100}
}

在 Slave 机器配置 keepalived

[root@node4 etc]# more /etc/keepalived/keepalived.conf
global_defs {
   notification_email {admin@qixing318.com}
   notification_email_from keepalived@node4
   router_id node4
}

vrrp_instance mes_Redis {
    state BACKUP
    interface eth0
    garp_master_delay 10
    smtp_alert
    virtual_router_id 3
    priority 90
    nopreempt
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {192.168.172.100}
}

配置防火墙

打开 Master 和 Slave 机器上的防火墙

[root@node3 ~]# more /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9022 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT
-A INPUT -p 112 -j ACCEPT
-A INPUT -p 255 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
[root@node3 ~]# iptables-restore /etc/sysconfig/iptables

 

Keepalived 的详细介绍 :请点这里
Keepalived 的下载地址 :请点这里

推荐阅读:

CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm

Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm

Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm

Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm

测试关闭 Redis Master

[root@node3 redis]# redis-cli 
redis 127.0.0.1:6379> get foo
"bar"
redis 127.0.0.1:6379> shutdown

查看 keepalived backup 信息,此时 keepalvied 进入 master 状态

Nov 12 18:47:25 message4 Keepalived_vrrp: VRRP_Instance(mes_Redis) Transition to MASTER STATE
Nov 12 18:47:26 message4 Keepalived_vrrp: VRRP_Instance(mes_Redis) Entering MASTER STATE
Nov 12 18:47:26 message4 Keepalived_vrrp: VRRP_Instance(mes_Redis) setting protocol VIPs.
Nov 12 18:47:26 message4 Keepalived_vrrp: VRRP_Instance(mes_Redis) Sending gratuitous ARPs on eth0 for 192.168.172.100
Nov 12 18:47:36 message4 Keepalived_vrrp: VRRP_Instance(mes_Redis) Sending gratuitous ARPs on eth0 for 192.168.172.100

查看 Redis slave 信息,此时 redis 进入 master 状态

[root@node4 redis]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether d4:85:64:50:47:48 brd ff:ff:ff:ff:ff:ff
    inet 192.168.172.4/24 brd 192.168.172.255 scope global eth0
    inet 192.168.172.100/32 scope global eth0
    inet6 fe80::d685:64ff:fe50:4748/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether d4:85:64:50:47:4a brd ff:ff:ff:ff:ff:ff
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether d4:85:64:50:47:44 brd ff:ff:ff:ff:ff:ff
5: eth3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state

测试恢复 Redis Master,此时 keepalived 状态变为 backup,redis 变为 slave

Nov 12 10:56:23 node3 Keepalived_vrrp: VRRP_Script(chk_redis) succeeded
Nov 12 10:56:23 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Entering BACKUP STATE
role:slave
master_host:192.168.172.4
master_port:6379
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0

数据同步正常

测试关闭 Keepalived backup

[root@node4 redis]# service keepalived stop

查看 keepalived master 信息

Nov 12 11:15:49 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Transition to MASTER STATE
Nov 12 11:15:50 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Entering MASTER STATE
Nov 12 11:15:50 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) setting protocol VIPs.
Nov 12 11:15:50 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Sending gratuitous ARPs on eth0 for 192.168.172.7
Nov 12 11:16:00 node3 Keepalived_vrrp: VRRP_Instance(mes_Redis) Sending gratuitous ARPs on eth0 for 192.168.172.7

测试关闭 Redis Slave 重启数据是否丢失

[root@node4 redis]# /dragon/bin/redis/bin/redis-cli 
redis 127.0.0.1:6379> get foo
"bar"

用 redis-benchmark 测试 Redis 性能

[root@node2 ~]# redis-benchmark -h 192.168.172.7 -t set -n 1000000 -r 100000000
====== SET ======
  1000000 requests completed in 18.96 seconds
  50 parallel clients
  3 bytes payload
  keep alive: 1

99.28% <= 1 milliseconds
99.85% <= 2 milliseconds
99.96% <= 3 milliseconds
99.97% <= 8 milliseconds
99.97% <= 9 milliseconds
99.98% <= 14 milliseconds
99.98% <= 15 milliseconds
99.99% <= 17 milliseconds
99.99% <= 18 milliseconds
100.00% <= 87 milliseconds
100.00% <= 87 milliseconds
52748.18 requests per second

压力测试一段时间,master 内存数据量达到 15.9G,slave 内存数据量达到 9G,此时 slave 持久化时间消耗很大,查询时延很大。

master 的 info

redis 127.0.0.1:6379> info
redis_version:2.4.14
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.6
process_id:24839
uptime_in_seconds:8348
uptime_in_days:0
lru_clock:2086437
used_cpu_sys:3687.96
used_cpu_user:1733.84
used_cpu_sys_children:0.01
used_cpu_user_children:0.00
connected_clients:1
connected_slaves:1
client_longest_output_list:495810
client_biggest_input_buf:0
blocked_clients:0
used_memory:17087636096
used_memory_human:15.91G
used_memory_rss:16042332160
used_memory_peak:17119264664
used_memory_peak_human:15.94G
mem_fragmentation_ratio:0.94
mem_allocator:jemalloc-2.2.5
loading:0
aof_enabled:0
changes_since_last_save:300459493
bgsave_in_progress:0
last_save_time:1342063376
bgrewriteaof_in_progress:0
total_connections_received:8839
total_commands_processed:301293452
expired_keys:0
evicted_keys:0
keyspace_hits:425469
keyspace_misses:1
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:1616
vm_enabled:0
role:master
slave0:192.168.172.4,38292,online
db0:keys=94571396,expires=0

slave 的 info

redis 127.0.0.1:6379> info
redis_version:2.4.14
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.6
process_id:21820
uptime_in_seconds:6894
uptime_in_days:0
lru_clock:2089328
used_cpu_sys:695.35
used_cpu_user:1090.20
used_cpu_sys_children:24.67
used_cpu_user_children:188.16
connected_clients:5
connected_slaves:0
client_longest_output_list:0
client_biggest_input_buf:4
blocked_clients:0
used_memory:9740498160
used_memory_human:9.07G
used_memory_rss:8099332096
used_memory_peak:9740500440
used_memory_peak_human:9.07G
mem_fragmentation_ratio:0.83
mem_allocator:jemalloc-2.2.5
loading:0
aof_enabled:1
changes_since_last_save:160162637
bgsave_in_progress:0
last_save_time:1342094071
bgrewriteaof_in_progress:1
total_connections_received:6799
total_commands_processed:226063438
expired_keys:0
evicted_keys:0
keyspace_hits:13
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:142125
vm_enabled:0
role:slave
aof_current_size:7735856830
aof_base_size:3791924084
aof_pending_rewrite:0
aof_buffer_length:16400
aof_pending_bio_fsync:0
master_host:192.168.172.3
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
db0:keys=88586614,expires=0
(1.76s)
redis 127.0.0.1:6379> get foo
"bar"
(2.33s)

参考 http://www.linuxidc.com/Linux/2014-02/96083.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计17463字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中