How to setup MariaDB MaxScale on CentOS 7

Share on Social Media

Learn how to setup MariaDB MaxScale on CentOS 7 with our comprehensive guide. Follow step-by-step instructions to enhance your database scalability, security, and load balancing capabilities. #centlinux #linux #mysql

What is MaxScale?

MaxScale is an intelligent database proxy developed by MariaDB Corporation. MaxScale is free and open source under Business Source License (BSL). MaxScale extends the high availability, load-balancing, scalability and security of MariaDB server and it simplifies the application development by decoupling it from underlying database infrastructure.

How to setup MariaDB MaxScale on CentOS 7
How to setup MariaDB MaxScale on CentOS 7

Read Also: How to install MariaDB MaxScale on Rocky Linux 9

Linux Server Specification

In our previous post “Install MariaDB Galera Cluster on CentOS 7”, we have configured two node MariaDB cluster on CentOS Linux 7 server using Galera. In this article, we will install MariaDB MaxScale database proxy for our Galera cluster.

Besides Galera cluster, we have also provisioned a virtual machine with following specification. This new virtual machine is used as the MaxScale database proxy for our MariaDB cluster.

  • Hostname – maxscale.example.com
  • IP Address – 192.168.116.80/24
  • CPU – 2.4 Ghz (2 cores)
  • Memory – 1 GB
  • Operating System – CentOS 7.6

Recommended Training: The Ultimate MySQL Bootcamp: Go from SQL Beginner to Expert from Colt Steele

1187016 51b3
show?id=oLRJ54lcVEg&bids=1628165

Install MariaDB MaxScale on CentOS 7

Connect to arbitrary node maxscale.example.com using ssh.

Install MariaDB and MaxScale yum repositories.

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash

Output:

