redis集群管理,超时链接自动关闭
*/5 * * * * /home/cf/redismng.sh
#!/bin/bash
st='192.168.100.101:2000
192.168.100.101:2001
192.168.100.101:2002
192.168.100.102:2003
192.168.100.102:2004
192.168.100.102:2005
192.168.100.103:2006
192.168.100.103:2007
192.168.100.103:2008'
hostport='192.168.100.101,192.168.100.102,192.168.100.103'
REDIS_HOME=/home/software/redis-3.2.4/src
sd=` echo $st | awk '{print }' `
#declare -i overtime= 10 ;
declare -i overtime=120;
echo $sd
for addrport in $sd
do
addr=`echo $addrport |cut -d ':' -f 1`
port=`echo $addrport | cut -d ':' -f 2`
echo "============"
echo $addr
echo $port
echo "============"
hostlist=`/home/software/redis-3.2.4/src/redis-cli -h $addr -p $port client list | awk '{print NR "_" $1 "_" $2 "_" $6 "_,"}'`
echo $hostlist;
array=(${hostlist//,/ })
for info in ${hostlist[*]}
do
echo "******"
echo $info
echo "******"
if [[ "$info"x != ""x ]]
then
client=`echo $info | cut -d _ -f 3 | cut -d = -f 2`
chost=`echo $info | cut -d _ -f 3 | cut -d = -f 2 | cut -d : -f 1`
cport=`echo $info | cut -d _ -f 3 | cut -d = -f 2 | cut -d : -f 2`
cidles=`echo $info | cut -d _ -f 4| cut -d = -f 2`
echo $client
echo $chost
echo $cport
echo $cidles
if [[ $(echo $hostport | grep $chost) == "" ]]
then
if [[ $(expr $cidles) -gt $overtime ]]
then
$REDIS_HOME/redis-cli -h $addr -p $port client kill $client
fi
fi
fi
done
done