Haproxy+MYSQL 负载均衡 原创
[root@monitor app1]# yum install haproxy
Loaded plugins: security
base | 3.7 kB :
epel | 4.3 kB :
epel/primary_db | 5.9 MB :
extras | 3.4 kB :
updates | 3.4 kB :
updates/primary_db | 5.2 MB :
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package haproxy.x86_64 :1.5.-.el6_7. will be installed
--> Finished Dependency Resolution Dependencies Resolved ================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
haproxy x86_64 1.5.-.el6_7. updates k Transaction Summary
================================================================================
Install Package(s) Total download size: k
Installed size: 2.4 M
Is this ok [y/N]: y
Downloading Packages:
haproxy-1.5.-.el6_7..x86_64.rpm | kB :
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : haproxy-1.5.-.el6_7..x86_64 /
Verifying : haproxy-1.5.-.el6_7..x86_64 / Installed:
haproxy.x86_64 :1.5.-.el6_7. Complete!
装了那些东西:
[root@monitor app1]# rpm -ql haproxy.x86_64 :1.5.-.el6_7.
/etc/haproxy
/etc/haproxy/haproxy.cfg
/etc/logrotate.d/haproxy
/etc/rc.d/init.d/haproxy
/etc/sysconfig/haproxy
/usr/bin/halog
/usr/bin/iprange
/usr/sbin/haproxy
/usr/share/doc/haproxy-1.5.
/usr/share/doc/haproxy-1.5./CHANGELOG
/usr/share/doc/haproxy-1.5./LICENSE
/usr/share/doc/haproxy-1.5./README
/usr/share/doc/haproxy-1.5./acl-content-sw.cfg
/usr/share/doc/haproxy-1.5./acl.fig
/usr/share/doc/haproxy-1.5./architecture.txt
/usr/share/doc/haproxy-1.5./close-options.txt
/usr/share/doc/haproxy-1.5./coding-style.txt
/usr/share/doc/haproxy-1.5./configuration.txt
/usr/share/doc/haproxy-1.5./content-sw-sample.cfg
/usr/share/doc/haproxy-1.5./cookie-options.txt
/usr/share/doc/haproxy-1.5./cttproxy-src.cfg
/usr/share/doc/haproxy-1.5./design-thoughts
/usr/share/doc/haproxy-1.5./design-thoughts/backends-v0.txt
/usr/share/doc/haproxy-1.5./design-thoughts/backends.txt
/usr/share/doc/haproxy-1.5./design-thoughts/be-fe-changes.txt
/usr/share/doc/haproxy-1.5./design-thoughts/binding-possibilities.txt
/usr/share/doc/haproxy-1.5./design-thoughts/buffer-redesign.txt
/usr/share/doc/haproxy-1.5./design-thoughts/buffers.fig
/usr/share/doc/haproxy-1.5./design-thoughts/config-language.txt
/usr/share/doc/haproxy-1.5./design-thoughts/connection-reuse.txt
/usr/share/doc/haproxy-1.5./design-thoughts/cttproxy-changes.txt
/usr/share/doc/haproxy-1.5./design-thoughts/entities-v2.txt
/usr/share/doc/haproxy-1.5./design-thoughts/how-it-works.txt
/usr/share/doc/haproxy-1.5./design-thoughts/http_load_time.url
/usr/share/doc/haproxy-1.5./design-thoughts/rate-shaping.txt
/usr/share/doc/haproxy-1.5./design-thoughts/sess_par_sec.txt
/usr/share/doc/haproxy-1.5./gpl.txt
/usr/share/doc/haproxy-1.5./haproxy-en.txt
/usr/share/doc/haproxy-1.5./haproxy-fr.txt
/usr/share/doc/haproxy-1.5./haproxy.
/usr/share/doc/haproxy-1.5./haproxy.cfg
/usr/share/doc/haproxy-1.5./internals
/usr/share/doc/haproxy-1.5./internals/acl.txt
/usr/share/doc/haproxy-1.5./internals/body-parsing.txt
/usr/share/doc/haproxy-1.5./internals/buffer-operations.txt
/usr/share/doc/haproxy-1.5./internals/buffer-ops.fig
/usr/share/doc/haproxy-1.5./internals/connect-status.txt
/usr/share/doc/haproxy-1.5./internals/connection-header.txt
/usr/share/doc/haproxy-1.5./internals/connection-scale.txt
/usr/share/doc/haproxy-1.5./internals/entities.fig
/usr/share/doc/haproxy-1.5./internals/entities.pdf
/usr/share/doc/haproxy-1.5./internals/entities.svg
/usr/share/doc/haproxy-1.5./internals/entities.txt
/usr/share/doc/haproxy-1.5./internals/hashing.txt
/usr/share/doc/haproxy-1.5./internals/header-parser-speed.txt
/usr/share/doc/haproxy-1.5./internals/header-tree.txt
/usr/share/doc/haproxy-1.5./internals/http-cookies.txt
/usr/share/doc/haproxy-1.5./internals/http-docs.txt
/usr/share/doc/haproxy-1.5./internals/http-parsing.txt
/usr/share/doc/haproxy-1.5./internals/naming.txt
/usr/share/doc/haproxy-1.5./internals/pattern.dia
/usr/share/doc/haproxy-1.5./internals/pattern.pdf
/usr/share/doc/haproxy-1.5./internals/polling-states.fig
/usr/share/doc/haproxy-1.5./internals/repartition-be-fe-fi.txt
/usr/share/doc/haproxy-1.5./internals/sequence.fig
/usr/share/doc/haproxy-1.5./internals/stats-v2.txt
/usr/share/doc/haproxy-1.5./internals/stream-sock-states.fig
/usr/share/doc/haproxy-1.5./internals/todo.cttproxy
/usr/share/doc/haproxy-1.5./lgpl.txt
/usr/share/doc/haproxy-1.5./proxy-protocol.txt
/usr/share/doc/haproxy-1.5./queuing.fig
/usr/share/doc/haproxy-1.5./tarpit.cfg
/usr/share/doc/haproxy-1.5./url-switching.cfg
/usr/share/haproxy
/usr/share/haproxy/.http
/usr/share/haproxy/.http
/usr/share/haproxy/.http
/usr/share/haproxy/.http
/usr/share/haproxy/.http
/usr/share/haproxy/.http
/usr/share/haproxy/.http
/usr/share/haproxy/README
/usr/share/man/man1/halog..gz
/usr/share/man/man1/haproxy..gz
/var/lib/haproxy
package :1.5.-.el6_7. is not installed
开机自动启动: chkconfig haproxy on 服务启动:
service haproxy on
[root@monitor etc]# netstat -tunlp | grep haproxy
tcp 0 0 0.0.0.0:8888 0.0.0.0:* LISTEN 1296/haproxy
tcp 0 0 10.169.216.172:3306 0.0.0.0:* LISTEN 1296/haproxy
udp 0 0 0.0.0.0:60642 0.0.0.0:* 1296/haproxy
日志记录:
[root@monitor etc]# cat /etc/rsyslog.d/49-haproxy.conf
# Create an additional socket in haproxy's chroot in order to allow logging via
# /dev/log to chroot'ed HAProxy processes
$AddUnixListenSocket /var/lib/haproxy/dev/log
$ModLoad imudp
$UDPServerRun
local3.* /var/log/haproxy.log # Send HAProxy messages to a dedicated logfile
if $programname startswith 'haproxy' then /var/log/haproxy.log
&~
[root@monitor etc]# cat /etc/haproxy/haproxy.cfg # 全局配置参数
global
log 127.0.0.1 local0 notice
user haproxy
group haproxy # 一些默认参数
defaults
log global
retries
option dontlognull
option redispatch
maxconn
timeout connect
timeout server
timeout client # 这个是我们定义的负载均衡的配置
listen mysql-lb1
# 绑定的IP和端口 haproxy服务器一个网卡IP
bind 10.169.216.172:3306
# 模式是TCP
mode tcp
# 通过mysql连接去检测mysql是否可以访问 创建用户haproxy_check 密码为空,权限usage
option mysql-check user haproxy_check
# 负载均衡算法是 轮询
balance roundrobin
# 下面两个就是后端被访问的server
server mysql_1 10.24.220.70: weight check
server mysql_2 10.169.214.33: weight check # 自带的监控服务器的配置
# 监控服务的端口是
listen stats *:
# 监控模式是http
mode http
option httpclose
balance roundrobin
stats uri /
stats realm Haproxy\ Statistics
# 监控的用户名和密码
stats auth myadmin:myadmin
后台MYSQL每台执行: # 通过mysql连接去检测mysql是否可以访问 创建用户haproxy_check 密码为空,权限usage
drop user haproxy_check@'10.169.216.172';
create user haproxy_check@'10.169.216.172';
grant usage on *.* to haproxy_check@'10.169.216.172';
set password for haproxy_check@'10.169.216.172' ='';
haproxy_check 账号测试:
root@monitor etc]# mysql -uhaproxy_check -p -h 10.169.216.172 -e "select @@hostname;"
Enter password:
+------------+
| @@hostname |
+------------+
| slave2 |
+------------+
[root@monitor etc]# mysql -uhaproxy_check -p -h 10.169.216.172 -e "select @@hostname;"
Enter password:
+------------+
| @@hostname |
+------------+
| slave1 |
+------------+
[root@monitor etc]# mysql -uhaproxy_check -p -h 10.169.216.172 -e "select @@hostname;"
Enter password:
+------------+
| @@hostname |
+------------+
| slave2 |
+------------+
[root@monitor etc]# mysql -uhaproxy_check -p -h 10.169.216.172 -e "select @@hostname;"
Enter password:
+------------+
| @@hostname |
+------------+
| slave1 |
+------------+
[root@monitor etc]# mysql -uhaproxy_check -p -h 10.169.216.172 -e "select @@hostname;"
Enter password:
+------------+
| @@hostname |
+------------+
| slave2 |
+------------+
[root@monitor etc]# mysql -uhaproxy_check -p -h 10.169.216.172 -e "select @@hostname;"
Enter password:
+------------+
| @@hostname |
+------------+
| slave1 |
+------------+
ROOT 用户测试 [root@monitor etc]# mysql -uroot -p -h 10.169.216.172 -e "select @@hostname;" Enter password:
+------------+
| @@hostname |
+------------+
| slave2 |
+------------+
[root@monitor etc]# mysql -uroot -p -h 10.169.216.172 -e "select @@hostname;"
Enter password:
+------------+
| @@hostname |
+------------+
| slave1 |
+------------+
Haproxy+MYSQL 负载均衡 原创的更多相关文章
- 05.haproxy+mysql负载均衡 整合 redis集群+ssm
本篇重点讲解haproxy+mysql负载均衡,搭建完成后与之前搭建的redis+ssm进行整合 (注:这里用到了两台mysql数据库,分别安装两台虚拟机上,已经成功实现主主复制,如果有需要,请查看我 ...
- 使用LVS+keepalived实现mysql负载均衡的实践和总结
前言 经过一段时间的积累,数据库的架构就需要根据项目不断的进行变化. 从单台数据库,到了两台数据库的主从,再到读写分离,再到双主,现在进一步需要更多的数据库服务器去支撑更加可怕的访问量. 那么经过那么 ...
- 基于 Haproxy 构建负载均衡集群
1.HAPROXY简介 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种负载均衡解决方案.HAProxy特别适用于那些负载特大的web ...
- Haproxy+Keepalived负载均衡
Haproxy介绍 HAProxy是一个特别适用于高可用性环境的TCP/HTTP开源的反向代理和负载均衡软件.在7层负载均衡方面的功能很强大(支持cookie track, header rewrit ...
- LNMP+HAProxy+Keepalived负载均衡 - LNMP基础环境准备
环境版本说明: 服务器系统:CentOS 7.5: ``` cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) # 输出结果 `` ...
- mysql负载均衡方案
mysql负载均衡方案 一.直接连接 数据库的读写分离方案很多,这里介绍基于mysql数据库的读写分离方案. 比较常见的读写分离方案如下: 1 基于查询分离 最简单的分离方法是将读和写分发到主和从服务 ...
- Haproxy 构建负载均衡集群
1.HAPROXY简介 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种负载均衡解决方案.HAProxy特别适用于那些负载特大的web ...
- Nginx,Haproxy/lvs负载均衡的优缺点分析
PS:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些使用经验,总结一下. 一般对负载均衡的使用是随着网站规模的提升根据不 ...
- HAProxy 的负载均衡服务器,Redis 的缓存服务器
问答社区网络 StackExchange 由 100 多个网站构成,其中包括了 Alexa 排名第 54 的 StackOverflow.StackExchang 有 400 万用户,每月 5.6 亿 ...
随机推荐
- UE 使用技巧
一.关于正则表达式的使用 删除空行: 替换 %[ ^t]++^p 为 空串 替换回车换行符:替换^p 为 空串 删除行尾空格: 替换 [ ^t]+$ 为 空串 删除行首空格: 替换 %[ ^t]+ 为 ...
- 《Python CookBook2》 第一章 文本 - 控制大小写 && 访问子字符串
控制大小写 任务: 将一个字符串由大写转成小写,或者泛起到而行之. 解决方案: >>> a = 'a'.upper() >>> a 'A' >>> ...
- c++ 概念及学习/c++ concept&learning(一)
学习过计算机组成原理就会知道,处理器会从主存中取得指令,然后进行解释执行.而他们的交流方式是以二进制方式进行的,也就是他们只能识别1和0 :其实计算机是不知道1和0的,现在的实现方式是以高电压与低电压 ...
- ESXi 与其它虚拟化底层产品之比较:
序号 虚拟化管理程序属性 VMware ESXi 5.0 采用 Hyper-V 的 Windows Server 2008 R2 SP1 Citrix XenServer 5.6 FP1 1 磁盘占 ...
- linux 系统常用命令
临时性的完全关闭防火墙,可以不重启机器: #/etc/init.d/iptables status ##查看防火墙状态 #/etc/init.d/iptable stop ...
- work7
uno. 理解C++变量的作用域和生命周期 没有要求讲解我就简单注释了一下~ #include <iostream>int main(){ for (int i=0;i<10;i++ ...
- 【转】使用JavaScriptCore在JS和OC间通信
http://www.cocoachina.com/ios/20160623/16796.html iOS 开发中,我们时不时的需要加载一些 Web 页面,一些需求使用 Web 页面来实现可以更可控, ...
- HDU 5776 sum (思维题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5776 题目让你求是否有区间的和是m的倍数. 预处理前缀和,一旦有两个数模m的值相同,说明中间一部分连续 ...
- CodeForces 589I Lottery (暴力,水题)
题意:给定 n 和 k,然后是 n 个数,表示1-k的一个值,问你修改最少的数,使得所有的1-k的数目都等于n/k. 析:水题,只要用每个数减去n/k,然后取模,加起来除以2,就ok了. 代码如下: ...
- ajax。表单
JQuery读书笔记--JQuery-Form中的ajaxForm和ajaxSubmit的区别JQuery中的ajaxForm和ajaxSubmit使用差不多功能也差不多.很容易误解. 按照作者的解释 ...