[info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo.
[info] Adding trusted package signing keys...
[info] Succeessfully added trusted package signing keys.

Build yum cache.

yum makecache fast

Output:

Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.ges.net.pk
* extras: mirrors.ges.net.pk
* updates: mirrors.ges.net.pk
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
mariadb-main | 2.9 kB 00:00
mariadb-maxscale | 2.4 kB 00:00
mariadb-tools | 2.9 kB 00:00
updates | 3.4 kB 00:00
(1/5): extras/7/x86_64/primary_db | 156 kB 00:01
(2/5): mariadb-tools/7/x86_64/primary_db | 11 kB 00:02
(3/5): mariadb-maxscale/7/x86_64/primary_db | 6.7 kB 00:02
(4/5): mariadb-main/7/x86_64/primary_db | 50 kB 00:03
(5/5): updates/7/x86_64/primary_db | 1.4 MB 00:04
Metadata Cache Created

Install MariaDB MaxScale using yum command.

yum install -y maxscale

Create MySQL User

To setup MariaDB MaxScale communication with Galera Cluster, we need a MySQL database user.

Connect to an instance of MariaDB Galera Cluster and create a user for monitoring and authentication by MaxScale. (Since, our nodes have formed a cluster, therefore, we only need to execute the following commands on any single node).

mysql -u root -p

Output:

Enter password:
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 11
Server version: 10.3.12-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

Execute following commands to create a MaxScale user with necessary privileges to perform it’s function properly.

create user 'maxscale'@'192.168.116.80' identified by '123';
grant select on mysql.user to 'maxscale'@'192.168.116.80';
grant select on mysql.db to 'maxscale'@'192.168.116.80';
grant select on mysql.tables_priv to 'maxscale'@'192.168.116.80';
grant show databases on *.* to 'maxscale'@'192.168.116.80';
flush privileges;

Create a user with privileges to remotely connect from any machine. This user will be used by our application to connect to MariaDB Galera cluster.

create user ahmer@'%' identified by '123';
grant show databases on *.* to ahmer@'%';
flush privileges;
exit

Setup MariaDB MaxScale on Linux

Now, connect to maxscale.example.com and configure MaxScale database proxy.

Edit MaxScale configurations.

mv /etc/maxscale.cnf /etc/maxscale.cnf.old
vi /etc/maxscale.cnf

and add following directives. (Please refer to MaxScale Documentation for more information about MaxScale configuration parameters)

#Global MaxScale Settings
[maxscale]
threads=auto 

#Define Server Nodes 
[mariadb-01]
type=server 
address=192.168.116.81 
port=3306 
protocol=MariaDBBackend 

[mariadb-02]
type=server 
address=192.168.116.82 
port=3306 
protocol=MariaDBBackend 

#Define Monitoring Service 
[Galera-Monitor] 
type=monitor 
module=galeramon 
servers=mariadb-01,mariadb-02 
user=maxscale 
password=123 
monitor_interval=1000 

#Define Galera Service 
[Galera-Service] 
type=service 
router=readconnroute 
router_options=synced 
servers=mariadb-01,mariadb-02 
user=maxscale 
password=123 

#Define Galera Listener 
[Galera-Listener] 
type=listener 
service=Galera-Service 
protocol=MariaDBClient 
port=4306 

#Define Administration Service 
[MaxAdmin-Service] 
type=service 
router=cli 

#Define Administration Listener 
[MaxAdmin-Listener] 
type=listener 
service=MaxAdmin-Service 
protocol=maxscaled 
socket=default 

Configure Linux Firewall

Allow Service Port in Linux Firewall.

firewall-cmd --permanent --add-port=4306/tcp
firewall-cmd --reload

Test MariaDB MaxScale configurations

Start and enable MaxScale service.

systemctl start maxscale.service
systemctl enable maxscale.service

Make some connections from clients to Galera Cluster using ahmer user via MaxScale database proxy.

mysql -h maxscale.example.com -P 4306 -u ahmer -p

Connect to maxscale.example.com using ssh, and use maxadmin command to see status of connections to MariaDB Galera Cluster.

maxadmin

Execute following command at maxadmin prompt.

list servers

Output:

Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
mariadb-01 | 192.168.116.81 | 3306 | 2 | Slave, Synced, Running
mariadb-02 | 192.168.116.82 | 3306 | 3 | Master, Synced, Running
-------------------+-----------------+-------+-------------+--------------------
MaxScale>

The above command shows the status of nodes in MariaDB Galera cluster including the active connections and replication status. You can use help command to get help on a maxadmin command or refer to maxadmin documentation for complete reference.

Read Also: MySQL Database Backup and Restore Techniques

Frequently Asked Questions (FAQs)

What is MariaDB MaxScale?
MariaDB MaxScale is a database proxy that enhances scalability, security, and high availability for MariaDB servers by acting as an intermediary between clients and databases.

What are the prerequisites for installing MaxScale on CentOS 7?
You need a CentOS 7 system with root access, a working MariaDB server setup, and network connectivity between MaxScale and your database servers.

Where can I download MariaDB MaxScale for CentOS 7?
MaxScale can be downloaded from the official MariaDB website or added via the MariaDB repository for easy installation using YUM.

Does MaxScale require configuration before use?
Yes, MaxScale needs a configuration file (maxscale.cnf) to define database servers, monitoring settings, and routing rules before it can start routing queries.

How do I start and manage MaxScale after installation?
MaxScale runs as a service, so you can start, stop, or check its status using systemctl commands (e.g., systemctl start maxscale). Logs are available in /var/log/maxscale/ for troubleshooting.

Final Thoughts

Setting up MariaDB MaxScale on CentOS 7 enables advanced database proxy features such as load balancing, query routing, and high availability for MariaDB clusters.

By installing the required packages, configuring MaxScale with the appropriate service definitions, and integrating it with your backend servers, you’ve built a scalable and resilient data routing layer. Regular monitoring and fine-tuning of MaxScale settings will help maintain optimal performance and ensure seamless failover and traffic management in your MariaDB environment.

Your Linux servers deserve expert care! I provide reliable management and optimization services tailored to your needs. Discover how I can help on Fiverr!

Enhance your database performance and reliability with expert support today!

Looking for something?

6 responses to “How to setup MariaDB MaxScale on CentOS 7”

  1. Krissana Avatar

    #Define Galera Service
    [Galera-Service]
    type=service
    router=readconnroute
    router_options=synced
    servers=mariadb-01,mariadb-02
    user=maxscale
    passwd=123 <– Should be 'password'

  2. Ahmer M Avatar

    Certainly not. Because we have created the database user maxscale with password 123.

  3. hacwa Avatar

    I changed this to password instead of passwd which allowed the service to start

    ● maxscale.service – MariaDB MaxScale Database Proxy
    Loaded: loaded (/usr/lib/systemd/system/maxscale.service; enabled; vendor preset: disabled)
    Active: failed (Result: exit-code) since Thu 2019-12-12 15:57:21 GMT; 3s ago
    Process: 17045 ExecStart=/usr/bin/maxscale (code=exited, status=1/FAILURE)
    Process: 17042 ExecStartPre=/usr/bin/install -d /var/lib/maxscale -o maxscale -g maxscale (code=exited, status=0/SUCCESS)
    Process: 17040 ExecStartPre=/usr/bin/install -d /var/run/maxscale -o maxscale -g maxscale (code=exited, status=0/SUCCESS)

    Dec 12 15:57:21 maxscale maxscale[17047]: Loaded module readconnroute: V2.0.0 from /usr/lib64/maxscale/libreadconnroute.so
    Dec 12 15:57:21 maxscale maxscale[17047]: Unknown parameter 'passwd' for object 'Galera-Service' of type 'service'. Did you mean 'password'?
    Dec 12 15:57:21 maxscale maxscale[17047]: [galeramon] Initialise the MySQL Galera Monitor module.
    Dec 12 15:57:21 maxscale maxscale[17047]: Loaded module galeramon: V2.0.0 from /usr/lib64/maxscale/libgaleramon.so
    Dec 12 15:57:21 maxscale maxscale[17047]: Loaded module MariaDBBackend: V2.0.0 from /usr/lib64/maxscale/libmariadbbackend.so
    Dec 12 15:57:21 maxscale maxscale[17047]: Failed to open, read or process the MaxScale configuration file /etc/maxscale.cnf. Exiting.
    Dec 12 15:57:21 maxscale systemd[1]: maxscale.service: control process exited, code=exited status=1
    Dec 12 15:57:21 maxscale systemd[1]: Failed to start MariaDB MaxScale Database Proxy.
    Dec 12 15:57:21 maxscale systemd[1]: Unit maxscale.service entered failed state.
    Dec 12 15:57:21 maxscale systemd[1]: maxscale.service failed.

  4. Ahmer M Avatar

    Thanks for the correction.

  5. Kajian Islami Avatar

    How to connect maxscale to WordPress sir?

    and which IP do I use for my input in WordPress?

    Thanks

  6. Ahmer M Avatar

    Hi, You can connect Maxscale load balancer to WordPress, in the same way that you connect a stand alone database.

    Only difference is that, you use IP address and Port of MaxScale server here.

Leave a Reply