监控redis集群脚本

UserParameter=Redis.clusterstatus[*],/etc/zabbix/zabbix_agentd.d/redis_status.sh $1
UserParameter=Redis.singleclusterstatus[*],sh /app/zabbixsh/redis_single_cluster.sh $1 $2 $3
#!/bin/bash
shdir=$(cd `dirname $0`; pwd)
agent_start_user=$1
zabbix_agent_dir=$2
agent_group=$3
zabbix_sh_dir=$4
#echo $zabbix_agent_dir
if [  ! -d "$zabbix_sh_dir" ];then
   mkdir -p $zabbix_sh_dir
fi

cat $zabbix_agent_dir/conf/zabbix_agentd.conf | grep "^Include=/usr/local/zabbix/conf/zabbix_agentd/*.conf" > /dev/null
        if [ $? -ne 0 ]
         then
            cat $zabbix_agent_dir/conf/zabbix_agentd.conf | grep "^Include=.*" > /dev/null
                if [ $? -eq 0 ]
                 then
                  
                  sed -i "/^Include=.*/d" $zabbix_agent_dir/conf/zabbix_agentd.conf
                  
                  echo "Include= $zabbix_agent_dir/conf/zabbix_agentd/*.conf">> $zabbix_agent_dir/conf/zabbix_agentd.conf
                  else 
                  echo "Include= $zabbix_agent_dir/conf/zabbix_agentd/*.conf">> $zabbix_agent_dir/conf/zabbix_agentd.conf
                 fi
fi
chown -R $agent_start_user:$agent_group $zabbix_agent_dir $zabbix_sh_dir
#!/bin/bash
REDISCLI='/usr/local/redis_cluster/redis_16380/redis-cli'
ip=$2
PORT=$3
conn_port=$3
if [ $PORT -eq 16385 ]; then
conn_port=16380
else
conn_port=$(($PORT+1))

fi
PASS='1'
redis_cluster()
{    
     ps -ef|grep redis|grep $PORT|grep -v redis_custom.sh>/dev/null
     result=$?     
     if [ $result -eq 0 ];then       
        node=`$REDISCLI -c -h $ip -p $PORT -a $PASS cluster nodes 2>/dev/null |grep "$ip:$PORT" |awk -F ' ' '{print $3}'|awk -F ',' '{print $1}'`
        if [ "$node" == "myself" ];then
         node=`$REDISCLI -c -h $ip -p $PORT -a $PASS cluster nodes 2>/dev/null |grep "$ip:$PORT" |awk -F ' ' '{print $3}'|awk -F ',' '{print $2}'` 
        fi
        echo $node
     else
         
          $REDISCLI -c -h $ip -p $conn_port -a $PASS cluster nodes 2>/dev/null|grep '$ip:$PORT' |awk -F ',' '{print $2}'|grep -c 'fail'
     fi
}
status(){
}
if [ "$1" == "cluster" ];then
 redis_cluster $2 $3 
else
 $1
fi
#!/bin/bash
#----将需要添加的服务器ip配置到列表
#----只需要运行此脚本即可  -
#-和其他服务器需要免密登陆
#-------

shdir=$(cd `dirname $0`; pwd)
server_ip=(
    )
zabbix_agent_dir=/usr/local/zabbix
zabbix_custom_sh=/app/zabbixsh
#agent端使用端口号默认22
port_romote=22
user_romote=root
agent_start_user=zabbix
agent_start_group=zabbix
#agent端运行的脚本
cunstom_sh=$shdir/conf/redis_single_cluster.sh
#处理agent配置文件的脚本
remote_sh=$shdir/conf/config.sh
#自定义配置选项的配置文件
cunstom_conf=$shdir/conf/userparameter_redis.conf
stop_agent(){
 
   for ip in ${server_ip[*]};
      do
      ssh -p${port_romote}  $user_romote@$ip -C "systemctl stop zabbix"
      done
}
scp_conf(){
  for ip in ${server_ip[*]};
      do
      scp -r -P${port_romote} $remote_sh $user_romote@$ip:$zabbix_agent_dir/conf
      ssh -p${port_romote} $user_romote@$ip -C "source $zabbix_agent_dir/conf/config.sh $agent_start_user $zabbix_agent_dir $agent_start_group $zabbix_custom_sh"
      scp -r -P${port_romote} $cunstom_sh $user_romote@$ip:$zabbix_custom_sh
      scp -r -P${port_romote} $cunstom_conf $user_romote@$ip:$zabbix_agent_dir/conf/zabbix_agentd
      
      done
}
star_agent(){
for ip in ${server_ip[*]};
      do
     ssh -p${port_romote} $user_romote@$ip -C 'systemctl restart zabbix'
     done
}
#stop_agent
scp_conf
star_agent
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凤舞飘伶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值