#dd dd0 配主从

vi /etc/my.cnf

[mysqld]

server-id = 1

log-bin = mysql-bin

binlog-ignore-db = mysql,information_schema

binlog_format = mixed

auto-increment-increment = 2

auto-increment-offset = 1

#dd

grant replication slave on *.* to 'dd'@'192.168.55.%' identified by '123456'

show master status;

#dd0

change master to master_host='192.168.55.138',master_user='dd',master_password='123456',master_log_file='mysql-bin.000001',master_log_pos=530;

start slave;

#dd dd0

tar haproxy

make TARGET=linux310 ARCH=x86_64

make install SBINDIR=/usr/sbin/ MANDIR=/usr/share/man/ DOCDIR=/usr/share/doc/

#dd dd0 配haproxy的启动脚本

vi /etc/rc.d/init.d/haproxy.sh

#!/bin/sh

#

# haproxy

#

# chkconfig: - 85 15

# description: HAProxy is a free, very fast and reliable solution \

# offering high availability, load balancing, and \

# proxying for TCP and HTTP-based applications

# processname: haproxy

# config: /etc/haproxy/haproxy.cfg

# pidfile: /var/run/haproxy.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ "$NETWORKING" = "no" ] && exit 0

exec="/usr/sbin/haproxy"

prog=$(basename $exec)

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

cfgfile=/etc/haproxy/haproxy.cfg

pidfile=/var/run/haproxy.pid

lockfile=/var/lock/subsys/haproxy

check() {

$exec -c -V -f $cfgfile $OPTIONS

}

start() {

$exec -c -q -f $cfgfile $OPTIONS

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

echo -n $"Starting $prog: "

# start it up here, usually something like "daemon $exec"

daemon $exec -D -f $cfgfile -p $pidfile $OPTIONS

retval=$?

echo

[ $retval -eq 0 ] && touch $lockfile

return $retval

}

stop() {

echo -n $"Stopping $prog: "

# stop it here, often "killproc $prog"

killproc $prog

retval=$?

echo

[ $retval -eq 0 ] && rm -f $lockfile

return $retval

}

restart() {

$exec -c -q -f $cfgfile $OPTIONS

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

stop

start

}

reload() {

$exec -c -q -f $cfgfile $OPTIONS

if [ $? -ne 0 ]; then

echo "Errors in configuration file, check with $prog check."

return 1

fi

echo -n $"Reloading $prog: "

$exec -D -f $cfgfile -p $pidfile $OPTIONS -sf $(cat $pidfile)

retval=$?

echo

return $retval

}

force_reload() {

restart

}

fdr_status() {

status $prog

}

case "$1" in

start|stop|restart|reload)

$1

;;

force-reload)

force_reload

;;

check)

check

;;

status)

fdr_status

;;

condrestart|try-restart)

[ ! -f $lockfile ] || restart

;;

*)

echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"

exit 2

esac

chmod +x /etc/rc.d/init.d/haproxy.sh

cd /etc/rc.d/init.d

chkconfig --add haproxy.sh

#dd dd0配haproxy

mkdir /etc/haproxy

mkdir /var/lib/haproxy

useradd -r haproxy

vi /etc/haproxy/haproxy.cfg

global

log 127.0.0.1 local2

chroot /var/lib/haproxy

pidfile /var/run/haproxy.pid

maxconn 4000

user haproxy

group haproxy

daemon

stats socket /var/lib/haproxy/stats

defaults

mode tcp

log global

option dontlognull

option redispatch

retries 3

timeout http-request 10s

timeout queue 1m

timeout connect 10s

timeout client 1m

timeout server 1m

timeout http-keep-alive 10s

timeout check 10s

maxconn 600

listen stats

mode http

bind :6677

stats enable

stats hide-version

stats uri /haproxyadmin?stats

stats realm Haproxy\ Statistics

stats auth admin:admin

stats admin if TRUE

frontend main

bind *:23306

default_backend mysql

backend mysql

balance leastconn

server m1 192.168.55.138:3306 check port 3306 maxconn 300

server m2 192.168.55.129:3306 check port 3306 maxconn 300

#dd dd0 启动haproxy并查看状态

systemctl start haproxy

systemctl status haproxy

#dd0以dd允许的账户通过haproxy的23306端口访问dd的mysql

mysql -udd -p123456 -h192.168.55.138 -P23306

show variables like 'server_id';

判断id是不是dd

#dd dd0配keepalived

vi /etc/keepalived/keepalived.conf # 两个机器配置文件不同

! Configuration File for keepalived

global_defs {

notification_email { # 忽略

acassen@firewall.loc

failover@firewall.loc

sysadmin@firewall.loc

}

notification_email_from Alexandre.Cassen@firewall.loc

smtp_server 192.168.200.1

smtp_connect_timeout 30

router_id LVS_DEVEL

}

vrrp_script chk_haproxy {

script "/etc/keepalived/chk.sh" # 检查haproxy的脚本

interval 2 # 每两秒检查一次

}

vrrp_instance VI_1 {

state BACKUP # 定义为BACKUP节点

nopreempt # 开启不抢占,另一个不写

interface ens33

virtual_router_id 51

priority 100 # 开启了不抢占,所以此处优先级必须高于另一台,另一个写99

advert_int 1

authentication {

auth_type PASS

auth_pass abcd

}

virtual_ipaddress {

192.168.81.150 # 配置VIP

}

track_script {

chk_haproxy # 调用检查脚本

}

notify_backup "/etc/init.d/haproxy restart"

notify_fault "/etc/init.d/haproxy stop"

}

