Installing MaxScale
When logged in as root, create an installation directory for MaxScale, download it and install it:
# cd /usr/local
# mkdir skysql
# cd skysql
# curl https://downloads.skysql.com/files/SkySQL/MaxScale/maxscale.preview.0.4.tar.gz > maxscale.preview.0.4.tar.gz
# tar xvfz maxscale.preview.0.4.tar.gz
# cd maxscale
Now we have MaxScale downloaded, but for maxscale to work, the MAXSCALE_HOME environment variable has to be set up, and to achieve this we, let's create a shell-script that starts MaxScale for us.
# vi maxstart.sh
Then set up this script like this:
#!/bin/bash
#
export MAXSCALE_HOME=/usr/local/skysql/maxscale/MaxScale
$MAXSCALE_HOME/../bin/maxscale
Once we have that script, let's make it executable:
# chmod +x maxstart.sh
Configuring MaxScale
The next step then is to configure MaxScale. The default configuration file for MaxScale is called MaxScale.cnf and is located in the etc directory under where MAXSCALE_HOME is located.
# vi /usr/local/skysql/maxscale/MaxScale/etc/MaxScale.cnf
In this file, each module has it's own section, as well as each server and there is also a section for MaxScale itself. Let's begin with MaxScale which has just one variables that controls the # of threads
MaxScale uses:
[maxscale]
threads=1
Following this, we set up the servers we are to manage here, of which there are three. For every configuration section, except the one for MaxScale core, we have to tell what type of entity we are defining here, in this case it is server:
[srv1]
type=server
address=10.0.0.1
port=3306
protocol=MySQLBackend
[srv2]
type=server
address=10.0.0.2
port=3306
protocol=MySQLBackend
[srv3]
type=server
address=10.0.0.3
port=3306
protocol=MySQLBackend
In addition we define which protocol module to use, and in this case there is not much else than MySQLBackend to choose from. As you can see, we do not define the master or slave properties of the servers, instead we let MaxScale figure that out for us by using a Monitor module, so now is the time to define that.
For the monitor to work, it will connect to the respective MySQL servers so we need to define a username and password for this. In the previous post I created a user for this called maxuser using the password maxpwd. Also, to simplify matters I created this user with full privileges,
[MySQL Monitor]
type=monitor
module=mysqlmon
servers=srv1,srv2,srv3
user=maxuser
passwd=maxpwd
The router we are about to use is the read-write split router, which manages routing writes to the master and reads to the slaves. Let's start with the router that is the central point here:
[RWSplitRouter]
type=service
router=readwritesplit
servers=srv1,srv2,srv3
user=maxuser
passwd=maxpwd
The reason we need to have a username and password even for the router is that this needs to authenticate users connecting to MaxScale itself, and to do that it needs to connect to the server it manages, connect to the mysql database and get the user authorization data from there, which is why we need an account that can access the mysql database.
Now we are close to getting started with MaxScale, what is left is to set up a listener for the router we defined above:
[RWSplitListener]
type=listener
service=RWSplitRouter
protocol=MySQLClient
port=3306
That concludes the configuration of MaxScale!
Testing MaxScale
# ./maxstart.sh
Now we should be able to connect to MaxScale and test that it works. We do this by setting up a MariaDB Client server.
This is set up just like our previous servers, only that we only install the MariaDB client. So set up a server like before, set IPADDR to 10.0.0.4 and run, as root:
# yum install MariaDB-client
I here assume that you have created the t1 table that we used to test replication in the previous post, if not, create it and populate it now:
# mysql -h 10.0.0.5 -u maxuser -pmaxpwd test -e "create table t1(c1 int)"
# mysql -h 10.0.0.5 -u maxuser -pmaxpwd test -e "insert into t1 values(1)"
Now we have a table to test with, so let's see what happens, and let's check that our SELECTs are being routed to our two slaves. We can do that by using the @@server_id variable, which is different
one these two of course:
# mysql -h 10.0.0.5 -u maxuser -pmaxpwd test -e "select c1, @@server_id from t1"
+------+-------------+
| c1 | @@server_id |
+------+-------------+
| 1 | 10 |
+------+-------------+
Cool, this ended up with one of the slaves, so if I try it again, it shoudl end up with the other slave, right:
# mysql -h 10.0.0.5 -u maxuser -pmaxpwd test -e "select c1, @@server_id from t1"
+------+-------------+
| c1 | @@server_id |
+------+-------------+
| 1 | 11 |
+------+-------------+
And if you didn't get the MaxScale to work, like seeing this in the error log:
/usr/local/skysql/maxscale/MaxScale/log/skygw_err1.log:
Couldn't find suitable Slave from 3 candidates.
Or if you can't connect to MaxScale, then the most likely issue is that you didn't stop iptables:
# /etc/init.d/iptables stop
All we done here for setting up some basic load balancing !


0 comments:
Post a Comment