没有合适的资源?快使用搜索试试~ 我知道了~
首页MySQL高可用学习笔记mysqlrouter_MHA.docx
MySQL高可用学习笔记mysqlrouter_MHA.docx
2星 需积分: 50 9 下载量 196 浏览量
更新于2023-03-03
评论 1
收藏 97KB DOCX 举报
该文档前半部分是一步一步怎么配置mysql_router,然后测试,后半部分是一步一步配置常用的MHA高可用工具和测试,文档详细清楚,基本上按照文档步骤一步步做下去都能配置成功
资源详情
资源评论
资源推荐
MySQL 高可用学习笔记
mysqlrouter 和 MHA
一. MySQL Router
官方下载
1.1. MySQL Router 的安装
[root@MyServer local]> ll | grep mysql-router
-rw-rw-r--. 1 root root 6343846 Apr 10 14:38 mysql-router-2.0.3-
linux-glibc2.12-x86-64bit.tar.gz
# 解压缩
[root@MyServer local]> tar zxvf mysql-router-2.0.3-linux-glibc2.12-
x86-64bit.tar.gz
# 做软连接
[root@MyServer local]> ln -sf mysql-router-2.0.3-linux-glibc2.12-x86-
64bit mysql-router
[root@MyServer local]> cd mysql-router
[root@MyServer mysql-router]> ll
total 20
drwxr-xr-x. 2 7161 wheel 4096
Feb 23 02:29 bin
# 二进制
可执行文件
drwxr-xr-x. 4 7161 wheel 4096
Feb 23 02:29 include
# 头文件
drwxr-xr-x. 3 7161 wheel 4096
Feb 23 02:29 lib
drwxrwxr-x. 2 7161 wheel 4096
Feb 23 02:29 run
drwxr-xr-x. 3 7161 wheel 4096
Feb 23 02:29 share
# lib 库
# 配置示例
# 创建日志目录
[root@MyServer mysql-router]> mkdir -p /var/log/mysqlrouter/
# 创建配置文件目录
[root@MyServer mysql-router]> mkdir -p /etc/mysqlrouter
[root@MyServer mysql-router]> touch /etc/mysqlrouter/mysqlrouter.ini
1.2. MySQL Router 的配置
配置文件为 /etc/mysqlrouter/mysqlrouter.ini
[DEFAULT]
# 定义日志目录
logging_folder = /var/log/mysqlrouter
[logger]
# 定义日志等级
level = INFO
# 一个高可用的标签
[routing:failover]
bind_address = 0.0.0.0
bind_port = 7001
max_connections = 1024
# 目前就支持两种 : read-write 和 read-only
# read-write:用于高可用,用于可读可写
# read-only:用于负载均衡,只读
mode = read-write
# 实际转发的地址
# 第一个 socket 如果可用,就一直会使用第一个
# 如果第一个 socket 无法连接了,才会连接到第二个 socket
destinations = 172.18.14.70:3306, 172.18.14.71:3306
# 一个用于复杂均衡的标签
[routing:balancing]
bind_address = 0.0.0.0
bind_port = 7002
max_connections = 1024
# 用于负载均衡的只读模式
mode = read-only
# 这里的两个 socket 是轮询用的
destinations = 172.18.14.72:3306, 172.18.14.73:3306
1.3. MySQL Router 的部署
+--------Master-------+ RW:Active
+-----+ M:172.18.14.70:3306 <-------------+ +--------+
| +---------------------+ | | MySQL |
| | | Router |
| rpl +--------Slave1-------+ RW:Standby | +--------+ +---------+
+-----> S:172.18.14.71:3306 <-------------+----+ RW <---RW---+ |
| +---------------------+ | 7001 | | Some |
| +--------+ | Clients |
| rpl +--------Slave2-------+ RO:Active | RO <---RO---+ |
+-----> S:172.18.14.72:3306 <-------------+----+ 7002 | +---------+
| +---------------------+ | +--------+
| |
| rpl +--------Slave3-------
+ RO:Active |
172.18.
14.68
+-----> S:172.18.14.73:3306 <-------------+
+---------------------+
1. Master、 Slave1、 Slave2、 Slave3 之间的复制关系是 独立 于 MySQL Router
的;
◦ 也就是说, MySQL Router 不管 MySQL 服务器的主从关系 以及数据是否一致,他
只起到 数据转发 作用
2. Slave1 是候选节点,在 Master 能提供服务 的时候, MySQL Router 不会 把连
接 转发给 Slave1 ;
3. 当 Master 宕机, MySQL Router 把 mode = read-write 的连接转发给 候选
节点 Slave1 时,并不保证 Slave1 上的数据是回放完毕的( 因为他管不了主从
复制);
1.4. MySQL Router 的启动
官方二进制安装包中的启动脚本
share/doc/mysqlrouter/sample_mysqlrouter.init 是 debian 系的;
如果要在 CentOS 上运行,可在 MySQL 官网下载 RedHat 对应的 mysql-router
的 RPM 包,解压后,将其中的/etc/init.d/mysqlrouter 抽取出来,上传到
CentOS 中,然后修改部分变量的路径即可,本文档中的启动脚本修改如下:
MySQL DBA 学习笔记----------------美河学习在线
www.eimhe.com 仅学习参考
#! /bin/bash
#
# mysqlrouter This shell script takes care of starting and stopping
# the MySQL Router
#
# chkconfig: 2345 66 34
# description: MySQL Router
# processname: mysqlrouter
# config: /etc/mysqlrouter/mysqlrouter.ini
# pidfile: /var/run/mysqlrouter/mysqlrouter.pid
#
# Copyright (c) 2015, Oracle and/or its affiliates. All rights
reserved.
#
# This program is free software; you can redistribute it and/or
modify
# it under the terms of the GNU General Public License as published
by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-
1301 USA
#
# Maintainer: MySQL Release Engineering <mysql-build@oss.oracle.com>
#
# Source function library
. /etc/rc.d/init.d/functions
# Source networking configuration
. /etc/sysconfig/network
# add general install path
base_dir=/usr/local/mysql-router
# fix exec path
exec=${base_dir}/bin/mysqlrouter
prog=mysqlrouter
piddir=${base_dir}/run/mysqlrouter
pidfile=${piddir}/mysqlrouter.pid
logdir=/var/log/mysqlrouter
logfile=$logdir/mysqlrouter.log
lockfile=/var/lock/subsys/$prog
# add conf path
conf=/etc/mysqlrouter/mysqlrouter.ini
start () {
[ -d $piddir ] || mkdir -p $piddir
chown mysql:mysql $piddir
[ -d $logdir ] || mkdir -p $logdir
chown mysql:mysql $logdir
[ -e $logfile ] || touch $logfile
chown mysql:mysql $logfile
export ROUTER_PID=$pidfile
# add opt -c to resolv mysqlrouter.ini
daemon --user mysql $exec -c $conf >/dev/null 2>&1 &
ret=$?
if [ $ret -eq "0" ]; then
action $"Starting $prog: " /bin/true
touch /var/lock/subsys/$prog
else
action $"Starting $prog: " /bin/false
fi
return $ret
}
stop () {
[ -f /var/lock/subsys/$prog ] || return 0
killproc mysqlrouter >/dev/null 2>&1
ret=$?
if [ $ret -eq "0" ]; then
rm -f $pidfile
rm -f /var/lock/subsys/$prog
action $"Stopping $prog: " /bin/true
else
ation $"Stopping $prog: " /bin/false
fi
}
restart () {
stop
start
}
condrestart () {
[ -e /var/lock/subsys/$prog ] && restart || return 0
}
case "$1" in
start)
start
;;
剩余60页未读,继续阅读
THECHINALION
- 粉丝: 0
- 资源: 20
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- zigbee-cluster-library-specification
- JSBSim Reference Manual
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1