




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、haproxy+mysql slave多从库负载均衡带故障检测V1.1Author:gaojinbo Time:2010-9-15 使用haproxy对mysql slave进行负载均衡,故障检测 环境: haproxy 00 vip db_read 40 db1 master
2、41 db2 slave1 42 db3 slave2 43 一、安装配置主从数据库,同步数据库为gaojinbo_www master上操作 1)修改配置 vi /etc/mysql/f server-id
3、= 1 log_bin = mysql-bin log-slave-updates binlog_do_db = gaojinbo_www 2)重启Mysql并查看master状态 /etc/init.d/mysql restart mysql -uroot -p
4、ylmf 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
5、; = mysql-bin log-slave-updates replicate_do_db = gaojinbo_www slave2上操作 1)修改配置 vi /etc/mysql/f server-id
6、60; = 3 log_bin = mysql-bin log-slave-updates replicate_do_db = gaojinbo_www 2台slave上操作 mysql -uroot -pylmf change maste
7、r 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
8、0; flags = REUSE socket_type = stream port
9、0; = 9201 wait = no user = nobody serve
10、r = /opt/mysqlchk_replication.sh log_on_failure += USERID disable = no
11、; only_from = /24 # recommended to put the IPs that need
12、0; # to connect exclusively (security purposes) vi /etc/services mysqlchk_read 9201/tcp #mysql slave check read 3.检测脚本 vi /opt
13、/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="
14、;" 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
15、;" 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
16、0; /bin/echo -e "HTTP/1.1 200 OKrn" /bin/echo -e "Content-Type: Content-Type: text/plainrn" /bin/echo -e "rn" /bin/echo -e
17、"MySQL is running.rn" /bin/echo -e "rn" else # mysql is down, return http 503 /bin/echo -e "HTTP/1.1 503 Service Unavailablern" &
18、#160; /bin/echo -e "Content-Type: Content-Type: text/plainrn" /bin/echo -e "rn" /bin/echo -e "MySQL is *down*.rn" /bi
19、n/echo -e "rn" fi 三、haproxy配置 1.下载 wget http:/haproxy.1wt.eu/download/1.4/src/haproxy-1.4.8.tar.gz 2.编译安装 tar xvzf haproxy-1.4.8.tar.gz cd haproxy-1.4.8 make TARGET=linux26 make install 3.配置文件 vi /etc/haproxy.cfg global maxc
20、onn 40000 debug #quiet user haproxy group haproxy nbproc 1
21、160; log local3 spread-checks 2 defaults timeout server 3s timeout connect 3s time
22、out client 60s timeout http-request 3s timeout queue 3s frontend db_read bind 40:3306 d
23、efault_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
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 菜摊租赁合同范本
- 股东增资扩股合同范本
- MRX343-生命科学试剂-MCE
- Cloniprazepam-生命科学试剂-MCE
- BP-Fluor-568-NHS-ester-生命科学试剂-MCE
- Alfalone-生命科学试剂-MCE
- 5-Bromo-1-methyl-1H-indazole-d3-生命科学试剂-MCE
- 4-1-Piperazinyl-1H-Indole-hydrochloride-4-Piperazinoindole-hydrochloride-生命科学试剂-MCE
- 2025年煤焦化产品合作协议书
- 2025年医用电子直线加速器合作协议书
- 综合应用能力事业单位考试(综合管理类A类)试题及解答参考
- 阿尔兹海默病的家庭护理
- bim技术课件教学课件
- 腹水形成的原因及治疗
- 单晶炉车间安全培训
- 高中地理必修第一册期末试卷及答案-中图版-2024-2025学年
- 护理核心制度测试题+参考答案
- 机械制造技术基础(课程课件完整版)
- 《2023版CSCO卵巢癌诊疗指南》解读课件
- 【医院药品管理系统探析与设计(论文)10000字】
- 螺旋体病梅毒课件
评论
0/150
提交评论