{"id":1518,"date":"2019-08-05T15:50:02","date_gmt":"2019-08-05T18:50:02","guid":{"rendered":"http:\/\/wagnerbianchi.com\/blog\/?p=1518"},"modified":"2021-04-21T18:39:40","modified_gmt":"2021-04-21T21:39:40","slug":"mariadb-maxscale-like-a-pro-setting-up-maxscale-2-3","status":"publish","type":"post","link":"http:\/\/wagnerbianchi.com\/blog\/?p=1518","title":{"rendered":"MariaDB MaxScale like a Pro: Setting up MaxScale 2.3"},"content":{"rendered":"<p>I created this series of blog posts after being worked with the MariaDB MaxScale for many customers. All the points mentioned here reflect my views; I&#8217;ll add links to the online docs so we can have an official reference. I intend to share my experiences working with MaxScale; we need more practical documentation so we improve the MaxScale usage and transfer knowledge.<\/p>\n<p><strong>First of all<\/strong>, MaxScale 2.3 release, notes, <a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb-maxscale-23-mariadb-maxscale-230-release-notes-2018-10-09\/\" target=\"_blank\">take a look<\/a>.<\/p>\n<p>Something you need to know before starting with the praxis here &#8211; all instances are running Debian 9.<\/p>\n<pre>root@prod-mariadb01:~# lsb_release -a\r\nNo LSB modules are available.\r\nDistributor ID:\tDebian\r\nDescription:\tDebian GNU\/Linux 9.9 (stretch)\r\nRelease:\t9.9\r\nCodename:\tstretch<\/pre>\n<p><strong>MariaDB MaxScale in a nutshell&#8230;<\/strong><\/p>\n<p>The MariaDB MaxScale is an intelligent database proxy which understands SQL language and has a bunch of bundle modules known as routers or services, monitors, filters, etc. After setting up the MaxScale packages, you have access to all bundle modules, as you need only to add a basic configuration file and start the service. Since version 2.1, you don&#8217;t need to elaborate a complete configuration file (\/etc\/maxscale.cnf) to start the service. Once you get a configuration file with the global [maxscale] section and at least one service defined, you can start the MaxScale service.<\/p>\n<p>What are we going to be doing for setting up the MariaDB MaxScale?<\/p>\n<ol>\n<li>Add the MariaDB Official Repository;<\/li>\n<li>Create the needed users on the database servers (you will see soon that I&#8217;m considering you already a Master\/Slave running environment);<\/li>\n<li>Create the .secrets file so we can encrypt the passwords for the users on the maxscale.cnf;<\/li>\n<li>Create a basic configuration file for MaxScale and start the process;<\/li>\n<li>Run dynamic commands so we can create a monitor (MariaDBMon), the servers, a listener, and link created servers with the monitor and the service.<\/li>\n<\/ol>\n<p><strong>Moving on&#8230;<\/strong><\/p>\n<p>By chance, you can be running something like below, which is going to give you the global configuration plus the ReadWtiteSplit Router configured as the service to be configured:<\/p>\n<pre>#: This is the basic configuration file we can get in place to start maxscale.\r\n#: Notice that we need yet to come back soon to this file so we can add the service \r\n#: encrypted user password (attention to security matters, no clear text passwords, please)\r\n\r\n[maxscale]\r\nthreads                     = auto\r\nlog_augmentation            = 1\r\nms_timestamp                = 1\r\n\r\n[rwsplit-service]\r\ntype                        = service\r\nrouter                      = readwritesplit\r\nuser                        = maxusr\r\npassword                    = <span style=\"font-weight: 400;\">&lt;add your encrypted maxusr password here&gt;\r\n<span class=\"c-mrkdwn__highlight\">version_string              <\/span>= 5.5.50-MariaDB #:should be used with all 10.1 servers and older<\/span>\r\n<\/pre>\n<p>As we need <em>SOP<\/em> or Standard Operational Procedures for everything we perform, the documentation I have for setting up MaxScale considers to always have two users:<\/p>\n<ul>\n<li><strong>A service user:<\/strong> no matter how many services\/routers you&#8217;re running on a MaxScale instance, you need to have at least one user set for the service. The defined user for service is the maxusr (yes, without the &#8220;e&#8221;, I didn&#8217;t forget that). Once you defined that user, you also need to create it on backends so the MaxScale Router\/Service can connect to backends and forward queries. In this specific scenario, as we&#8217;re speaking about the ReadWriteSplit Router, writes will be sent to the master and reads will be sent to the slaves. You would like to check how the <a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb-maxscale-23-readwritesplit\/#readwritesplit-routing-decisions\" target=\"_blank\">ReadWriteSplit Router Routing Decisions<\/a> work so you can better design your applications;<\/li>\n<li><strong>A monitor user<\/strong>: monitors are modules that monitor the backends, and depending on what you&#8217;re running, you will use one monitor or another. If you running a replication cluster, regular GTID Master\/Slaves replication, you want to use the <a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb-maxscale-23-mariadb-monitor\/#overview\" target=\"_blank\">MariaDBMon<\/a> which is going to give you the automatic operations such as failover\/rejoin and the manual possibility to perform a switchover;<\/li>\n<li><strong>A replication user<\/strong>: as we&#8217;re considering a replication cluster, or a yet simple master\/slave scenario, we need to have a user so MaxScale can configure replication on database servers when needed. It happens when we configure MaxScale to execute a failover in case the master should crash, we run a manual switchover or yet, a rejoin needs to be executed when the old master comes back to the cluster now as a new slave\/replica. If you don&#8217;t create a replication user when configuring the <a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb-maxscale-23-mariadb-monitor\/#overview\" target=\"_blank\">MariaDBMon<\/a>, be aware that the user for your replication will be the one you defined to run the monitor per se, <span style=\"text-decoration: underline;\"><strong>I personally don&#8217;t like that<\/strong><\/span> (don&#8217;t be lazy, \ud83d\ude09 ).<\/li>\n<\/ul>\n<p>Let&#8217;s assume you have a simple Master\/Slave already running, like below:<\/p>\n<pre><strong>#: master\/slave topology<\/strong>\r\nMariaDB MaxScale Servers\r\n--------------------------------------------------------\r\n1. prod_maxscale01 (10.136.87.62\/24 - Mode: Active)\r\n\r\nMariaDB Servers Backends Cluster\r\n--------------------------------------------------------\r\n2. prod_mariadb01 (10.136.88.50\/24 - master)\r\n3. \\__ prod_mariadb02 (10.136.69.104\/24 - slave\/replica)\r\n4. \\__ prod_mariadb03 (10.136.79.28\/24  - slave\/replica)<\/pre>\n<p>As a best practice, always configure the <a href=\"https:\/\/mariadb.com\/kb\/en\/library\/replication-and-binary-log-system-variables\/#report_host\" target=\"_blank\">@@global.report_host<\/a> on all database servers with their names:<\/p>\n<pre>prod-mariadb01 [(none)]&gt; show slave hosts;\r\n+-----------+----------------+------+-----------+\r\n| Server_id | Host           | Port | Master_id |\r\n+-----------+----------------+------+-----------+\r\n|         3 | prod_mariadb03 | 3306 |         1 |\r\n|         2 | prod_mariadb02 | 3306 |         1 |\r\n+-----------+----------------+------+-----------+\r\n2 rows in set (0.000 sec<\/pre>\n<p>Assuming the above MariaDB Servers Backends Cluster already have replication up and running (most of you have an environment like this one), you can just think about how we can add a MaxScale server in the middle of applications and your database servers. Most of the time I&#8217;m going to refer to database servers as backends as per the regular terminology we use after adding a Load Balancer to a database topology.<\/p>\n<p>Doing a quick recap on where we are, we need now to create the users on the master, so, we can see users replicating to slaves and have the same data all around. Also, it&#8217;s good to have the <a href=\"https:\/\/mariadb.com\/kb\/en\/library\/gtid\/#gtid_strict_mode\" target=\"_blank\">@@global.gtid_strict_mode<\/a> set on all the servers so we can keep the binary log files the same on all the servers (MaxScale also likes that).<\/p>\n<p>Below we are creating the users as mentioned before, considering the backends we&#8217;re working with:<\/p>\n<pre>#: maxscale service user\r\nCREATE USER 'maxusr'@'10.136.%' IDENTIFIED BY '123';\r\nGRANT SELECT ON mysql.user TO 'maxusr'@'10.136.%';\r\nGRANT SELECT ON mysql.db TO 'maxusr'@'10.136.%';\r\nGRANT SELECT ON mysql.tables_priv TO 'maxusr'@'10.136.%';\r\nGRANT SHOW DATABASES ON *.* TO 'maxusr'@'10.136.%';\r\nGRANT SELECT ON mysql.roles_mapping TO maxusr@'10.136.%';\r\n\r\n#: maxscale monitor user\r\nCREATE USER 'maxmon'@'10.136.%' IDENTIFIED BY '321';\r\nGRANT RELOAD, SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'maxmon'@'10.136.%';\r\nGRANT CREATE, SELECT, UPDATE, INSERT, DELETE ON maxscale_schema.* TO 'maxmon'@'10.136.%';\r\n\r\n#: replication users  - make sure the below user can connect\r\n#: from all backends to all backends\r\nCREATE USER mariadb@'10.136.%' IDENTIFIED BY '123';\r\nGRANT RELOAD, REPLICATION SLAVE ON *.* TO mariadb@'10.136.%';<\/pre>\n<p>One additional detail here is that if you&#8217;re running the MariaDB Server 10.3.4 or you upgraded from an older version to a newer one, like MariaDB Server 10.3.5, as the user maxmon has the SUPER privilege, the DELETE HISTORY privilege will also be added to the list of GRANTS due to the fact that user should also be able to delete data from the <a href=\"https:\/\/mariadb.com\/kb\/en\/library\/grant\/#table-privileges\" target=\"_blank\" rel=\"noopener\">System Versioned Tables<\/a>.<\/p>\n<p>After creating the above users, we need to go the prod_maxscale01 &#8211; 10.136.87.62 &#8211; as we need to set up the MariaDB Official Repository and setup MaxScale packages:<\/p>\n<pre>#: setting up the repository\r\nroot@prod-maxscale01:~# curl -sS https:\/\/downloads.mariadb.com\/MariaDB\/mariadb_repo_setup | sudo bash\r\n[warning] Found existing file at \/etc\/apt\/sources.list.d\/mariadb.list. Moving to \/etc\/apt\/sources.list.d\/mariadb.list.old_1.\r\n[info] Repository file successfully written to \/etc\/apt\/sources.list.d\/mariadb.list\r\n[info] Adding trusted package signing keys...\r\nExecuting: \/tmp\/apt-key-gpghome.sDa0MNg3Md\/gpg.1.sh --keyserver hkp:\/\/keys.gnupg.net:80 --recv-keys 0x8167EE24 0xE3C94F49 0xcbcb082a1bb943db 0xf1656f24c74cd1d8 0x135659e928c12247\r\ngpg: key 135659E928C12247: \"MariaDB Maxscale &lt;maxscale@googlegroups.com&gt;\" not changed\r\ngpg: key F1656F24C74CD1D8: 4 signatures not checked due to missing keys\r\ngpg: key F1656F24C74CD1D8: \"MariaDB Signing Key &lt;signing-key@mariadb.org&gt;\" not changed\r\ngpg: key CBCB082A1BB943DB: 32 signatures not checked due to missing keys\r\ngpg: key CBCB082A1BB943DB: \"MariaDB Package Signing Key &lt;package-signing-key@mariadb.org&gt;\" not changed\r\ngpg: key CE1A3DD5E3C94F49: 3 signatures not checked due to missing keys\r\ngpg: key CE1A3DD5E3C94F49: \"MariaDB Enterprise Signing Key &lt;signing-key@mariadb.com&gt;\" not changed\r\ngpg: key 70E4618A8167EE24: \"MariaDBManager\" not changed\r\ngpg: Total number processed: 5\r\ngpg:              unchanged: 5\r\nHit:1 http:\/\/security.debian.org stretch\/updates InRelease\r\nIgn:2 http:\/\/mirrors.digitalocean.com\/debian stretch InRelease\r\nHit:3 https:\/\/repos.insights.digitalocean.com\/apt\/do-agent main InRelease\r\nGet:4 http:\/\/mirrors.digitalocean.com\/debian stretch-updates InRelease [91.0 kB]\r\nHit:5 http:\/\/downloads.mariadb.com\/MariaDB\/mariadb-10.4\/repo\/debian stretch InRelease\r\nHit:6 http:\/\/mirrors.digitalocean.com\/debian stretch Release\r\nIgn:7 http:\/\/downloads.mariadb.com\/MaxScale\/2.3\/debian stretch InRelease\r\nHit:8 http:\/\/downloads.mariadb.com\/Tools\/debian stretch InRelease\r\nHit:10 http:\/\/downloads.mariadb.com\/MaxScale\/2.3\/debian stretch Release\r\nHit:9 https:\/\/packagecloud.io\/akopytov\/sysbench\/debian stretch InRelease\r\nFetched 91.0 kB in 0s (106 kB\/s)\r\nReading package lists... Done\r\n[info] Successfully added trusted package signing keys.\r\n\r\n#: setting up packages\r\nroot@prod-maxscale01:~# apt install maxscale maxscale-experimental mariadb-client -y\r\nReading package lists... Done\r\nBuilding dependency tree\r\nReading state information... Done\r\nThe following NEW packages will be installed:\r\n  maxscale maxscale-experimental\r\n0 upgraded, 2 newly installed, 0 to remove and 5 not upgraded.\r\nNeed to get 167 kB\/31.1 MB of archives.\r\nAfter this operation, 143 MB of additional disk space will be used.\r\nGet:1 http:\/\/downloads.mariadb.com\/MaxScale\/2.3\/debian stretch\/main amd64 maxscale-experimental amd64 2.3.11 [167 kB]\r\nFetched 167 kB in 0s (337 kB\/s)\r\nSelecting previously unselected package maxscale.\r\n(Reading database ... 35953 files and directories currently installed.)\r\nPreparing to unpack ...\/maxscale_2.3.11_amd64.deb ...\r\nUnpacking maxscale (2.3.11) ...\r\nSelecting previously unselected package maxscale-experimental.\r\nPreparing to unpack ...\/maxscale-experimental_2.3.11_amd64.deb ...\r\nUnpacking maxscale-experimental (2.3.11) ...\r\nSetting up maxscale (2.3.11) ...\r\nSetting up maxscale-experimental (2.3.11) ...<\/pre>\n<p>Why am I setting up the mariadb-client package also? We need to test access from the MaxScale host to the backends so we can make sure MaxScale configured with the users we created will also be able to access backends. To catch permission or access denied when we execute queries is really bad as we need to recap on everything we did for the set up and it can take some time to review everything. We definitely don&#8217;t want that. Test access and move on.<\/p>\n<p>Now, let&#8217;s create the .secrets and get an encryption version of users passwords:<\/p>\n<pre>#: create the .secrets file\r\nroot@prod_maxscale01:~# maxkeys\r\nGenerating .secrets file in \/var\/lib\/maxscale.\r\n\r\n#: generate the encrypted password for maxusr - this is the service user\r\n#: you are going to need the below-encrypted password for the next question\r\nroot@prod-maxscale01:~# maxpasswd 123 #: maxusr\r\nA0FE98035CFA5EB978337B739E949878\r\n\r\n#: generate the encrypted password for maxmon - this is the monitor user\r\n#: you are going to need the below-encrypted password on next labs\r\nroot@prod-maxscale01:~# maxpasswd 321 #: maxmon\r\nAFB909850E7181E9906159CE45176FAD\r\n\r\n#: generate the encrypted password for the mariadb replication user\r\nroot@prod-maxscale01:~# maxpasswd 123 #: mariadb\r\nA0FE98035CFA5EB978337B739E949878\r\n\r\n#: adjust permissions for the .secrets file\r\nroot@prod-maxscale01:~# chown maxscale:maxscale \/var\/lib\/maxscale\/.secrets\r\n<\/pre>\n<p>With encrypted passwords, we can create a basic configuration file. The below is your \/etc\/maxscale.cnf:<\/p>\n<pre>[maxscale]\r\nthreads                     = auto\r\nlog_augmentation            = 1\r\nms_timestamp                = 1\r\nadmin_host                  = 0.0.0.0\r\nadmin_port                  = 8989\r\n\r\n[rwsplit-service]\r\ntype                        = service\r\nrouter                      = readwritesplit\r\nuser                        = maxusr\r\npassword                    = A0FE98035CFA5EB978337B739E949878\r\n<\/pre>\n<p>Check if the maxscale.service is enabled so it can start with the OS boot and start it. Check the log file afterward:<\/p>\n<pre>#: starting up the maxscale.service\r\nroot@prod-maxscale01:~# systemctl --now enable maxscale.service\r\n\r\nroot@prod-maxscale01:~# tail -n30 \/var\/log\/maxscale\/maxscale.log\r\nMariaDB MaxScale  \/var\/log\/maxscale\/maxscale.log  Mon Aug  5 12:25:54 2019\r\n----------------------------------------------------------------------------\r\n2019-08-05 12:25:54   notice : (mxb_log_set_syslog_enabled): syslog logging is enabled.\r\n2019-08-05 12:25:54   notice : (mxb_log_set_maxlog_enabled): maxlog logging is enabled.\r\n2019-08-05 12:25:54.078   notice : (mxb_log_set_highprecision_enabled): highprecision logging is enabled.\r\n2019-08-05 12:25:54.078   notice : (config_load_global): Using up to 976.56KiB of memory for query classifier cache\r\n2019-08-05 12:25:54.079   notice : (change_cwd): Working directory: \/var\/log\/maxscale\r\n2019-08-05 12:25:54.079   notice : (init_sqlite3): The collection of SQLite memory allocation statistics turned off.\r\n2019-08-05 12:25:54.079   notice : (init_sqlite3): Threading mode of SQLite set to Multi-thread.\r\n2019-08-05 12:25:54.080   notice : (main): MariaDB MaxScale 2.3.11 started (Commit: 36355922281a6820de63b76fb76c9203861e3988)\r\n2019-08-05 12:25:54.080   notice : (main): MaxScale is running in process 13166\r\n2019-08-05 12:25:54.080   notice : (main): Configuration file: \/etc\/maxscale.cnf\r\n2019-08-05 12:25:54.080   notice : (main): Log directory: \/var\/log\/maxscale\r\n2019-08-05 12:25:54.081   notice : (main): Data directory: \/var\/lib\/maxscale\r\n2019-08-05 12:25:54.081   notice : (main): Module directory: \/usr\/lib\/x86_64-linux-gnu\/maxscale\r\n2019-08-05 12:25:54.081   notice : (main): Service cache: \/var\/cache\/maxscale\r\n2019-08-05 12:25:54.082   notice : (load_module): Loaded module qc_sqlite: V1.0.0 from \/usr\/lib\/x86_64-linux-gnu\/maxscale\/libqc_sqlite.so\r\n2019-08-05 12:25:54.082   notice : (qc_setup): Query classification results are cached and reused. Memory used per thread: 976.56KiB\r\n2019-08-05 12:25:54.083   notice : (init): The systemd watchdog is Enabled. Internal timeout = 30s\r\n2019-08-05 12:25:54.083   notice : (config_load_single_file): Loading \/etc\/maxscale.cnf.\r\n2019-08-05 12:25:54.084   notice : (is_directory): \/etc\/maxscale.cnf.d does not exist, not reading.\r\n2019-08-05 12:25:54.084   notice : (mxs_get_module_object): Initializing statement-based read\/write split router module.\r\n2019-08-05 12:25:54.085   notice : (load_module): Loaded module readwritesplit: V1.1.0 from \/usr\/lib\/x86_64-linux-gnu\/maxscale\/libreadwritesplit.so\r\n2019-08-05 12:25:54.085   notice : (qc_sqlite_process_init): Statements that cannot be parsed completely are logged.\r\n2019-08-05 12:25:54.086   notice : (service_launch_all): Starting a total of 1 services...\r\n2019-08-05 12:25:54.086   warning: (serviceStartAllPorts): Service 'rwsplit-service' has no listeners defined.\r\n2019-08-05 12:25:54.086   notice : (service_launch_all): Service 'rwsplit-service' started (1\/1)\r\n2019-08-05 12:25:54.086   notice : (main): Started REST API on [0.0.0.0]:8989\r\n2019-08-05 12:25:54.086   notice : (main): MaxScale started with 1 worker threads, each with a stack size of 8388608 bytes.\r\n2019-08-05 12:25:54.090   notice : (hkthread): Housekeeper thread started.<\/pre>\n<p>Now you have MaxScale up and running! It&#8217;s time for testing the maxusr and maxmon connectivity with backends:<\/p>\n<pre>#: service user access test\r\nroot@prod-maxscale01:~# mysqladmin -u maxusr -p123 -h 10.136.88.50 ping\r\nmysqld is alive\r\nroot@prod-maxscale01:~# mysqladmin -u maxusr -p123 -h 10.136.69.104 ping\r\nmysqld is alive\r\nroot@prod-maxscale01:~# mysqladmin -u maxusr -p123 -h 10.136.79.28 ping\r\nmysqld is alive\r\n\r\n#: monitor user access test\r\nroot@prod-maxscale01:~# mysqladmin -u maxmon -p321 -h 10.136.88.50 ping\r\nmysqld is alive\r\nroot@prod-maxscale01:~# mysqladmin -u maxmon -p321 -h 10.136.69.104 ping\r\nmysqld is alive\r\nroot@prod-maxscale01:~# mysqladmin -u maxmon -p321 -h 10.136.79.28 ping\r\nmysqld is alive<\/pre>\n<p>A final test to make sure everything is really set is to test is you can access all databases from all databases. I don&#8217;t wanna go over the 9! test here, but, it&#8217;s good you go over it and make sure the replication user can access all from all, as replication will be set by MaxScale and you don&#8217;t want to have access denied reported by the IO_THREAD for a new slave configured by MaxScale.<\/p>\n<p>At this point, we have MaxScale running with a basic configuration file and also, basic settings for the ReadWriteSplit Router, which is the only service we have running on MaxScale currently. You can notice that we have configurations on the global [maxscale] section for making it possible to remote access MaxScale using the MaxCtrl. Here I&#8217;m not considering <a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb-maxscale-23-maxadmin-admin-interface\/#maxadmin-admin-interface\" target=\"_blank\" rel=\"noopener\">MaxAdmin as it&#8217;s deprecated on MaxScale 2.3<\/a> and will be removed on M<a href=\"https:\/\/twitter.com\/wagnerbianchijr\/status\/1157399519690199040\" target=\"_blank\" rel=\"noopener\">axScale 2.4<\/a>; this latter, currently in beta.<\/p>\n<p>Currently, you can use MaxCtrl to retrieve basic information like below:<\/p>\n<pre>#: maxscale global configurations\r\nroot@prod-maxscale01:~# maxctrl show maxscale\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u2502 Version      \u2502 2.3.11                                                               \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 Commit       \u2502 36355922281a6820de63b76fb76c9203861e3988                             \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 Started At   \u2502 Mon, 05 Aug 2019 12:25:54 GMT                                        \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 Activated At \u2502 Mon, 05 Aug 2019 12:25:54 GMT                                        \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 Uptime       \u2502 17863                                                                \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 Parameters   \u2502 {                                                                    \u2502\r\n\u2502              \u2502     \"libdir\": \"\/usr\/lib\/x86_64-linux-gnu\/maxscale\",                  \u2502\r\n\u2502              \u2502     \"datadir\": \"\/var\/lib\/maxscale\",                                  \u2502\r\n\u2502              \u2502     \"process_datadir\": \"\/var\/lib\/maxscale\/data13166\",                \u2502\r\n[...snip...]\r\n\u2502              \u2502     \"admin_auth\": true,                                              \u2502\r\n\u2502              \u2502     \"admin_enabled\": true,                                           \u2502\r\n\u2502              \u2502     \"admin_log_auth_failures\": true,                                 \u2502\r\n\u2502              \u2502     \"admin_host\": \"0.0.0.0\",                                         \u2502\r\n\u2502              \u2502     \"admin_port\": 8989,                                              \u2502\r\n\u2502              \u2502     \"admin_ssl_key\": \"\",                                             \u2502\r\n\u2502              \u2502     \"admin_ssl_cert\": \"\",                                            \u2502\r\n\u2502              \u2502     \"admin_ssl_ca_cert\": \"\",                                         \u2502\r\n\u2502              \u2502     \"passive\": false,                                                \u2502\r\n[...snip...]\r\n\u2502              \u2502     \"load_persisted_configs\": true                                   \u2502\r\n\u2502              \u2502 }                                                                    \u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/pre>\n<p>There are lots os commands to retrieve information from MaxScale using the MaxCtrl in communication to the REST API, running now listening on MaxScale host on any interface, as per the `admin_host` variable and on port 8989, as the what is defined at `admin_port`. As we tested the communication with the MaxScale, we can use now MaxCtrl to create the needed objects like a monitor and a listener, add the servers and link them to the monitor and the service. Since MaxScale 2.1 we have a way to do this with Dynamic Commands; the results of the commands will be to create objects and persist them in files created at the &#8211;persistdir. Additionally, a <a href=\"https:\/\/mariadb.com\/kb\/en\/mariadb-maxscale-23-common-monitor-parameters\/#monitor-crash-safety\" target=\"_blank\" rel=\"noopener\">journal file<\/a> will be also kept at the MaxScale &#8211;datadir so it can keep track of the current status of the backends in case the maxscale.service is restarted.<\/p>\n<p>Let&#8217;s create the cluster, follow the below commands so we can do that:<\/p>\n<pre>#: ReadWriteSplit setup Using Dynamic Commands\r\n#: Created by Wagner Bianchi &lt;bianchi@mariadb.com&gt;\r\n#: task: creating the monitor\r\nmaxctrl create monitor replication-monitor mariadbmon --monitor-user=maxmon --monitor-password=AFB909850E7181E9906159CE45176FAD replication_user=mariadb replication_password=A0FE98035CFA5EB978337B739E949878\r\n\r\n#: task: configuring the monitor for the replication cluster\r\nmaxctrl alter monitor replication-monitor monitor_interval          1000 \r\nmaxctrl alter monitor replication-monitor failcount                 3 \r\nmaxctrl alter monitor replication-monitor auto_failover             true \r\nmaxctrl alter monitor replication-monitor auto_rejoin               true\r\nmaxctrl alter monitor replication-monitor enforce_read_only_slaves  true\r\n\r\n#: task: create a listener\r\nmaxctrl create listener rwsplit-service replication-rwsplit-listener 3306\r\n\r\n#: task: create servers\r\nmaxctrl create server prod_mariadb01 10.136.88.50  3306\r\nmaxctrl create server prod_mariadb02 10.136.69.104 3306\r\nmaxctrl create server prod_mariadb03 10.136.79.28  3306\r\n\r\n#: task: link servers with the service\r\nmaxctrl link service rwsplit-service prod_mariadb01\r\nmaxctrl link service rwsplit-service prod_mariadb02\r\nmaxctrl link service rwsplit-service prod_mariadb03\r\n\r\n#: task: link servers with the monitor\r\nmaxctrl link monitor replication-monitor prod_mariadb01\r\nmaxctrl link monitor replication-monitor prod_mariadb02\r\nmaxctrl link monitor replication-monitor prod_mariadb03<\/pre>\n<p>If you executed the above commands while tailing the maxscale.log, you would see many interesting things. At this point, it&#8217;s ready to go:<\/p>\n<pre>root@prod-maxscale01:~# maxctrl list servers\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u2502 Server         \u2502 Address       \u2502 Port \u2502 Connections \u2502 State           \u2502 GTID         \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 prod_mariadb03 \u2502 10.136.79.28  \u2502 3306 \u2502 0           \u2502 Slave, Running  \u2502 0-1-3        \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 prod_mariadb02 \u2502 10.136.69.104 \u2502 3306 \u2502 0           \u2502 Slave, Running  \u2502 0-1-3        \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 prod_mariadb01 \u2502 10.136.88.50  \u2502 3306 \u2502 0           \u2502 Master, Running \u2502 0-1-3        \u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/pre>\n<p>To conclude this blog post, we can do a final test, a sysbench on maxscale server:<\/p>\n<pre>root@prod-maxscale01:~# mysql -u bianchi -p123 -h 10.136.87.62 -e \"create database maxscaledb\" -vvv\r\n--------------\r\ncreate database maxscaledb\r\n--------------\r\n\r\nQuery OK, 1 row affected (0.002 sec)\r\n\r\nBye\r\n\r\nroot@prod-maxscale01:~# sysbench --test=\/usr\/share\/sysbench\/oltp_read_write.lua --table_size=10000 --mysql-db=maxscaledb --tables=20 --mysql-user=bianchi --mysql-password=123 --mysql-port=3306 --mysql-host=10.136.87.62 --db-driver=mysql --threads=32 --events=0 --time=60 --rand-type=uniform --report-interval=1 prepare\r\nsysbench 1.0.17 (using bundled LuaJIT 2.1.0-beta2)\r\n\r\nInitializing worker threads...\r\n\r\nCreating table 'sbtest15'...\r\nCreating table 'sbtest17'...\r\nCreating table 'sbtest16'...\r\nCreating table 'sbtest14'...\r\n[...snip...]\r\nCreating a secondary index on 'sbtest19'...\r\nCreating a secondary index on 'sbtest20'...\r\nCreating a secondary index on 'sbtest16'...\r\nCreating a secondary index on 'sbtest11'...\r\nCreating a secondary index on 'sbtest14'...\r\n\r\nroot@prod-maxscale01:~# sysbench --test=\/usr\/share\/sysbench\/oltp_read_write.lua --table_size=10000 --mysql-db=maxscaledb --tables=20 --mysql-user=bianchi --mysql-password=123 --mysql-port=3306 --mysql-host=10.136.87.62 --db-driver=mysql --threads=32 --events=0 --time=60 --rand-type=uniform --report-interval=1 run &amp;\r\n[1] 15656\r\n\r\nroot@prod-maxscale01:~# maxctrl list servers\r\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\r\n\u2502 Server         \u2502 Address       \u2502 Port \u2502 Connections \u2502 State           \u2502 GTID     \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 prod_mariadb03 \u2502 10.136.79.28  \u2502 3306 \u2502 32          \u2502 Slave, Running  \u2502 0-1-8144 \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 prod_mariadb01 \u2502 10.136.88.50  \u2502 3306 \u2502 32          \u2502 Master, Running \u2502 0-1-8144 \u2502\r\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\r\n\u2502 prod_mariadb02 \u2502 10.136.69.104 \u2502 3306 \u2502 32          \u2502 Slave, Running  \u2502 0-1-8144 \u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/pre>\n<p>Next blog, I will carry on with this same environment as per what was defined here, I will test failover, switchover, and rejoin.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I created this series of blog posts after being worked with the MariaDB MaxScale for many customers. All the points mentioned here reflect my views; I&#8217;ll add links to the online docs so we can have an official reference. I intend to share my experiences working with MaxScale; we need more practical documentation so we [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1518"}],"collection":[{"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1518"}],"version-history":[{"count":22,"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1518\/revisions"}],"predecessor-version":[{"id":1547,"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1518\/revisions\/1547"}],"wp:attachment":[{"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1518"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wagnerbianchi.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}