`
sillycat
  • 浏览: 2488836 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

MySQL HA Solution 2019(4)MaxScale

 
阅读更多
MySQL HA Solution 2019(4)MaxScale

You can find your download from here
https://mariadb.com/downloads/#mariadb_platform-mariadb_maxscale

I choose ubuntu 18.04 for my testing
> wget https://downloads.mariadb.com/MaxScale/2.3.11/ubuntu/dists/bionic/main/binary-amd64/maxscale-2.3.11-1.ubuntu.bionic.x86_64.deb

Here is how I install that
> sudo apt install ./maxscale-2.3.11-1.ubuntu.bionic.x86_64.deb

Go to my MySQL master machine
> mysql -u debian-sys-maint -pG1FEbrOMSORmcaUK
> use mysql;

Create Monitor Account
> create user scalemon@'%' identified by 'kaishi';
> grant replication slave, replication client on *.* to scalemon@'%';

Create Proxy Account
> create user maxscale@'%' identified by 'kaishi';
> grant select on mysql.* to maxscale@'%';

> flush privileges;

Check and Modify the Configuration
> sudo vi /etc/maxscale.cnf
> cat /etc/maxscale.cnf
# MaxScale documentation:
# https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale-23/
# Global parameters
#
# Complete list of configuration options:
# https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-maxscale-configuration-usage-scenarios/
[maxscale]
threads=auto
# Server definitions
#
# Set the address of the server to the network
# address of a MariaDB server.
#
[server1]
type=server
address=ubuntu-master
port=3306
protocol=MariaDBBackend
[server2]
type=server
address=ubuntu-dev5
port=3306
protocol=MariaDBBackend
[server3]
type=server
address=ubuntu-dev6
port=3306
protocol=MariaDBBackend
# Monitor for the servers
#
# This will keep MaxScale aware of the state of the servers.
# MariaDB Monitor documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-monitor/
#[MariaDB-Monitor]
[MySQL-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
user=scalemon
password=kaishi
monitor_interval=10000
# Service definitions
#
# Service Definition for a read-only service and
# a read/write splitting service.
#
# ReadConnRoute documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-23-readconnroute/
#[Read-Only-Service]
#type=service
#router=readconnroute
#servers=server1
#user=myuser
#password=mypwd
#router_options=slave
# ReadWriteSplit documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-23-readwritesplit/
[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=maxscale
password=kaishi
max_slave_connections=100%
# This service enables the use of the MaxAdmin interface
# MaxScale administration guide:
# https://mariadb.com/kb/en/mariadb-maxscale-23-maxadmin-admin-interface/
[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=MariaDBClient
#port=4008
[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MariaDBClient
port=4006
[MaxAdmin-Listener]
type=listener
service=MaxAdmin-Service
protocol=maxscaled
socket=default

Start the service
> maxscale --config=/etc/maxscale.cnf

Some error message in the config
Protocol module 'mysqlclient' has been deprecated, use 'mariadbclient' instead.
error  : Invalid value for parameter 'service' for object 'Read-Only-Listener' of type 'listener': Read-Only-Service (was expecting a service name)
THE 'cli' MODULE AND 'maxadmin' ARE DEPRECATED: Use 'maxctrl' instead
Monitor module 'mysqlmon' has been deprecated, use 'mariadbmon' instead.
error  : Failed to open, read or process the MaxScale configuration file /etc/maxscale.cnf.
error  : Unable to find library for module: maxctrl. Module dir: /usr/lib/x86_64-linux-gnu/maxscale
warning: Protocol module 'mysqlbackend' has been deprecated, use 'mariadbbackend' instead.

Check logging file permission
> sudo chmod 777 -R /var/log/maxscale/
> sudo chmod 777 -R /var/lib/maxscale/
> sudo chmod 777 -R /var/run/maxscale/
> sudo chmod 777 -R /var/cache/maxscale/

Checking the logging, it starts
2019-08-03 12:46:04   notice : Selecting new master server.
2019-08-03 12:46:04   notice : Setting 'server1' as master.
2019-08-03 12:46:04   notice : Server changed state: server1[ubuntu-master:3306]: new_master. [Running] -> [Master, Running]
2019-08-03 12:46:04   notice : Server changed state: server2[ubuntu-dev5:3306]: new_slave. [Running] -> [Slave, Running]
2019-08-03 12:46:04   notice : Server changed state: server3[ubuntu-dev6:3306]: new_slave. [Running] -> [Slave, Running]

I used to have an account mycat/mycat when I test mycat, now, I will try that.
> mysql -h ubuntu-dev5 -P 4006 -u mycat -pmycat

> select @@hostname;
+-------------+
| @@hostname  |
+-------------+
| ubuntu-dev5 |

> start transaction;
> select @@hostname;
+---------------+
| @@hostname    |
+---------------+
| ubuntu-master |

> rollback;
> select @@hostname;
+-------------+
| @@hostname  |
+-------------+
| ubuntu-dev5 |

> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mycat              |
| mysql              |

> use mycat;

> show tables;
+-----------------+
| Tables_in_mycat |
+-----------------+
| mycatuser       |


> insert into mycatuser(id, name) values (1, 'carl');

> select * from mycatuser;
+----+------+
| id | name |
+----+------+
|  1 | carl |

Some tools
> sudo maxadmin enable account carl
> maxadmin -S /var/run/maxscale/maxadmin.sock list servers;
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server             | Address         | Port  | Connections | Status             
-------------------+-----------------+-------+-------------+--------------------
server1            | ubuntu-master   |  3306 |           1 | Master, Running
server2            | ubuntu-dev5     |  3306 |           1 | Slave, Running
server3            | ubuntu-dev6     |  3306 |           1 | Slave, Running


Open logging on all mysql
> sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
general_log_file        = /var/log/mysql/mysql.log
general_log             = 1

Restart the service
> sudo /etc/init.d/mysql restart

Or
> sudo service mysql restart

Checking logging
> sudo tail -f /var/log/mysql/mysql.log


References:
https://www.centos.bz/2018/01/mariadb%E4%B8%BB%E4%BB%8E%E9%85%8D%E7%BD%AE%E4%B8%8Emaxscale%E5%AE%9E%E7%8E%B0mysql%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB/
http://www.ttlsa.com/mysql/maxscale-install-read-write-split/
https://www.jianshu.com/p/95e79ae11a20
https://toutiao.io/posts/zwq2k1/preview
https://yq.aliyun.com/articles/515688/




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics