haproxymysqlslave多从库负载均衡带故障检测V1.1.doc_第1页
haproxymysqlslave多从库负载均衡带故障检测V1.1.doc_第2页
haproxymysqlslave多从库负载均衡带故障检测V1.1.doc_第3页
haproxymysqlslave多从库负载均衡带故障检测V1.1.doc_第4页
haproxymysqlslave多从库负载均衡带故障检测V1.1.doc_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

haproxy+mysql slave多从库负载均衡带故障检测V1.1Author:gaojinbo Time:2010-9-15 使用haproxy对mysql slave进行负载均衡,故障检测 环境: haproxy 00 vip db_read 40 db1 master 41 db2 slave1 42 db3 slave2 43 一、安装配置主从数据库,同步数据库为gaojinbo_www master上操作 1)修改配置 vi /etc/mysql/f server-id = 1 log_bin = mysql-bin log-slave-updates binlog_do_db = gaojinbo_www 2)重启Mysql并查看master状态 /etc/init.d/mysql restart mysql -uroot -pylmf grant replication slave on *.* to replication% identified by ylmf; show master statusG; 说明:添加用户replication用户同步数据库,记录master状态,配置从库的时候需要 slave1上操作 1)修改配置 vi /etc/mysql/f server-id = 2 log_bin = mysql-bin log-slave-updates replicate_do_db = gaojinbo_www slave2上操作 1)修改配置 vi /etc/mysql/f server-id = 3 log_bin = mysql-bin log-slave-updates replicate_do_db = gaojinbo_www 2台slave上操作 mysql -uroot -pylmf change master to master_host=41,master_port=3306,master_user=replication,master_password=ylmf,master_log_file=mysql-bin.000003,master_log_pos=106; 二、mysql同步检测脚本,只需要在2台slave上操作 1.安装xinetd apt-get install xinetd 2.增加检测服务 vi /etc/xinetd.d/mysqlchk service mysqlchk_read flags = REUSE socket_type = stream port = 9201 wait = no user = nobody server = /opt/mysqlchk_replication.sh log_on_failure += USERID disable = no only_from = /24 # recommended to put the IPs that need # to connect exclusively (security purposes) vi /etc/services mysqlchk_read 9201/tcp #mysql slave check read 3.检测脚本 vi /opt/mysqlchk_status.sh #!/bin/bash # # /opt/mysqlchk_status.sh # # This script checks if a mysql server is healthy running on localhost. It will # return: # # HTTP/1.x 200 OKr (if mysql is running smoothly) # # OR # # HTTP/1.x 500 Internal Server Errorr (else) # MYSQL_HOST= MYSQL_PORT=3306 MYSQL_USERNAME=root MYSQL_PASSWORD=ylmf # # We perform a simple query that should return a few results ERROR_MSG=/usr/bin/mysql host=$MYSQL_HOST port=$MYSQL_PORT user=$MYSQL_USERNAME password=$MYSQL_PASSWORD -e show databases; 2/dev/null # # Check the output. If it is not empty then everything is fine and we return # something. Else, we just do not return anything. # if $ERROR_MSG != then # mysql is fine, return http 200 /bin/echo -e HTTP/1.1 200 OKrn /bin/echo -e Content-Type: Content-Type: text/plainrn /bin/echo -e rn /bin/echo -e MySQL is running.rn /bin/echo -e rn else # mysql is down, return http 503 /bin/echo -e HTTP/1.1 503 Service Unavailablern /bin/echo -e Content-Type: Content-Type: text/plainrn /bin/echo -e rn /bin/echo -e MySQL is *down*.rn /bin/echo -e rn fi 三、haproxy配置 1.下载 wget http:/haproxy.1wt.eu/download/1.4/src/haproxy-1.4.8.tar.gz2.编译安装 tar xvzf haproxy-1.4.8.tar.gz cd haproxy-1.4.8 make TARGET=linux26 make install 3.配置文件 vi /etc/haproxy.cfg global maxconn 40000 debug #quiet user haproxy group haproxy nbproc 1 log local3 spread-checks 2 defaults timeout server 3s timeout connect 3s timeout client 60s timeout http-request 3s timeout queue 3s frontend db_read bind 40:3306 default_backend cluster_db_read frontend web_haproxy bind :80 default_backend web_status backend cluster_db_read mode tcp option tcpka balance roundrobin option httpchk server db03_slave 42:3306 weight 1 check port 9201 inter 1s rise 5 fall 1 server db04_slave 43:3306 weight 1 check port 9201 inter 1s rise 5 fall 1

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论