Deployment
Installation is easy, at least on the latest LTS version of Ubuntu (Trusty, 14.04) which we used for our tests.
Add a public key:
$ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8167EE24 |
deb [arch=amd64] http://downloads.mariadb.com/software/MaxScale/maxscale/DEB trusty main |
$ apt-get update && apt-get install maxscale |
Configuration
Once installed, we need to configure it. Along with installation comes an example configuration file, located in: /usr/local/skysql/maxscale/etc/MaxScale_template.cnf. It gives a nice introduction to the available options, and helps to setup the environment.
MaxScale uses a pluggable architecture with different plugins providing different features. In this post, we will concentrate on the routing part, and for now, leave out other interesting possibilities like query rewriting. MaxScale uses different types of services; monitors, services, listeners and filters.
For our tests we defined two types of routing services:
- ‘router=readwritesplit’, which provides read/write (RW) splitting,
- ‘router=readconnroute’, which provides round-robin-like (RR) kind of access.
[maxscale]threads=4[Galera Monitor]type=monitormodule=galeramonservers=server1,server2,server3user=maxmonpasswd=maxpwdmonitor_interval=10000disable_master_failback=1[qla]type=filtermodule=qlafilteroptions=/tmp/QueryLog[fetch]type=filtermodule=regexfiltermatch=fetchreplace=select[RW]type=servicerouter=readwritesplitservers=server1,server2,server3user=rootpasswd=secretpassmax_slave_connections=100%router_options=slave_selection_criteria=LEAST_CURRENT_OPERATIONS[RR]type=servicerouter=readconnrouterouter_options=syncedservers=server1,server2,server3user=rootpasswd=secretpass[Debug Interface]type=servicerouter=debugcli[CLI]type=servicerouter=cli[RWlistener]type=listenerservice=RWprotocol=MySQLClientaddress=10.69.179.54port=3307[RRlistener]type=listenerservice=RRprotocol=MySQLClientaddress=10.69.179.54port=3308[Debug Listener]type=listenerservice=Debug Interfaceprotocol=telnetdaddress=127.0.0.1port=4442[CLI Listener]type=listenerservice=CLIprotocol=maxscaledaddress=127.0.0.1port=6603[server1]type=serveraddress=10.138.103.93port=3306protocol=MySQLBackend[server2]type=serveraddress=10.139.81.25port=3306protocol=MySQLBackend[server3]type=serveraddress=10.81.192.219port=3306protocol=MySQLBackendThere are couple of interesting bits in the configuration file. As you can see, we had to define user/password pairs several times. Those users are used to check the health of the MySQL nodes and to get access to the list of users defined in the system. For the sake of simplicity we used plain text passwords but it is possible to use hashed passwords for better security.
Finally, since we wanted to compare performance of MaxScale vs HAProxy, we used HAProxy installed from within ClusterControl in a default setup – configured similarly to MaxScale’s RR service.
How does MaxScale work with Galera Cluster?
So, let’s talk about how MaxScale sees the Galera Cluster. MaxScale provides an admin CLI which gives you access to some internal statistics. After the first login (user admin, password skysql), you can check available options by running the ‘help’ command. One of the very useful commands is ‘show servers’, which returns a health status of the cluster. Below is the example output of that command.
$ /usr/local/skysql/maxscale/bin/maxadmin -u adminPassword:MaxScale> show serversServer 0x219bac0 (server1) Server: 10.138.103.93 Status: Slave, Synced, Running Protocol: MySQLBackend Port: 3306 Server Version: 5.6.22-72.0-56-log Node Id: 2 Master Id: -1 Repl Depth: 0 Number of connections: 0 Current no. of conns: 0 Current no. of operations: 0Server 0x20f7da0 (server2) Server: 10.139.81.25 Status: Slave, Synced, Running Protocol: MySQLBackend Port: 3306 Server Version: 5.6.22-72.0-56-log Node Id: 1 Master Id: -1 Repl Depth: 0 Number of connections: 0 Current no. of conns: 0 Current no. of operations: 0Server 0x20f7c90 (server3) Server: 10.81.192.219 Status: Master, Synced, Running Protocol: MySQLBackend Port: 3306 Server Version: 5.6.22-72.0-56-log Node Id: 0 Master Id: -1 Repl Depth: 0 Number of connections: 0 Current no. of conns: 0 Current no. of operations: 0We are interested in the status of the nodes right now – as we can see, we have three nodes ‘Running’, all of them are ‘Synced’. Two were elected as ‘Slave’ and one as a ‘Master’. Those states are what we can use in the configuration file. For example, in RR service we defined the following variable:
router_options=syncedIt means that, at any given time, connections can be routed to any of the nodes, as long as they are in the ‘synced’ state (i.e. not serving as a donor or joining the cluster). On the other hand, the RW service was looking for ‘Slave’ and ‘Master’ states to route traffic accordingly. In case of a master failure, a new node is elected as a new master. Your application needs to reconnect though, MaxScale currently does not provide failover for currently open connections.
What’s worth noting, if you want to setup a RW split, you will need to set the max_slave_connections variable accordingly. By default MaxScale sets it to one and, as a result, only one slave is getting read connections. You can here use a fixed number (2, 5) or a percent of the slave pool (50%, 100%). As we wanted all of our slaves, no matter how many there are out there, to serve the traffic, we set this variable to 100%:
max_slave_connections=100%Another interesting bit is the ‘master’ failover part – when MaxScale detects that a node, elected as a master, is unreachable, it promotes one of the ‘slaves’ to the ‘master’ role. Then, by default, when old ‘master’ comes back online, it is immediately promoted to its old master role. As a result, writes may switch back and forth between different nodes should the ‘master’ start to flap. You can switch this default behavior by adding ‘disable_master_failback=1’ directive to the definition of the monitor service.
In case of any connectivity issues, it’s worth checking log files (by default located in the /usr/local/skysql/maxscale/log/ directory) and the kind of MySQL users MaxScale had detected. The latter can be done from the CLI, using the ‘show dbusers <service>’ command:
MaxScale> show dbusers RWUsers table dataHashtable: 0x2a0c900, size 52 No. of entries: 3 Average chain length: 0.5 Longest chain length: 7User names: sbtest@%, maxmon@%, maxmon@% MaxScale> reload dbusers RWIn general, the CLI gives you some nice options to use. We’ll not go over all of them in this post, but we’d still like to mention some features:
- configuration (at least partially) can be changed on fly and reloaded (reload config command)
- server state can be set from the CLI, which enables a DBA to move writes to a different node in the cluster (set server … command)
- services can be disabled/enabled/restarted from the CLI
helphelp <command> (for example help show) Stay tuned for part two of this post where we will cover the performance
comparison between MaxScale’s different router services and HAProxy.
Không có nhận xét nào:
Đăng nhận xét