#dd dd0 配chk.sh

vi /etc/keepalived/chk.sh

#!/bin/bash

if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ]; then

/etc/init.d/keepalived stop

fi

chmod +x /etc/keepalived/chk.sh

service keepalived start

#测试

ip addr # 查看是否绑定了虚ip

tcpdump -nn -i ens33 vrrp # 抓包查看

http://192.168.55.138:6677/haproxyadmin?stats # 通过haproxy查看状态

mysql 代理 a_Keepalived+Mysql+Haproxy相关推荐

  1. php mysql 代理_让PHP像C罗一样操作MySQL之ProxySQL

    ProxySQL 简介 ProxySQL是一个高性能的MySQL中间件,是灵活强大的MySQL代理层.像C罗一样的强大,可以实现读写分离,支持Query路由功能,支持动态指定某个SQL进行cache, ...

  2. Amoeba数据库代理 实现mysql读写分离

    Amoeba   依赖jdk centons7安装jdk8 目前Amoeba for Mysql最新版本为amoeba-mysql-3.0.5-RC-distribution.zip. 安装过程很简单 ...

  3. mysql-proxy做mysql代理连接阿里云服务器

    背景:在家办公,IT 部门紧急开启 openvpn 供员工访问公司内网系统.需要访问阿里云上的数据库,但是数据库配置了白名单,只允许公司 IP 访问. 这种情况下可以在公司内网一台虚拟机上搭建 mys ...

  4. golang 通过socks5代理连接mysql(gorm)

    前言 在前一段时间遇见过这样一件事,我们的部分服务要部署在两个机房,而且两个机房并不互通,但是两个服务要通过mysql数据库实现配合工作,从无到有想到了两种实现方式. 这里注明一点的是mysql是与主 ...

  5. mysql-proxy代理加mysql主从实现读写分离

    实验环境搭建: mysql-proxy   192.168.1.163 mysql-master  192.168.1.164 (主) mysql-slave   192.168.1.162 (从) ...

  6. 灵活强大的MySQL代理中间件ProxySQL应用实战(2)

    一.ProxySQL的运行机制 ProxySQL有一个完备的配置系统,配置ProxySQL是基于sql命令的方式完成的.ProxySQL支持配置修改之后的在线保存.应用,不需要重启即可生效.整个配置系 ...

  7. Linux服务篇--反向代理及负载均衡器Haproxy

    本章概要 HAProxy介绍 HAProxy配置 ACL 1.HAProxy介绍 HAProxy介绍 前言 lvs性能强,功能弱:nginx(haproxy)功能多,性能相对较弱,因此,一般情况下,在 ...

  8. 使用MySQL Proxy解决MySQL主从同步延迟

    MySQL的主从同步机制非常方便的解决了高并发读的应用需求,给Web方 面开发带来了极大的便利.但这种方式有个比较大的缺陷在于MySQL的同步机制是依赖Slave主动向Master发请求来获取数据的, ...

  9. MySQL主从(MySQL proxy Lua读写分离设置,一主多从同步配置,分库分表方案)

    Mysql Proxy Lua读写分离设置 一.读写分离说明 读写分离(Read/Write Splitting),基本的原理是让主数据库处理事务性增.改.删操作(INSERT.UPDATE.DELE ...

最新文章

  1. keyvaluepair_C# KeyValuePairTKey,TValue的用法【转】 .
  2. 华为eNSP安装使用教程 故障解决
  3. Redis 开发陷阱及避坑指南!
  4. Spring boot (5):Spring data jpa 的使用
  5. (30)FPGA面试题全局时钟资源及原语
  6. Python中easy_install 和 pip 的安装及使用
  7. Java视频教程等百度云资源分享
  8. 节点name在graph中无法展示_小节点 · 大奥秘│这正是你想学习的精妙休闲观景空间!(内含视频讲解)...
  9. 用户画像 客户喜好消费的商品分类模型表
  10. 个人简历英语及计算机能力怎么写,简历个人能力怎么写(简历中个人能力的填写技巧)...
  11. android 监听短信并发送到服务器
  12. html5页面中添加腾讯地图api
  13. 10019---SpringBoot简介
  14. 【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧
  15. stm32f405rgt6与as5048a的SPI通信问题
  16. windows ce 专题
  17. val.substring is not a function
  18. 易之 - 我是个算命先生(2014年3月23日)
  19. CSDN怎么转载别人的博客(转载)
  20. 使用工具【ZipCenOp.jar】自动修复zip伪加密文件

热门文章

  1. Windows和Linux如何使用Java代码实现关闭进程
  2. 解决yum命令失效,vim: command not found
  3. JAVA入门[6]-Mybatis简单示例
  4. Junit4常用注解
  5. MYSQL的全表扫描,主键索引(聚集索引、第一索引),非主键索引(非聚集索引、第二索引),覆盖索引四种不同查询的分析...
  6. ecos内核概览--bakayi译
  7. LLVM完整参考安装
  8. 获得变量的名称获得传入参数的参数类型与堆栈中的函数名获得变量的名称
  9. 深入理解面向对象设计的七大原则
  10. 学习笔记(31):Python网络编程并发编程-定时器