Maxscale read-write separation
maxscale installation
Official website configuration file detailed explanation address:
https://mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale/maxscale-configuration-usage-scenarios/#authentication
Installation package maxscale-1.4.3-1.centos.6.x86_64.rpm
# rpm -ivh maxscale-1.4.3-1.centos.6.x86_64.rpm
# mkdir /data/maxscale3306
# cd /data/maxcale3306
# make {cache,data,lang,log}
# cat/etc/maxscale.cnf
[maxscale]
threads=auto ##Number of threads enabled, default is 1. Set to auto, same as CPU core
# Server definitions
maxlog=1 #Write logs to maxscale's log file
log_to_shm=0 #Do not write logs to the shared cache. Speed up can be enabled when debug mode is enabled.
log_warning=1 #Record alarm information
log_notice=1 #log notice
log_info=1 #log info
log_debug=0 #Do not turn on debug mode
#auth_connect_timeout=60 #Default 3 seconds
#auth_read_timeout=60 #Default 1 second
#auth_write_timeout=60 #Default 2 seconds
#localhost_match_wildcard_host=1
logdir=/data/maxscale3306/log/ #Log location
datadir=/data/maxscale3306/data/ #data location
cachedir=/data/maxscale3306/cache/ #cache location
piddir=/data/maxscale3306/ #pid file location
connection_timeout=300 #Connection timeout
max_connections=1000 #Maximum connections
#language=/data/maxscale3306/lang/
# Set the address of the server to the network
# address of a MySQL server.
#
#[server1], and [server2] are master, 223 is master, 224 is slave, there can be multiple in addition to [server3...]
[server1]
type=server
address=192.168.144.223
port=3312
protocol=MySQLBackend
#serversize=10 #weight settings
[server2]
type=server
address=192.168.144.224
port=3310
protocol=MySQLBackend
#serversize=10 #weight settings
# 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] #Monitor information, The monitored user needs to have permission to access replication client on the backend database grant replication slave, replication client on *.* to scalemon@'%' identified by '123456';
type=monitor
module=mysqlmon
servers=server1,server2
user=scalemon
passwd=B7A14BD5A08414AF147BD35CE0F761FC #Encrypted 123456, followed by encryption methods, or not encrypted
monitor_interval=10000 #Monitor heartbeat for 1 second
detect_stale_master=true #When all slave nodes are broken, all reads and writes are directed to the master node
#max_slave_replication_lag=5 #If the delay exceeds 5 seconds, forward the request to other slaves. Here, only two nodes are not open.
# 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 options are all commented out
#[Read-Only Service]
#type=service
#router=readconnroute
#servers=server1,server2
#user=maxscale
#passwd=123456
#router_options=slave
#filters=Hint
#[Hint]
#type=filter
#module=hintfilter
# ReadWriteSplit documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/master/Documentation/Routers/ReadWriteSplit.md
Select ON mysql.tables_priv; Show ASES ON *.* grant select,show databases on mysql.* to maxscale@'%' identified by '123456';
[Read-Write Service]
type=service
router=readwritesplit
servers=server2,server1
router_options=master_accept_reads=false,master_failure_mode=fail_on_write
user=maxscale
passwd=B7A14BD5A08414AF147BD35CE0F761FC #123456 encrypted
max_slave_connections=100% #All slaves provide select query service
use_sql_variables_in=all ###Dynamic parameters can go through all databases [all| master] If it is set to master, the Chinese displayed at the foreground is garbled. Generally, it is recommended to set it to all
#weightby=serversize #weight settings
#enable_root_user=1 #enable root login to execute
auth_all_servers=true #
log_auth_warnings=true #Logging of authentication failures and warnings to record those trying to connect to MaxScale and where they came from
filters=Hint #Force select to go master option, reference: mariadb.com/kb/en/mariadb-enterprise/mariadb-maxscale/maxscale-hint-syntax/ do not know why it is not easy to use, forced also do not go master
[Hint]
type=filter
module=hintfilter
# 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's all commented out, said above
#[Read-Only Listener]
#type=listener
#service=Read-Only Service
#protocol=MySQLClient
#port=4008
[Read-Write Listener]
type=listener
service=Read-Write Service
protocol=MySQLClient
port=4006 #port, program port
[MaxAdmin Listener]
type=listener
service=MaxAdmin Service
protocol=maxscaled
port=6603 #management port
Encryption:
# maxkeys /data/maxscale3306/data/.secrets --Create encrypted files
# maxpasswd /data/maxscale3306/data/.secrets 123456 ---Generate encrypted passwords
B7A14BD5A08414AF147BD35CE0F761FC This is the password in the configuration file
Note: Create the.secrets file for encrypted files in the directory defined by datadir
Start:
# /etc/init.d/maxscale start|stop|restart
Or maxscale -f /etc/maxscale.cnf
# netstat -ntelp | grep max*
Testing:
The test will not be demonstrated
Management:
Default password: mariadb
# maxadmin list servers -pmariadb View current server status
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
server1 | 192.168.144.223 | 3312 | 0 | Master, Running
server2 | 192.168.144.224 | 3310 | 0 | Slave, Running
-------------------+-----------------+-------+-------------+--------------------
# maxadmin list services -pmariadb View current service connections
Services.
--------------------------+----------------------+--------+---------------
Service Name | Router Module | #Users | Total Sessions
--------------------------+----------------------+--------+---------------
Read-Write Service | readwritesplit | 1 | 788
MaxAdmin Service | cli | 2 | 5
--------------------------+----------------------+--------+---------------
# maxadmin list listeners -pmariadb View current running port
Listeners.
---------------------+--------------------+-----------------+-------+--------
Service Name | Protocol Module | Address | Port | State
---------------------+--------------------+-----------------+-------+--------
Read-Write Service | MySQLClient | * | 4006 | Running
MaxAdmin Service | maxscaled | * | 6603 | Running
---------------------+--------------------+-----------------+-------+--------
If you want to change the administrative password, add it to the configuration file
[MaxAdmin]
type=service
router=cli
user=maxscale
passwd=Mhu87p2D