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. ...
随机推荐
- destoon框架二次开发【整理】
=========================================================== destoon使用中的一些心得 ====================== ...
- dedecms标签大全
今天用了1个小时的时间整理了dedecms标签大全,非常经典,非常经典的织梦dedecms标签,希望对大家制作dedecms网站有帮助 channel_____栏目 dede_arcty ...
- 分析业务模型-类图(Class Diagram)
分析业务模型-类图(Class Diagram) 分析业务模型-类图(Class Diagram)(上) 摘要:类图(Class Diagram)可能是用得最多的一种UML图.类图的基本语法并 ...
- 怎么解决ERROR in Node Sass does not yet support your current environmen问题?
好久没有重新安装node.js,昨天和小伙伴们一起安装,由于自己是在网上自行下载的node,安装地比较顺利,但另外两个小伙伴用的共享文件夹里自带的node,却是屡次碰到问题,快被逼疯,在运行Vue时总 ...
- 【good】在CentOS 6.x上安装GlusterFS
转发:http://quenywell.com/install-glusterfs-on-centos-6-x/ 本文主要介绍如何在CentOS 6.x上快速安装GlusterFS.GlusterFS ...
- ajax请求返回乱码
1,web.xml中有如下配置: <!-- 编码过滤器 --> <filter> <filter-name>encodingFilter</filter-na ...
- MyEclipse设置jsp页默认打开方式
可以用来设置jsp页默认打开是代码编辑模式而不是半视图半代码的模式. 1.选择菜单Window→Preferences. 2.选择General→Editors→File Associations.在 ...
- 学会用git真的很重要
一.首先,作为一名开发人员,目前个人菜鸟一个,觉得有个仓库来管理好自己的项目是真的很重要,而目前个人认为在git上面管理自己的项目是真的很不错的推荐,接下来给大家介绍一下如何使用git上传.管理自己的 ...
- 【转】 C++易混知识点4: 自己编写一个智能指针(Reference Counting)学习auto_ptr和reference counting
这篇文章建大的介绍了如何编写一个智能指针. 介绍: 什么是智能指针?答案想必大家都知道,智能指针的目的就是更好的管理好内存和动态分配的资源,智能指针是一个智能的指针,顾名思义,他可以帮助我们管理内存. ...
- mybatis-spring最新版下载地址
mybatis-spring最新版下载地址: http://mvnrepository.com/artifact/org.mybatis/mybatis-spring/1.2.3 mybatis-sp ...