Enhance monitor script for HA

Add keepalived real server check script
This commit is contained in:
yixingj 2018-01-16 15:33:16 +08:00
parent bf14cf4436
commit ffa69bb256
2 changed files with 63 additions and 12 deletions

View File

@ -0,0 +1,44 @@
#!/bin/bash
set -e
#get protocol
#LOG=/var/log/keepalived_check.log
nodeip=$1
nodeaddress="http://${nodeip}"
http_code=`curl -s -o /dev/null -w "%{http_code}" ${nodeaddress}`
if [ $http_code == 200 ] ; then
protocol="http"
elif [ $http_code == 301 ]
then
protocol="https"
else
# echo "`date +"%Y-%m-%d %H:%M:%S"` $1, CHECK_CODE=$http_code" >> $LOG
exit 1
fi
systeminfo=`curl -k -o - -s ${protocol}://${nodeip}/api/systeminfo`
echo $systeminfo | grep "registry_url"
if [ $? != 0 ] ; then
exit 1
fi
#TODO need to check Clair, but currently Clair status api is unreachable from LB.
# echo $systeminfo | grep "with_clair" | grep "true"
# if [ $? == 0 ] ; then
# clair is enabled
# do some clair check
# else
# clair is disabled
# fi
#check top api
http_code=`curl -k -s -o /dev/null -w "%{http_code}\n" ${protocol}://${nodeip}/api/repositories/top`
set +e
if [ $http_code == 200 ] ; then
exit 0
else
exit 1
fi

View File

@ -28,7 +28,9 @@ vrrp_instance VI_1 {
}
}
########## Section for Harbor use HTTP protocol ######################
#Please change VIP, harbor_node1_ip, harbor_node2_ip to real ip address
#Please comment this secion out when use https
virtual_server VIP 80 {
delay_loop 15
lb_algo rr
@ -39,20 +41,24 @@ virtual_server VIP 80 {
real_server harbor_node1_ip 80 {
weight 10
TCP_CHECK {
connect_timeout 3
connect_port 80
MISC_CHECK {
misc_path “/usr/local/bin/check.sh harbor_node1_ip”
misc_timeout 5
}
}
real_server harbor_node2_ip 80 {
weight 10
TCP_CHECK {
connect_timeout 3
connect_port 80
MISC_CHECK {
misc_path “/usr/local/bin/check.sh harbor_node2_ip”
misc_timeout 5
}
}
}
#########################End of HTTP############################
##########################HTTPS#################################
#Please uncomment the follow when harbor running under https
#virtual_server VIP 443 {
# delay_loop 15
@ -64,17 +70,18 @@ virtual_server VIP 80 {
#
# real_server harbor_node1_ip 443 {
# weight 10
# TCP_CHECK {
# connect_timeout 3
# connect_port 443
# MISC_CHECK {
# misc_path “/usr/local/bin/check.sh harbor_node1_ip”
# misc_timeout 5
# }
# }
#
# real_server harbor_node2_ip 443 {
# weight 10
# TCP_CHECK {
# connect_timeout 3
# connect_port 443
# MISC_CHECK {
# misc_path “/usr/local/bin/check.sh harbor_node2_ip”
# misc_timeout 5
# }
# }
#}
#########################End of HTTPS Section#################