[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 负载均衡 原创的更多相关文章

  1. 05.haproxy+mysql负载均衡 整合 redis集群+ssm

    本篇重点讲解haproxy+mysql负载均衡,搭建完成后与之前搭建的redis+ssm进行整合 (注:这里用到了两台mysql数据库,分别安装两台虚拟机上,已经成功实现主主复制,如果有需要,请查看我 ...

  2. 使用LVS+keepalived实现mysql负载均衡的实践和总结

    前言 经过一段时间的积累,数据库的架构就需要根据项目不断的进行变化. 从单台数据库,到了两台数据库的主从,再到读写分离,再到双主,现在进一步需要更多的数据库服务器去支撑更加可怕的访问量. 那么经过那么 ...

  3. 基于 Haproxy 构建负载均衡集群

    1.HAPROXY简介 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种负载均衡解决方案.HAProxy特别适用于那些负载特大的web ...

  4. Haproxy+Keepalived负载均衡

    Haproxy介绍 HAProxy是一个特别适用于高可用性环境的TCP/HTTP开源的反向代理和负载均衡软件.在7层负载均衡方面的功能很强大(支持cookie track, header rewrit ...

  5. LNMP+HAProxy+Keepalived负载均衡 - LNMP基础环境准备

    环境版本说明: 服务器系统:CentOS 7.5: ``` cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) # 输出结果 `` ...

  6. mysql负载均衡方案

    mysql负载均衡方案 一.直接连接 数据库的读写分离方案很多,这里介绍基于mysql数据库的读写分离方案. 比较常见的读写分离方案如下: 1 基于查询分离 最简单的分离方法是将读和写分发到主和从服务 ...

  7. Haproxy 构建负载均衡集群

    1.HAPROXY简介 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种负载均衡解决方案.HAProxy特别适用于那些负载特大的web ...

  8. Nginx,Haproxy/lvs负载均衡的优缺点分析

    PS:Nginx/LVS/HAProxy是目前使用最广泛的三种负载均衡软件,本人都在多个项目中实施过,参考了一些资料,结合自己的一些使用经验,总结一下. 一般对负载均衡的使用是随着网站规模的提升根据不 ...

  9. HAProxy 的负载均衡服务器,Redis 的缓存服务器

    问答社区网络 StackExchange 由 100 多个网站构成,其中包括了 Alexa 排名第 54 的 StackOverflow.StackExchang 有 400 万用户,每月 5.6 亿 ...

随机推荐

  1. Andriod中绘(画)图----Canvas的使用详解

    http://blog.csdn.net/qinjuning/article/details/6936783

  2. 七中滤波方法测试matlab实现

    http://blog.163.com/xiaheng0804@126/blog/static/1205282120132129471816/ 创建两个混合信号,便于更好测试滤波器效果.同时用七中滤波 ...

  3. (原创)LAMP教程1-下载虚拟机软件

    (原创)LAMP教程1 从今天开始会在我的博客更新LAMP教程,第一章节就是安装虚拟机,因为不可能所有的人都有机会操作服务器,所以今天我打算教大家用虚拟机安装配置当下比较流行的框架,lamp. 好了费 ...

  4. codeforces 675D Tree Construction set

    转自:http://blog.csdn.net/qwb492859377/article/details/51447350 #include <stdio.h> #include < ...

  5. 关于DISPLAY变量显示问题

    DISPLAY用来设置将图形显示到何处 在本机上直接登录之后,startx,可以发现display变量自动设置为 [oracle@kel ~]$ echo $DISPLAY :0.0 不论使用何种用户 ...

  6. webstrom11 激活,webstorm 2016.1激活

    http://15.idea.lanyus.com/  webstorm11注册激活,你值得拥有 webstorm 2016.1 最新激活方式:http://blog.lanyus.com/archi ...

  7. 数据库连接类oracleHelper

    //=============================================================================== // OracleHelper ba ...

  8. Chapter3:字符串、向量和数组

    C++11新特性:范围for(range for) for (declaration: expression) statement vector和数组都是对象的集合,而引用不是对象. vector对象 ...

  9. 用MATLAB实现字符串分割

    strsplit更好用,用法: strsplit(strtrim(sprintf('  \t\nds   \nhs\t dssd    \t    \n'))) 以下转载 Matlab的字符串处理没有 ...

  10. HDU 5775 Bubble Sort (线段树)

    Bubble Sort 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5775 Description P is a permutation of t ...