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 亿 ...
随机推荐
- Asp.Net中的获取Web.config中设置的参数!(前后台的代码示例)
一.Web.config中设置代码 <appSettings> <add key="deleted" value="1" ...
- C字符串和C++中string的区别 &&&&C++中int型与string型互相转换
在C++中则把字符串封装成了一种数据类型string,可以直接声明变量并进行赋值等字符串操作.以下是C字符串和C++中string的区别: C字符串 string对象(C++) 所需的头文件名称 ...
- [Hive - LanguageManual] Hive Default Authorization - Legacy Mode
Disclaimer Prerequisites Users, Groups, and Roles Names of Users and Roles Creating/Dropping/Using R ...
- Salt自动化之自动更新Gitfs-爱折腾技术网
Salt自动化之自动更新Gitfs-爱折腾技术网 pygit2
- 【转】并发编程之GCD
http://blog.xcodev.com/blog/2013/11/04/gcd-intro/ Dispatch Queue Dispatch Queue是一个任务执行队列,可以让你异步或同步地执 ...
- JS代码格式化修改表格的数值的格式
今天在cognos中第一次需要用到JS,主要是报表页面展示的时候是可能得到如下的数据 ,我需要对其中类型中有金额字样的,后面的数值,精确2位小数:有百分比字样的,数值显示成百分比.如下. 我先尝试了自 ...
- mysql从一个表中拷贝数据到另一个表中sql语句
这一段在找新的工作,今天面试时,要做一套题,其中遇到这么一句话,从一个表中拷贝所有的数据到另一个表中的sql是什么? 原来我很少用到,也没注意过这个问题,面试后我上网查查,回来自己亲手写了写,测试了下 ...
- Linux平台部署varnish 高性能缓存服务器
一:varnish部署前准备: 1.1相关软件以及系统,web服务 系统要求:Centos 6(以上) (64位) 相关中间件:varnish-4.0.2 1.2相关系统依赖包安装检查准备 1.2.1 ...
- [转]directsound抓取麦克风PCM数据封装类
网上有很多方法从麦克风读取PCM数据,不想一一举例.只是在这里发布一个我自己写的directsound的麦克风PCM数据采集类,通过它,可以很方便的利用directsound技术把麦克风的数据采集到, ...
- ASP导出Word带页眉页脚,中文不乱码
关键代码: <% Response.Clear() Response.CodePage= Response.Charset="UTF-8" Response.ContentT ...