maxscale读写分离
今天,写写mysql兄弟公司maridb开发的一个读写分离,既然是兄弟,那也适用于mysql。
1、安装依赖包
yum -y install gcc gcc-c++ ncurses ncurses-devel cmake
2、下载软件
cd /usr/local
wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.14.tar.gz
3、添加mysql用户和用户组
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
4、解压安装mysql
# 创建数据目录
mkdir -p /data/mysql
# 解压boost
tar xzf boost_1_59_0.tar.gz # 解压mysql,编译安装
tar xzf mysql-5.7..tar.gz
cd mysql-5.7.
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/data/mysql \
-DDOWNLOAD_BOOST= \
-DWITH_BOOST=/usr/local/boost_1_59_0 \
-DSYSCONFDIR=/etc \
-DWITH_INNOBASE_STORAGE_ENGINE= \
-DWITH_PARTITION_STORAGE_ENGINE= \
-DWITH_FEDERATED_STORAGE_ENGINE= \
-DWITH_BLACKHOLE_STORAGE_ENGINE= \
-DWITH_MYISAM_STORAGE_ENGINE= \
-DENABLED_LOCAL_INFILE= \
-DENABLE_DTRACE= \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EMBEDDED_SERVER=1 make
make install
# 复制到启动项
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig mysql on
# 复制配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf # 安装
/usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
5、添加环境变量
cd ~ vi .profile_bash PATH=/usr/local/mysql/bin:$PATH export PATH
6、mysql主从复制(利用gtid特性)
# 关闭selinux和防火墙
systemctl stop firewalld.service
vi /etc/selinux/config
# 配置每个节点配置文件my.cnf
# 添加如下
log-bin=mysql-bin
server-id=
gtid_mode=ON
log_slave_updates
enforce_gtid_consistency
(注:除了server-id每个节点不一样,其它都一样,也必须加,以一般主从复制区别,多了下面的3个参数)
# 主节点添加复制账号
grant replication slave on *.* to 'backup'@'%'identified by'backup';
# 从节点执行
change master to master_host='192.168.10.140', master_user='backup', master_password='backup',master_port=,master_auto_position=;
start slave;
7、maxscale安装
yum install libaio.x86_64 libaio-devel.x86_64 novacom-server.x86_64 libedit -y
MaxScale 的下载地址:
https://downloads.mariadb.com/files/MaxScale rpm -ivh maxscale-beta-2.0.-.centos..x86_64.rpm
创建监控用户
mysql> create user scalemon@'%' identified by "123456"; mysql> grant replication slave, replication client on *.* to scalemon@'%';
创建路由用户
mysql> create user scaleroute@'%' identified by "123456"; mysql> grant select on mysql.* to scaleroute@'%';
用户创建完成后,开始配置
vi /etc/maxscale.cnf
[root@maxscale1 ~]# cat /etc/maxscale.cnf
# MaxScale documentation on GitHub:
# https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Documentation-Contents.md # Global parameters
#
# Complete list of configuration options:
# https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Getting-Started/Configuration-Guide.md [maxscale]
threads=
log_info=
logdir=/tmp/ # Server definitions
#
# Set the address of the server to the network
# address of a MySQL server.
# [server1]
type=server
address=192.168.10.140
port=
protocol=MySQLBackend [server2]
type=server
address=192.168.10.141
port=
protocol=MySQLBackend [server3]
type=server
address=192.168.10.142
port=
protocol=MySQLBackend # Monitor for the servers
#
# This will keep MaxScale aware of the state of the servers.
# MySQL Monitor documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Monitors/MySQL-Monitor.md [MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1,server2,server3
user=scalemon
passwd=
monitor_interval= # Service definitions
#
# Service Definition for a read-only service and
# a read/write splitting service.
# # ReadConnRoute documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Routers/ReadConnRoute.md # [Read-Only Service]
# type=service
# router=readconnroute
# servers=server1
# user=myuser
# passwd=mypwd
# router_options=slave # ReadWriteSplit documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Routers/ReadWriteSplit.md [Read-Write Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=scaleroute
passwd=
max_slave_connections=% # This service enables the use of the MaxAdmin interface
# MaxScale administration guide:
# https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Reference/MaxAdmin.md [MaxAdmin Service]
type=service
router=cli # Listener definitions for the services
#
# These listeners represent the ports the
# services will listen on.
# # [Read-Only Listener]
# type=listener
# service=Read-Only Service
# protocol=MySQLClient
# port= [Read-Write Listener]
type=listener
service=Read-Write Service
protocol=MySQLClient
port= [MaxAdmin Listener]
type=listener
service=MaxAdmin Service
protocol=maxscaled
socket=default
启动
maxscale --config=/etc/maxscale.cnf
[root@maxscale1 ~]# maxadmin -S /tmp/maxadmin.sock
MaxScale> list services
Services.
--------------------------+----------------------+--------+---------------
Service Name | Router Module | #Users | Total Sessions
--------------------------+----------------------+--------+---------------
Read-Write Service | readwritesplit | |
MaxAdmin Service | cli | |
--------------------------+----------------------+--------+---------------
命令也有变化,请自行翻墙到Google查看
MaxScale> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
server1 | 192.168.10.140 | | | Master, Running
server2 | 192.168.10.141 | | | Slave, Running
server3 | 192.168.10.142 | | | Slave, Running
-------------------+-----------------+-------+-------------+--------------------
mysql -h 192.168.10.140 -P4006 -uscalemon -p
mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| maxscale1 |
+------------+
row in set (0.00 sec) 关了一个slave后
MaxScale> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
server1 | 192.168.10.140 | | | Master, Running
server2 | 192.168.10.141 | | | Slave, Running
server3 | 192.168.10.142 | | | Down
-------------------+-----------------+-------+-------------+--------------------
参考,我是开启翻墙的
maxscale读写分离的更多相关文章
- docker环境 mysql读写分离 mycat maxscale
#mysql读写分离测试 环境centos 7.4 ,docker 17.12 ,docker-compose mysql 5.7 主从 mycat 1.6 读写分离 maxscale 2.2.4 读 ...
- MaxScale:实现MySQL读写分离与负载均衡的中间件利器
1. MaxScale 是干什么的? 配置好了 MySQL 的主从复制结构后,我们希望实现读写分离,把读操作分散到从服务器中,并且对多个从服务器能实现负载均衡. 读写分离和负载均衡 是MySQL集群的 ...
- Maxscale安装-读写分离(1)
前言 关于MySQL中间件的产品也很多,之前用过了360的Atlas.玩过MyCat.这边我选择 Maxscale的原因就是功能能满足需求,也看好他的未来发展. 其实有关于如何安装 Maxscale的 ...
- Mysql - 读写分离与读负载均衡之Maxscale
一.概述 常见的高可用方案如MMM和MHA等都将重点放在主库上,一旦主库出现故障,通过这些方案能将主库故障进行转移. 本文将给大家介绍一款由mariadb公司出品的中间件Maxscale,该中间件能实 ...
- Centos7安装maxscale 实现mysql的读写分离
安装依赖 yum install -y novacom-server.x86_64 libaio.x86_64 libaio-devel.x86_64 网站下载 https://downloads.m ...
- MHA + Maxscale 数据库的高可用和读写分离
MySQL 常见发行版本 MySQL 标准化.自动化部署 深入浅出MySQL备份与恢复 深入理解MySQL主从复制 MySQL构架设计与容量规划 MHA Maxscale MySQL 常见发行版本 M ...
- 采用Atlas+Keepalived实现MySQL读写分离、读负载均衡【转载】
文章 原始出处 :http://sofar.blog.51cto.com/353572/1601552 ============================================== ...
- 基于Keepalived高可用集群的MariaDB读写分离机制实现
一 MariaDB读写分离机制 在实现读写分离机制之前先理解一下三种主从复制方式:1.异步复制:MariaDB默认的复制即是异步的,主库在执行完客户端提交的事务后会立即将结果返给给客户端,并不关心从库 ...
- Atlas+Keepalived实现MySQL读写分离、读负载均衡
一.基础介绍 ========================================================================================== 1. ...
随机推荐
- two Pass方法连通域检测
原理: Two-Pass方法检测连通域的原理可参见这篇博客:http://blog.csdn.net/lichengyu/article/details/13986521. 参考下面动图,一目了然. ...
- UITableViewCell滑动删除及移动
实现Cell的滑动删除, 需要实现UITableView的代理UITableViewDelegate中如下方法: //先要设Cell可编辑 - (BOOL)tableView:(UITableView ...
- Java XML 序列化和反序列化
Utils 类: import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWr ...
- 洛谷P1233 [木棍加工]
主要思路: 这道题一眼看过去就可以贪心.. 首先可以按L排序.. 显然排序之后我们就可以抛开L不管了.. 然后就可以愉快的贪心了.. 细节: 这道题可以看成用 最少的合法序列(详见原题) 装下所有木棍 ...
- common-logging--源码之SimpleLog
common-logging源码Log接口 在common-logging的源码中,将log核心类抽象成了一个Log接口. 这里贴出Log接口的源码: /* * Licensed to the Apa ...
- 面向对象之原型——challenge
面向对象之原型 object-oriented面向对象的设计,不同于其他语言,js中的面向对象没有类的概念,因此,其对象也有些特殊. 所谓对象就是无序属性的集合,其属性可以包含基本值.对象.函数.也就 ...
- MySQL基于binlog主从复制
MySQL复制介绍 默认情况 下复制是异步进行的,从库也不需要一直连接到主库来同步数据 MySQL复制的数据粒度可以是主实例上所有的数据库,也可以是指定的一个或多个数据库 ,也可以是一个数据库里的指定 ...
- matlab文件读写处理实例(三)——读取文件特定行
(1) 读取文件特定行 CODE: ; ; if nline==line fprintf(fidout,'%s\n',tline); data ...
- jenkins构建自由风格项目[四]
标签(linux): jenkins 笔者Q:972581034 交流群:605799367.有任何疑问可与笔者或加群交流 构建一个php项目 创建一个新的项目 选择从git获取源码 配置gitlab ...
- 系统uid在1-499的原因
1.因为是保留给系统使用的UID,为了与用户设置的账户区分,防止冲突. 2.并没有其他特别的意义, 3.也叫作虚拟用户,除了0之外,所有的UID在使用上并没有任何区别. 4.linux中文件和程序都要 ...