dlslaved 0.1

(Delayed Slave Daemon for MySQL)

dlslaved

allows delayed replication for MySQL databases.


The

dlslaved

syntax is really simple :



   -> dlslaved -h ipAddress -u username -p password -P portNumber



  • 11/06/2007 : initial release
  • Well, it's done. I finally put the source code on Internet. So, be gentle. It's my first unix program.
    The internal architecture of dlslaved is very simple. It uses the SecondsBehindMaster MySQL internal variable, and the STOP and START slave command to try to have 7200 seconds (a constant in the program) constantly behind the master.
    Try it, use it, send back errors and source modifications.

    It compiles under Linux and Solaris (x86 and Sparc) using gcc.

    Download dlslaved user's manual (a PDF file).
    Download dlslaved source code for Linux and Solaris (i think most Unix like systems). To compile, you need MySQL binaries and libraries to be install in /usr/local/mysql directory.


Contact me at rodolphe.jouannet(at)free.fr for support or questions.

根据上述思路,写一shell来实现相同的操作:

  1. #!/bin/bash 
  2. # 监控mysql slave状态,实现slave延时 
  3. INTERVAL="1800" 
  4. #CURPATH=$(pwd) 
  5. CURPATH=/home/adminshell 
  6. AUTH='-uroot -ppassword' 
  7. SLAVE_IO="Slave_IO_Running:" 
  8. SLAVE_SQL="Slave_SQL_Running:" 
  9. SHOW_SLAVE_STATUS="show slave status\G" 
  10. START_SLAVE="start slave" 
  11. STOP_SLAVE="stop slave" 
  12.  
  13. MYSQL="$(which mysql)" 
  14. if [ $? -ge 1 ] 
  15. then 
  16.     MYSQL="/usr/local/mysql/bin/mysql" 
  17. fi 
  18.  
  19. PIDOF="$(which pidof)" 
  20. if [ $? -ge 1 ] 
  21. then 
  22.     PIDOF="/sbin/pidof" 
  23. fi 
  24.  
  25. while : 
  26. do 
  27.     TIMESTAMP_TODAY="$(date +%Y%m%d)" 
  28.     LOGFILE="${CURPATH}/mysql_slave_delay_${TIMESTAMP_TODAY}.log" 
  29.     echo "[`date +%c`] mysqld process check" >> $LOGFILE 
  30.     MYSQLDPID=$($PIDOF mysqld) 
  31.     if [ -z $MYSQLDPID ];then 
  32.         echo "mysqld is not started!" >> $LOGFILE 
  33.     else 
  34.         echo "[`date +%c`] mysqld is running" >> $LOGFILE 
  35.         echo "[`date +%c`] mysql slave status check" >> $LOGFILE 
  36.         SLAVE_IO_STATUS=$($MYSQL $AUTH -Bse "$SHOW_SLAVE_STATUS" | grep $SLAVE_IO | awk '{ print $2 }') 
  37.         SLAVE_SQL_STATUS=$($MYSQL $AUTH -Bse "$SHOW_SLAVE_STATUS" | grep $SLAVE_SQL | awk '{ print $2 }') 
  38.         if [ "$SLAVE_IO_STATUS" = "Yes" -a "$SLAVE_SQL_STATUS" = "Yes" ];then 
  39.             echo "[`date +%c`] mysql slave is running,stop it" >> $LOGFILE 
  40.             $MYSQL $AUTH -Bse "$STOP_SLAVE" 
  41.         else 
  42.             echo "[`date +%c`] mysql slave is not running,start it" >> $LOGFILE 
  43.             $MYSQL $AUTH -Bse "$START_SLAVE" 
  44.         fi 
  45.         echo "[`date +%c`] ****************************************************" >> $LOGFILE 
  46.         sleep ${INTERVAL} 
  47.     fi 
  48. done 

本日志由 flyinweb 于 2010-01-28 15:28:33 发表,目前已经被浏览 4061 次,评论 0 次;

作者添加了以下标签: mysql slave

引用通告:http://www.517sou.net/Article/407/Trackback.ashx

评论订阅:http://www.517sou.net/Article/407/Feeds.ashx

评论列表

    暂时没有评论
(必填)
(必填,不会被公开)