mysql router 自动failover测试
mysql router 启动服务文件内容:
[root@monitor mysqlrouter]# cat /etc/init.d/mysqlrouter
#! /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
;;
stop)
stop
;;
status)
status -p "$pidfile" $prog
;;
restart)
restart
;;
condrestart|try-restart)
condrestart
;;
reload)
exit 3
;;
force-reload)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|condrestart|try-restart|reload|force-reload}"
exit 2
esac
exit $?
当程序意外被KILL后,有相关程序运行标识,需要先STOP
rm -f $pidfile
rm -f /var/lock/subsys/$prog
再启动,否则程序会提示有一个实例运行而不能运行该服务
/var/lock/subsys目录的作用
实际上,判断是否上锁就是判断这个文件,所以文件存在与否也就隐含了是否上锁。而这个目录的内容并不能表示一定上锁了,因为很多服务在启动脚本里用 touch来创建这个加锁文件,在系统结束时该脚本负责清除锁,这本身就不可靠(比如意外失败导致锁文件仍然存在),我在脚本里一般是结合PID文件(如 果有PID文件的话),从PID文件里得到该实例的PID,然后用ps测试是否存在该PID,从而判断是否真正有这个实例在运行,更加稳妥的方法是用进程 通讯了,不过这样的话单单靠脚本就做不到了。
[root@monitor bin]# cat /etc/mysqlrouter/mysqlrouter.ini
[DEFAULT]
#mkdir -p /var/log/mysql-router
logging_folder = /var/log/mysql-router
plugin_folder = /usr/local/mysql-router/lib/mysqlrouter
runtime_folder = /usr/local/mysql-router [logger]
# 定义日志等级
level = INFO # 一个高可用的标签
[routing:failover]
bind_address = 0.0.0.0
bind_port =
max_connections =
# 目前就支持两种 : read-write 和 read-only
# read-write:用于高可用,用于可读可写
# read-only:用于负载均衡,只读
mode = read-write
# 实际转发的地址
# 第一个socket如果可用,就一直会使用第一个
# 如果第一个socket无法连接了,才会连接到第二个socket
destinations = 10.24.220.70:, 10.169.214.33:
起动: [root@monitor bin]# ./mysqlrouter -c /etc/mysqlrouter/mysqlrouter.ini &
[]
[root@monitor bin]# Logging to /var/log/mysql-router/mysqlrouter.log
^C
[root@monitor bin]# cat Logging to /var/log/mysql-router/mysqlrouter.log
cat: Logging: No such file or directory
cat: to: No such file or directory
-- :: INFO [7f2cb44a4700] [routing:failover] listening on 0.0.0.0:; read-write
-- :: INFO [7f13125a2700] [routing:failover] listening on 0.0.0.0:; read-write
-- :: INFO [7f2816b4a700] [routing:failover] listening on 0.0.0.0:; read-write
-- :: INFO [7fec2b5f4700] [routing:failover] listening on 0.0.0.0:; read-write
-- :: INFO [7ff971019700] [routing:failover] listening on 0.0.0.0:; read-write
[root@monitor bin]# mysql -u root -p123 -h 172.18.14.68^CP -e "show variables like 'server_id'";
[root@monitor bin]# mysql -u root -p -h 10.169.216.172 -P -e "show variables like 'server_id'";
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | |
+---------------+-------+
[root@monitor bin]# mysql -u root -p -h 10.169.216.172 -P -e "show variables like 'server_id'";
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | |
+---------------+-------+ server1:
service mysq.server stop [root@monitor bin]# mysql -u root -p -h 10.169.216.172 -P -e "show variables like 'server_id'";
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | |
+---------------+-------+
[root@monitor bin]# mysql -u root -p -h 10.169.216.172 -P -e "show variables like 'server_id'";
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | |
+---------------+-------+
mysql router 自动failover测试的更多相关文章
- MYSQL router 自动均衡负载
配制文件: /etc/mysqlrouter/mysqlrouter.ini [DEFAULT] logging_folder = /var/log/mysql-router plugin_folde ...
- MySQL高可用方案MHA自动Failover与手动Failover的实践及原理
集群信息 角色 IP地址 ServerID 类型 Master ...
- MySQL Router 测试使用 转
MySQL Router 测试使用 . 特性 MySQL Router 并没有包括一些特别新的特性, 总体上看中规中矩, 不过 first-available 和插件两个特性挺有意思, 后续会进行讲解 ...
- mysql 主从复制以及binlog 测试
###mysql查看binlog日志内容 https://blog.csdn.net/nuli888/article/details/52106910 mysql的binlog日志位置可通过show ...
- MHA自动Failover过程解析(updated) 转
允许转载, 转载时请以超链接形式标明文章原始出处和网站信息 http://www.mysqlsystems.com/2012/03/figure-out-process-of-autofailover ...
- 利用MySQL Router构建读写分离MGR集群
GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 目录 1. 部署MySQL Router 2. 启动mysqlrouter服务 3. 确认读写分离效果 4. 确认只读负载 ...
- 利用XAG在RAC环境下实现GoldenGate自动Failover
概述 在RAC环境下配置OGG,要想实现RAC节点故障时,OGG能自动的failover到正常节点,要保证两点: 1. OGG的checkpoint,trail,BR文件放置在共享的集群文件系统上,R ...
- MySQL Cluster搭建与测试
MySQL Cluster是一个基于NDB Cluster存储引擎的完整的分布式数据库系统.不仅仅具有高可用性,而且可以自动切分数据,冗余数据等高级功能.和Oracle Real Cluster Ap ...
- Redis主从自动failover
Redis主从架构持久化存在一个问题,即前次测试的结论,持久化需要配置在主实例上才能跨越实例保证数据不丢失,这样以来主实例在持久化数据到硬 盘的过程中,势必会造成磁盘的I/O等待,经过实际测试,这个持 ...
随机推荐
- Tableau学习笔记之五
计算用户自定义字段,虽然在Tableau软件中已经加入了很多的数值操作运算,比如平均值,最大值等,但是可以自定义自己需要的数值操作运算. 数值操作可以有以下:预定义函数,百分比,总计,分级等等 1.直 ...
- 叉积判断 POJ1696
// 叉积判断 POJ1696 #include <iostream> #include <algorithm> #include <cstring> #inclu ...
- 题目1437:To Fill or Not to Fill:贪心算法解决加油站选择问题(未解决)
//贪心算法解决加油站选择问题 //# include<iostream> # include<stdio.h> using namespace std; # include& ...
- C++ 之高效使用STL ( STL 算法分类)
http://blog.csdn.net/zhoukuo1981/article/details/3452118
- homework-03 图形化化最大子序列和
你现在使用的代码规范是什么, 和上课前有什么改进? 我们一开始使用的是C++完成的相关程序.本次因为一些原因,改为C#进行编写.因为2013-10-21在VS2012中,所以所有的代码都已经被VS自 ...
- 设置VMWARE通过桥接方式使用主机网卡上网
1 Host-only连接方式 让虚机具有与宿主机不同的各自独立IP地址,但与宿主机位于不同网段,同时为宿主主机新增一个IP地址,且保证该IP地址与各虚机IP地址位于同一网段.最终结果是新建了一个由 ...
- poj 1466 Girls and Boys(二分图的最大独立集)
http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS Memory Limit: 10000K Total Submis ...
- eclispe输入@注解时提示所有注解的设置
修改输入@提示所有的注解提示方法 eclipse下windows-->preference-->java-->editor-->Content Assist下的Enable a ...
- HDU1398Square Coins(母函数)
母函数介绍见另一篇随笔HDU1028Ignatius and the Princess III(母函数) #include<iostream> #include<stdio.h> ...
- MFC编辑框换行实现
MFC中换行实现 在mfc中编辑框允许输入多行时,换行符被表示为<归位><换行>即“\r\n”,用ascii码表示为13 10 如果为编辑框中想要输入换行,就请将编辑框的属性: ...