HAproxy+Mycat
haproxy+mycat搭建
haproxy server 10.0.1.134
mycat server 10.0.1.134,10.0.1.135
mysql master 10.0.1.134
mysql slave 10.0.1.135
CentOS release 6.6 (Final)
jdk-8u101-linux-x64
Mycat-server-1.6-RELEASE-20161010173036-linux
1 下载haproxy
[root@hongquan soft]# tar zxvf haproxy-1.7.0.tar.gz
[root@hongquan soft]# cd haproxy-1.7.0
[root@hongquan haproxy-1.7.0]# make TARGET=linux26 PREFIX=/usr/local/haproxy ARCH=x86_64
make install PREFIX=/usr/local/haproxy
[root@hongquan haproxy-1.7.0]# useradd haproxy
[root@hongquan haproxy-1.7.0]# cd /usr/local/haproxy/
[root@hongquan haproxy]# chown -R haproxy:haproxy *
#vim /usr/local/haproxy/haproxy.cfg
global
log 127.0.0.1 local0 ##记日志的功能
maxconn 4096
chroot /usr/local/haproxy
user haproxy
group haproxy
daemon
defaults
log global
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen admin_status 10.0.1.134:48800 ##VIP
stats uri /admin-status ##统计页面
stats auth admin:admin
mode http
option httplog
listen allmycat_service 10.0.1.134:8096 #10.0.1.134 8096端口转发到34,35 mycat 8086端口
mode tcp
option tcplog
option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
balance roundrobin
server mycat_26 10.0.1.134:8086 check port 48700 inter 5s rise 2 fall 3
server mycat_27 10.0.1.135:8086 check port 48700 inter 5s rise 2 fall 3
srvtimeout 20000
listen allmycat_admin 10.0.1.134:8097 ##转发到mycat的9066端口,及mycat的管理控制台端口
mode tcp
option tcplog
option httpchk OPTIONS * HTTP/1.1\r\nHost:\ www
balance roundrobin
server mycat_26_admin 10.0.1.134:9086 check port 48700 inter 5s rise 2 fall 3
server mycat_27_admin 10.0.1.135:9086 check port 48700 inter 5s rise 2 fall 3
srvtimeout 20000
安装haproxy日志
默认haproxy是不记录日志的,为了记录日志还需要配置syslog模块,
在Linux下是rsyslogd服务,yum –y install rsyslog先安装rsyslog,然后
记录haproxy日志的配置
#cd /etc/rsyslog.d/
如果没有这个目录,新建
#cd /etc
#mkdir rsyslog.d
#cd /etc/rsyslog.d/
#touch haproxy.conf
#vi /etc/rsyslog.d/haproxy.conf
$ModLoad imudp
$UDPServerRun 514
local0.* /var/log/haproxy.log
#vi /etc/rsyslog.conf
1、在#### RULES ####上面一行的地方加入以下内容:
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
#### RULES ####
2、在local7.*
/var/log/boot.log的下面加入以下内容(增加后的效果如下):
# Save boot messages also to boot.log
local7.* /var/log/boot.log
local0.* /var/log/haproxy.log
这里告诉一个VIM 技巧 进入VI 编辑页面按G可以跳转到文件的最后一行
保存,重启rsyslog服务
service rsyslog restart
将rsyslog加入自动启动服务
chkconfig --add rsyslog
chkconfig --level 2345 rsyslog on
现在你就可以看到日志(/var/log/haproxy.log)了
配置监听mycat是否存活
下面的配置是在10.0.1.134 10.0.1.135两台MYCAT 服务器上配置
在Mycat server1 Mycat server2上都需要添加检测端口48700的脚本,为此需要用到xinetd,xinetd为linux系统的基础服务
首先在xinetd目录下面增加脚本与端口的映射配置文件
1、如果xinetd没有安装,使用如下命令安装:
yum install xinetd -y
2、检查/etc/xinetd.conf的末尾是否有这一句:includedir /etc/xinetd.d
没有就加上,
3、检查 /etc/xinetd.d文件夹是否存在,不存在也加上
#cd /etc
#mkdir xinetd.d
4、增加 /etc/xinetd.d/mycat_status
#vim /etc/xinetd.d/mycat_status
service mycat_status
{
flags = REUSE
socket_type = stream
port = 48700
wait = no
user = root
server =/usr/local/bin/mycat_status
log_on_failure += USERID
disable = no
}
创建编辑/usr/local/bin/mycat_status 文件,并赋予执行权限
[root@test927 xinetd.d]# cat /usr/local/bin/mycat_status
#!/bin/bash
#/usr/local/bin/mycat_status.sh
# This script checks if a mycat server is healthy running on localhost. It will
# return:
#
# "HTTP/1.x 200 OK\r" (if mycat is running smoothly)
#
# "HTTP/1.x 503 Internal Server Error\r" (else)
mycat=`/opt/mycat/bin/mycat status | grep 'not running' | wc -l`
if [ "$mycat" = "0" ];
then
/bin/echo -e "HTTP/1.1 200 OK\r\n"
else
/bin/echo -e "HTTP/1.1 503 Service Unavailable\r\n"
fi
##############################################
注意:/opt/mycat/bin/mycat 为MYCAT的$HOME 目录
chmod 777 /usr/local/bin/mycat_status
chmod 777 /etc/xinetd.d/mycat_status
4、/etc/services中加入mycat_status服务
加入mycat_status服务
#cd /etc
#vi services
在末尾加入
mycat_status 48700/tcp # mycat_status
保存
重启xinetd服务
service xinetd restart
将xinetd加入自启动服务
chkconfig --add xinetd
chkconfig --level 2345 xinetd on
5、验证mycat_status服务是否启动成功
验证mycat_status服务是否启动成功
#netstat -antup|grep 48700
如果成功会现实如下内容:
netstat -antup|grep 48700
tcp 0 0 :::48700 :::* LISTEN 12609/xinetd
启动HAPROXY
/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/haproxy.cfg
HAproxy+Mycat的更多相关文章
- Dubbo入门到精通学习笔记(二十):MyCat在MySQL主从复制的基础上实现读写分离、MyCat 集群部署(HAProxy + MyCat)、MyCat 高可用负载均衡集群Keepalived
文章目录 MyCat在MySQL主从复制的基础上实现读写分离 一.环境 二.依赖课程 三.MyCat 介绍 ( MyCat 官网:http://mycat.org.cn/ ) 四.MyCat 的安装 ...
- MyCat集群部署(HAProxy + MyCat)
本文档内容的依赖龙果学院<基于Dubbo的分布式系统架构实战>课程 二.软件版本 操作系统:CentOS-6.6-x86_64 JDK版本:jdk1.7.0_72 HAProxy版本:ha ...
- KeepAlived+HaProxy+MyCat+Percona双机热备PXC集群
一.搭建PXC集群 1.环境:centos7+PXC5.7.21+mycat1.6.5 2.卸载mariadb rpm -qa | grep mariadb* yum -y remove mariad ...
- haproxy mycat mysql 读写分离MHA高可用
主机IP信息 hostname IP 172.16.3.140 haproxy01 172.16.3.141 haproxy02 172.16.3.142 mycat01 172.16.3.143 m ...
- haproxy Mycat集2---KeepAlived
KA 配两台 MASTER,BACKUP节点 安装Keepalived 1.下载安装依赖包 yum install -y wget make gcc openssl-devel popt-devel ...
- haproxy Mycat集
8-1 镜像haproxy docker run -it --privileged --name haproxy docker.io/centos:latest 8-2wget http://w ...
- mycat高可用方案
1.建议采用标准的mysql主从复制高可用配置并交付给mycat来完成后端mysql节点的主从自动切换. 2.mycat自身的高可用性 由HAproxy+Mycat集群+Mysql主从所组成的高可用性 ...
- 06mycat使用haproxy进行负载均衡
集群的服务器列表 在10.11.0.210和10.11.0.216中部署mycat和haproxy(因为实验机器性能有限,实际生产环境中需要单独用服务做haproxy反向代理) 两台机器的Mycat配 ...
- Mycat读写分离、主从切换、分库分表的操作记录
系统开发中,数据库是非常重要的一个点.除了程序的本身的优化,如:SQL语句优化.代码优化,数据库的处理本身优化也是非常重要的.主从.热备.分表分库等都是系统发展迟早会遇到的技术问题问题.Mycat是一 ...
随机推荐
- JQuery 操作 iframe
JQuery访问iframe内的元素 $("iframe#Main", top.document).contents().find("#id"); JQuery ...
- JAVA使用Freemarker生成静态文件中文乱码
1.指定Configuration编码 Configuration freemarkerCfg = new Configuration(); freemarkerCfg.setEncoding(Loc ...
- 多校HDU5723 最小生成树+dfs回溯
Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- CentOS防火墙iptables-config的相关配置参数详解
默认/etc/sysoncifg/iptables-config的配置内容: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 2 ...
- [转载]Google Android开发精华教程
原文地址:Android开发精华教程">Google Android开发精华教程作者:huiyi8zai Android是Google于2007年11月5日宣布的基于Linux平台的开 ...
- Java基础(7)-集合类3
list集合的特点 1)有序(存储和取出的元素一直) 2)可重复 List子类的特点 ArrayList 有序,可重复 底层数据结构是数组 查询快,增删慢 线程不安全,效率高 Vector 有序,可重 ...
- html div 加边框样式
边框虚线样式:dashed边框实现样式:solid border:1px dashed #000代表设置对象边框宽度为1px黑色虚线边框 border:1px solid #000代表设置对象边框宽度 ...
- BZOJ4199/UOJ131 [Noi2015]品酒大会
本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000 作者博客:http://www.cnblogs.com/ljh2000-jump/ ...
- SaaS架构经验总结
2B Saas系统最近几年都很火.很多创业公司都在尝试创建企业级别的应用 cRM, HR,销售, Desk Saas系统.很多Saas创业公司也拿了大额风投.毕竟Saas相对传统软件的优势非常明显. ...
- IDEA配置JavaWeb项目Artifacts