buhao 发表于 2018-9-27 07:20:30

MySQL从库集群方案之HAProxy篇

  
/etc/init.d/HAProxy
  

  
#!/bin/sh
  
#
  
# chkconfig: - 85 15
  
# description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \
  
#            for high availability environments.
  
# processname: HAProxy
  
# config: /etc/HAProxy/HAProxy.cfg
  
# pidfile: /var/run/HAProxy.pid
  

  
# Script Author: Simon Matter
  
# Version: 2004060600
  

  
# Source function library.
  
if [ -f /etc/init.d/functions ]; then
  
. /etc/init.d/functions
  
elif [ -f /etc/rc.d/init.d/functions ] ; then
  
. /etc/rc.d/init.d/functions
  
else
  
exit 0
  
fi
  

  
# Source networking configuration.
  
. /etc/sysconfig/network
  

  
# Check that networking is up.
  
[ ${NETWORKING} = "no" ] && exit 0
  

  
# This is our service name
  
BASENAME=HAProxy
  
if [ -L $0 ]; then
  
BASENAME=`find $0 -name $BASENAME -printf %l`
  
BASENAME=`basename $BASENAME`
  
fi
  

  
[ -f /etc/$BASENAME/$BASENAME.cfg ] || exit 1
  

  
RETVAL=0
  

  
start() {
  
/usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
  
if [ $? -ne 0 ]; then
  
echo "Errors found in configuration file, check it with '$BASENAME check'."
  
return 1
  
fi
  

  
echo -n "Starting $BASENAME: "
  
daemon /usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid
  
RETVAL=$?
  
echo
  
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME
  
return $RETVAL
  
}
  

  
stop() {
  
echo -n "Shutting down $BASENAME: "
  
killproc $BASENAME -USR1
  
RETVAL=$?
  
echo
  
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASENAME
  
[ $RETVAL -eq 0 ] && rm -f /var/run/$BASENAME.pid
  
return $RETVAL
  
}
  

  
restart() {
  
/usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
  
if [ $? -ne 0 ]; then
  
echo "Errors found in configuration file, check it with '$BASENAME check'."
  
return 1
  
fi
  
stop
  
start
  
}
  

  
reload() {
  
/usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
  
if [ $? -ne 0 ]; then
  
echo "Errors found in configuration file, check it with '$BASENAME check'."
  
return 1
  
fi
  
/usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid -sf $(cat /var/run/$BASENAME.pid)
  
}
  

  
check() {
  
/usr/sbin/$BASENAME -c -q -V -f /etc/$BASENAME/$BASENAME.cfg
  
}
  

  
rhstatus() {
  
status $BASENAME
  
}
  

  
condrestart() {
  
[ -e /var/lock/subsys/$BASENAME ] && restart || :
  
}
  

  
# See how we were called.
  
case "$1" in
  
start)
  
start
  
;;
  
stop)
  
stop
  
;;
  
restart)
  
restart
  
;;
  
reload)
  
reload
  
;;
  
condrestart)
  
condrestart
  
;;
  
status)
  
rhstatus
  
;;
  
check)
  
check
  
;;
  
*)
  
echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}"
  
exit 1
  
esac
  

  
exit $?
  

  
chkconfig –add HAProxy
  
chkconfig HAProxy on
  
service HAProxy start


页: [1]
查看完整版本: MySQL从库集群方案之HAProxy篇