If you are like me (let's for everyones sake hope you are not,
though) you like to do things the hard way, in particular when it
comes to testing things. For example when installing things on
your Linux box, just to try them out, you might not want to do a
yum install an rpm -ivh or an apt-get to
have some files spread all over your system, instead you want to
tar xvf some tarball and possibly, if you are in a good
mood or you want to be a nice so you get some gifts for christmas
or maybe because it is just that day, you unpack that tarball in
/usr/local instead of in /home/bofh/junk. And this
will usually get you in some trouble, but as we have already
determined that we are truly bad (maybe we should get a tattoo or
two also, or is the right to death-metal antics reserved for IT
security personel only? Sure seems so) we can ignore that and get
to work.
Here I will show you how to install MariaDB MaxScale from a tar-ball and get it
running, without touching any system directories or anything if
you want to test it or if you, even in production, want to
install it in some non-standard location (like /usr/local.
I actually like to have stuff there, I don't know what's so wrong
with that. I'm a rebel, I know).
To begin with, let's download MariaDB MaxScale tarball (rpm's are
for wussies), for example from mariadb.com where you should
register and then go to "my
portal"->"Downloads"->"MariaDB MaxScale" and download
an appropriate .tar.gz for your operating system of
choice. In my case I download it for CentOS 6 / RHEL 6 and as the
current MariaDB MaxScale version is 1.4.3 I issue the command in
my home directory (/home2/anders):
$ wget https://downloads.mariadb.com/enterprise/<my
tag>/mariadb-maxscale/1.4.3/rhel/6/x86_64/maxscale-1.4.3-1.rhel.6.x86_64.tar.gz
With <my tag> replaced by a generated tag on mariadb.com.
Following this we are stuck with a tarball named
maxscale-1.4.3-1.rhel.6.x86_64.tar.gz and we unpack that
as usual and then create a more readable link to the created
directory:
$ tar xvfz maxscale-1.4.3-1.rhel.6.x86_64.tar.gz
$ ln -s maxscale-1.4.3-1.rhel.6.x86_64 maxscale143
So far nothing magic has happened. The next step is to create a
few directories in our new maxscale143 directory where MariaDB
MaxScale will keep temporary, stuff, logs etc:
$ cd maxscale143
$ mkdir cache data log
The next step after this is to create a MariaDB MaxScale
configuration file. There is a template for this in the
etc subdirectory so we just have to copy that:
$ cp etc/maxscale.cnf.template etc/maxscale.cnf
The supplied config file will start MariaDB MaxScale with just 1
server defined, and unless you have this server running on a
non-standard port or on another machine than the one where
MariaDB MaxScale itself is running, you can leave this
configuration file alone, and if not you have to edit the
[server1] section appropriately.
Another thing to look for is iptables / firewalld settings, but
this you already know about I guess. You might want to turn them
off (which is not recommended at all) or configure it
appropriately. As per the default configuration with MariaDB
MaxScale 1.4.3, ports 4006, 4008 and 6603 will be listened to, so
you configure iptables / firewalld appropriately. And don't turn
them of, do this the right way for once. I turned iptables off by
the way, just to annoy you.
Now, MariaDB MaxScale will connect to the server we defined in
the configuration file above, and we need to allow it to connect
and execute a few commands. There are two users that MariaDB
MaxScale can use, one to connect and get authentication data,
like usernames and passwords, and another separate one to monitor
the state of the server. In the supplied configuration template
these two users use the same account, namely myuser using
mypwd as the password, and this is what I use in the
following where are set up the appropriate user and grant in the
MariaDB server I am connecting to, and also note that I am
assuming that MariaDB MaxScale and the MariaDB server on question
run on the same node. So connect to MariaDB and issue the
following commands:
MariaDB> CREATE USER 'myuser'@'localhost' IDENTIFIED BY
'mypwd';
MariaDB> GRANT SELECT ON mysql.user TO
'myuser'@'localhost';
MariaDB> GRANT SELECT ON mysql.db TO
'myuser'@'localhost';
MariaDB> GRANT SELECT ON mysql.tables_priv TO
'myuser'@'localhost';
MariaDB> GRANT SHOW DATABASES ON *.*TO
'myuser'@'localhost';
MariaDB> GRANT REPLICATION SLAVE ON *.* TO
'myuser'@'localhost';
MariaDB> GRANT REPLICATION CLIENT ON *.* TO
'myuser'@'localhost';
With this in place we are ready to start MariaDB MaxScale, but
this is an itsy bitsy more complex than you think. The issue is
that the default locations for a lot of stuff that MariaDB
MaxScale wants to use is somewhere in the global file system, and
they are also not relative to some basedir as is
conveniently the case with MariaDB server itself. to support
this, instead of putting all this in the global section in the
MariaDB MaxScale config file I'll instead put any necessary
arguments to get MaxScale going on the command line, and for that
I have created three scripts, 1 to set up the environment, one to
start MariaDB MaxScale and one to stop it. Let's start with the
environment one. This is places in the MariaDB MaxScale home
directory (maxscale143) is called maxenv.sh and has the
following contents:
#!/bin/bash
#
MAXSCALE_HOME=$(cd $(dirname $BASH_SOURCE) ; pwd)
PATH=$PATH:$MAXSCALE_HOME/usr/bin
export LD_LIBRARY_PATH=$MAXSCALE_HOME/usr/lib64/maxscale
The next file to create is the script to start MariaDB MaxScale,
this is called startmax.sh, is again placed in the MariaDB
MaxScale root directory and has this content:
#!/bin/bash
#
. `dirname $0`/maxenv.sh
$MAXSCALE_HOME/usr/bin/maxscale \
--config=$MAXSCALE_HOME/etc/maxscale.cnf \
--logdir=$MAXSCALE_HOME/log \
--language=$MAXSCALE_HOME/var/lib/maxscale \
--datadir=$MAXSCALE_HOME/data \
--libdir=$MAXSCALE_HOME/usr/lib64/maxscale \
--piddir=$MAXSCALE_HOME --syslog=no \
--cachedir=$MAXSCALE_HOME/cache
As you can see this invokes maxenv.sh before going on to
start MariaDB MaxScale. The only parameter that I really don't
have to set here, but which I set anyway, again just to be
annoying to the world in general, is --syslog=no as we are only
testing things here and logging to syslog is then not really
appropriate (but it is the default).
All we need now is script to stop MariaDB MaxScale, and for this
create a file called stopmax.sh in the MariaDB MaxScale home
directory with this content:
#!/bin/bash
#
. `dirname $0`/maxenv.sh
if [ -e "$MAXSCALE_HOME/maxscale.pid" ]; then
kill -term `cat $MAXSCALE_HOME/maxscale.pid`
fi
Following this, the one thing that remains to be done is to make
the scripts we just created executable:
$ chmod +x maxenv.sh startmax.sh stopmax.sh
Now we are ready to try things, let's start MariaDB MaxScale
first:
$ ./startmax.sh
And then let's see if we can connect to the MariaDB server
through MariaDB MaxScale:
$ mysql -h 127.0.0.1 -P 4006 -u myuser -pmypwd
Welcome to the MariaDB monitor. Commands end with ; or
\g.
Your MySQL connection id is 6950
Server version: 10.0.0 1.4.3-maxscale MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and
others.
Type 'help;' or '\h' for help. Type '\c' to clear the current
input statement.
MySQL [(none)]>
As you can see, I am not connecting as root here, as this is not
allowed by MariaDB MaxScale by default. Also, I am not connecting
to localhost as that assumes I am connecting using a socket,
which is not what we want to do here.
This is all for today, now I'll need to start my Harley-Davidson
and head down town to hang with the other tough guys (OK, I'm
really taking my beaten-up Ford and pick up the kids from
Kindergarten, I admit it).
Keep on SQL'ing
/Karlsson
Aug
10
2016