六:主实例写入测试数据,该脚本原则上会写入25条测试数据,不过由于未优化redis默认并发数,会导致一些写入请求失败,最终功写入231839条测 试数据,占内存总大小为25M左右,写入过程中可以观察主从实例的持久化文件变化情况,主实例的持久化文件维持在30k,从实例的则不断的扩展!
[root@server11 ~]# cat test.sh
#!/bin/bash
REDISCLI="/usr/local/redis2/bin/redis-cli -h 192.168.1.120 -a 123 -n 1 SET"
ID=1
while(($ID<50001))
do
INSTANCE_NAME="i-2-$ID-VM"
UUID=`cat /proc/sys/kernel/random/uuid`
PRIVATE_IP_ADDRESS=10.`echo "$RANDOM % 255 + 1" | bc`.`echo "$RANDOM % 255 + 1" | bc`.`echo
"$RANDOM % 255 + 1" | bc`\
CREATED=`date "+%Y-%m-%d %H:%M:%S"`
$REDISCLI vm_instance:$ID:instance_name "$INSTANCE_NAME"
$REDISCLI vm_instance:$ID:uuid "$UUID"
$REDISCLI vm_instance:$ID:private_ip_address "$PRIVATE_IP_ADDRESS"
$REDISCLI vm_instance:$ID:created "$CREATED"
$REDISCLI vm_instance:$INSTANCE_NAME:id "$ID"
ID=$(($ID+1))
done
[root@server11 ~]# sh test.sh
[root@server11 redis2]# /usr/local/redis2/bin/redis-cli -h 192.168.1.120 -a 123 info |egrep
'used_memory_peak_human|db1:keys'
used_memory_peak_human:24.98M
db1:keys=231839,expires=0
七:模拟主实例故障,观察日志输出,验证从实例是否能成功接管VIP,同时将实例变成读写模式
[root@server11 ~]# killall -9 redis-server
[root@server11 ~]# ip a |grep 192
inet 192.168.1.112/24 brd 192.168.1.255 scope global eth0
[root@server11 ~]# ps -ef |grep redis
root 15886 6458 0 09:49 pts/0 00:00:00 grep redis
[root@server11 ~]# ps -ef |grep keep
root 16029 6458 0 09:49 pts/0 00:00:00 grep keep
[root@server12 ~]# tail -f /usr/local/redis2/var/keepalived-redis-state.log
[master]
Wed Dec 12 09:48:52 CST 2012
Being master....
Run SLAVEOF cmd ...
OK Already connected to specified master
Run SLAVEOF NO ONE cmd ...
OK
[root@server12 ~]# tail -f /var/log/messages
Dec 12 09:48:51 server12 Keepalived_vrrp[3108]: VRRP_Instance(VI_1{) Transition to MASTER STATE
Dec 12 09:48:52 server12 Keepalived_vrrp[3108]: VRRP_Instance(VI_1{) Entering MASTER STATE
Dec 12 09:48:52 server12 Keepalived_vrrp[3108]: VRRP_Instance(VI_1{) setting protocol VIPs.
Dec 12 09:48:52 server12 Keepalived_vrrp[3108]: VRRP_Instance(VI_1{) Sending gratuitous ARPs on eth0 for 192.168.1.120
Dec 12 09:48:52 server12 Keepalived_vrrp[3108]: Netlink reflector reports IP 192.168.1.120 added
Dec 12 09:48:52 server12 avahi-daemon[2921]: Registering new address record for 192.168.1.120 on eth0.
Dec 12 09:48:52 server12 Keepalived_healthcheckers[3106]: Netlink reflector reports IP 192.168.1.120 added
Dec 12 09:48:57 server12 Keepalived_vrrp[3108]: VRRP_Instance(VI_1{) Sending gratuitous ARPs on eth0 for 192.168.1.120
[root@server12 ~]# ip a |grep 192
inet 192.168.1.113/24 brd 192.168.1.255 scope global eth0
inet 192.168.1.120/32 scope global eth0
[root@server12 ~]# /usr/local/redis2/bin/redis-cli -h 192.168.1.120 -a 123 info |grep -A 3 'Replication'
# Replication
role:master
connected_slaves:0