[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. 翻译【ElasticSearch Server】第一章:开始使用ElasticSearch集群(2)

    安装和配置集群(Installing and Configuring your Cluster) 第一步是确保正确安装了 Java SE环境.ElasticSearch需要版本6或更高的版本,可以从下 ...

  2. IOS UIActivityIndicatorView 等待指示器

    自己做的一个 等待指示器 #import <UIKit/UIKit.h> @interface RockIndicatorView : UIView { } @property(nonat ...

  3. 《Python 学习手册4th》 第四章 介绍Python对象类型

    ''' 时间: 9月5日 - 9月30日 要求: 1. 书本内容总结归纳,整理在博客园笔记上传 2. 完成所有课后习题 注:“#” 后加的是备注内容(每天看42页内容,可以保证月底看完此书) ''' ...

  4. 常用sql命令

    --1) 创建一张学生表,包含以下信息,学号,姓名,年龄,性别,家庭住址,联系电话 CREATE TABLE student (     [id] [int] IDENTITY(1,1) NOT NU ...

  5. Jacoco远程统计代码覆盖率

    Jacoco   什么是Jacoco? Jacoco是一个开源的Java代码覆盖率工具,Jacoco可以嵌入到Ant .Maven中,并提供了EclEmma Eclipse插件,也可以使用JavaAg ...

  6. 通过反汇编C语言小程序学习Liunx汇编语言

    大家好!    我是来自山东师范大学的吴乐.    今天在<Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ...

  7. python解惑之 __file__ 与argv[0]

    在python下,获取当前执行主脚本的方法有两个:sys.argv[0]和__file__. sys.argv[0] 获取主执行文件路径的最佳方法是用sys.argv[0],它可能是一个相对路径,所以 ...

  8. PLSQL 连接Oracle11g (64位)

    1.用plsql连不上oracle 11g(64位),先去下载一个oracle 11g(32位客户端) http://www.oracle.com/technetwork/database/featu ...

  9. [Hive - LanguageManual] Hive Concurrency Model (待)

    Hive Concurrency Model Hive Concurrency Model Use Cases Turn Off Concurrency Debugging Configuration ...

  10. Downloading the Google Cloud Storage Client Library

    Google Cloud Storage client是一个客户端库,与任何一个生产环境使用的App Engine版本都相互独立.如果你想使用App Engine Development server ...