<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<article lang="">
  <para/>
  <para/>
  <informaltable frame="all">
    <tgroup cols="3"><tbody><row><entry><para><inlinegraphic fileref="embedded:Image1" width="4.03cm" depth="2.687cm"/></para></entry><entry><para/></entry><entry><para>w: www.mariadb.com</para><para/><para>e: info@mariadb.com</para></entry></row></tbody></tgroup>
  </informaltable>
  <para/>
  <para>
    <anchor id="__DdeLink__35287_615637241"/>
    <anchor id="__DdeLink__35179_615637241"/>
  </para>
  <para/>
  <para>MaxScale</para>
  <para/>
  <para>Configuration &amp; Usage Scenarios</para>
  <para/>
  <para/>
  <para>Mark Riddoch</para>
  <para/>
  <para>Last Updated: 2nd July 2014</para>
  <para/>
  <sect1>
    <title><anchor id="h.own38oq23q1h"/>Contents</title>
    <para/>
    <para>
      <link linkend="">Contents</link>
    </para>
    <para>
      <link linkend="">Document</link>
      <link linkend=""> </link>
      <link linkend="">History</link>
    </para>
    <para>
      <link linkend="">Introduction</link>
    </para>
    <para>
      <link linkend="">Terms</link>
    </para>
    <para>
      <link linkend="">Configuration</link>
    </para>
    <para>
      <link linkend="">Global</link>
      <link linkend=""> </link>
      <link linkend="">Settings</link>
    </para>
    <para>
      <link linkend="">Threads</link>
    </para>
    <para>
      <link linkend="">Service</link>
    </para>
    <para>
      <link linkend="">Router</link>
    </para>
    <para>
      <link linkend="">Filters</link>
    </para>
    <para>
      <link linkend="">Servers</link>
    </para>
    <para>
      <link linkend="">User</link>
    </para>
    <para>
      <link linkend="">Passwd</link>
    </para>
    <para>
      <link linkend="">weightby</link>
    </para>
    <para>
      <link linkend="">Server</link>
    </para>
    <para>
      <link linkend="">Address</link>
    </para>
    <para>
      <link linkend="">Port</link>
    </para>
    <para>
      <link linkend="">Protocol</link>
    </para>
    <para>
      <link linkend="">Monitoruser</link>
    </para>
    <para>
      <link linkend="">MonitorPw</link>
    </para>
    <para>
      <link linkend="">Listener</link>
    </para>
    <para>
      <link linkend="">Service</link>
    </para>
    <para>
      <link linkend="">Protocol</link>
    </para>
    <para>
      <link linkend="">Address</link>
    </para>
    <para>
      <link linkend="">Port</link>
    </para>
    <para>
      <link linkend="">Filter</link>
    </para>
    <para>
      <link linkend="">Module</link>
    </para>
    <para>
      <link linkend="">Options</link>
    </para>
    <para>
      <link linkend="">Other</link>
      <link linkend=""> </link>
      <link linkend="">Parameters</link>
    </para>
    <para>
      <link linkend="">Monitor</link>
    </para>
    <para>
      <link linkend="">Module</link>
    </para>
    <para>
      <link linkend="">Servers</link>
    </para>
    <para>
      <link linkend="">User</link>
    </para>
    <para>
      <link linkend="">Passwd</link>
    </para>
    <para>
      <link linkend="">Protocol</link>
      <link linkend=""> </link>
      <link linkend="">Modules</link>
    </para>
    <para>
      <link linkend="">MySQLClient</link>
    </para>
    <para>
      <link linkend="">MySQLBackend</link>
    </para>
    <para>
      <link linkend="">Telnetd</link>
    </para>
    <para>
      <link linkend="">maxscaled</link>
    </para>
    <para>
      <link linkend="">HTTPD</link>
    </para>
    <para>
      <link linkend="">Router</link>
      <link linkend=""> </link>
      <link linkend="">Modules</link>
    </para>
    <para>
      <link linkend="">Connection</link>
      <link linkend=""> </link>
      <link linkend="">Based</link>
      <link linkend=""> </link>
      <link linkend="">Routing</link>
    </para>
    <para>
      <link linkend="">Statement</link>
      <link linkend=""> </link>
      <link linkend="">Based</link>
      <link linkend=""> </link>
      <link linkend="">Routing</link>
    </para>
    <para>
      <link linkend="">Available</link>
      <link linkend=""> </link>
      <link linkend="">Routing</link>
      <link linkend=""> </link>
      <link linkend="">Modules</link>
    </para>
    <para>
      <link linkend="">Readconnroute</link>
    </para>
    <para>
      <link linkend="">Master</link>
      <link linkend="">/</link>
      <link linkend="">Slave</link>
      <link linkend=""> </link>
      <link linkend="">Replication</link>
      <link linkend=""> </link>
      <link linkend="">Setup</link>
    </para>
    <para>
      <link linkend="">Galera</link>
      <link linkend=""> </link>
      <link linkend="">Cluster</link>
      <link linkend=""> </link>
      <link linkend="">Configuration</link>
    </para>
    <para>
      <link linkend="">Readwritesplit</link>
    </para>
    <para>
      <link linkend="">Master</link>
      <link linkend="">/</link>
      <link linkend="">Slave</link>
      <link linkend=""> </link>
      <link linkend="">Replication</link>
      <link linkend=""> </link>
      <link linkend="">Setup</link>
    </para>
    <para>
      <link linkend="">Debugcli</link>
    </para>
    <para>
      <link linkend="">Debug</link>
      <link linkend=""> </link>
      <link linkend="">CLI</link>
      <link linkend=""> </link>
      <link linkend="">Configuration</link>
    </para>
    <para>
      <link linkend="">CLI</link>
    </para>
    <para>
      <link linkend="">CLI</link>
      <link linkend=""> </link>
      <link linkend="">Configuration</link>
    </para>
    <para>
      <link linkend="">Monitor</link>
      <link linkend=""> </link>
      <link linkend="">Modules</link>
    </para>
    <para>
      <link linkend="">Mysqlmon</link>
    </para>
    <para>
      <link linkend="">Galeramon</link>
    </para>
    <para>
      <link linkend="">Filter</link>
      <link linkend=""> </link>
      <link linkend="">Modules</link>
    </para>
    <para>
      <link linkend="">Statement</link>
      <link linkend=""> </link>
      <link linkend="">Counting</link>
      <link linkend=""> </link>
      <link linkend="">Filter</link>
    </para>
    <para>
      <link linkend="">Query</link>
      <link linkend=""> </link>
      <link linkend="">Log</link>
      <link linkend=""> </link>
      <link linkend="">All</link>
      <link linkend=""> </link>
      <link linkend="">Filter</link>
    </para>
    <para>
      <link linkend="">Regular</link>
      <link linkend=""> </link>
      <link linkend="">Expression</link>
      <link linkend=""> </link>
      <link linkend="">Filter</link>
    </para>
    <para>
      <link linkend="">Tee</link>
      <link linkend=""> </link>
      <link linkend="">Filter</link>
    </para>
    <para>
      <link linkend="">Encrypting</link>
      <link linkend=""> </link>
      <link linkend="">Passwords</link>
    </para>
    <para>
      <link linkend="">Creating</link>
      <link linkend=""> </link>
      <link linkend="">Encrypted</link>
      <link linkend=""> </link>
      <link linkend="">Passwords</link>
    </para>
    <para>
      <link linkend="">Configuration</link>
      <link linkend=""> </link>
      <link linkend="">Updates</link>
    </para>
    <para>
      <link linkend="">Limitations</link>
    </para>
    <para>
      <link linkend="">Authentication</link>
    </para>
    <para>
      <link linkend="">Wildcard</link>
      <link linkend=""> </link>
      <link linkend="">Hosts</link>
    </para>
    <para>
      <link linkend="">Limitations</link>
    </para>
    <para>
      <link linkend="">Error</link>
      <link linkend=""> </link>
      <link linkend="">Reporting</link>
    </para>
    <para/>
    <para/>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.q8c6oow7f5cv"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.fpm61wmsats7"/><anchor id="h.88m40r5skidw"/>Document History</title>
    <para/>
    <informaltable frame="all">
      <tgroup cols="3"><tbody><row><entry><para><anchor id="h.e4bj355l51vg"/>Date</para></entry><entry><para><anchor id="h.g2bmau1ye1ua"/>Change</para></entry><entry><para><anchor id="h.yxkjhmw1p04u"/>Who</para></entry></row><row><entry><para><anchor id="h.3l6u7upuslgl"/>21st July 2013</para></entry><entry><para><anchor id="h.i8hdhztksgls"/>Initial version</para></entry><entry><para><anchor id="h.6wc8a489u56v"/>Mark Riddoch</para></entry></row><row><entry><para><anchor id="h.5o3zr4e9t6tm"/>23rd July 2013</para></entry><entry><para><anchor id="h.71maybn7tdc2"/>Addition of default user and password for a monitor and discussion of monitor user requirements</para><para><anchor id="h.aud61d2ng9xw"/>New monitor documented for Galera clusters</para><para><anchor id="h.5rwb0470q4bk"/>Addition of example Galera cluster configuration</para></entry><entry><para><anchor id="h.dltcv85grgid"/>Mark Riddoch</para></entry></row><row><entry><para>13th November 2013</para></entry><entry><para>state for Galera Monitor is “synced”</para></entry><entry><para>Massimiliano Pinto</para></entry></row><row><entry><para>2nd December 2013</para></entry><entry><para><anchor id="h.xcr3rlrlsjhh"/>Updated the description of the command line arguments to match the code updates.</para><para><anchor id="h.6xdahdds2gpa"/>Improved descriptions and general documentation.</para><para>Enhanced example configurations</para></entry><entry><para>Mark Riddoch</para></entry></row><row><entry><para>6th February 2014</para></entry><entry><para>Added “enable_root_user” as a service parameter</para></entry><entry><para>Massimiliano Pinto</para></entry></row><row><entry><para>7th February 2014</para></entry><entry><para><anchor id="h.erikxlgqyy1o"/>Addition of bind address information</para><para>Clarification of user configuration required for monitoring users and the user needed to fetch the user data</para></entry><entry><para><anchor id="h.h2skhqp3jeqf"/>Mark Riddoch</para></entry></row><row><entry><para>3rd March 2014</para></entry><entry><para>MySQL authentication with hostnames</para></entry><entry><para>Massimiliano Pinto</para></entry></row><row><entry><para>3rd March 2014</para></entry><entry><para>Addition of section that describes authentication requirements and the rules for creating user credentials</para></entry><entry><para>Mark Riddoch</para></entry></row><row><entry><para>28th March 2014</para></entry><entry><para>Unix socket support</para></entry><entry><para>Massimiliano Pinto</para></entry></row><row><entry><para>8th   May   2014</para></entry><entry><para>Added “version_string” parameter in service</para></entry><entry><para>Massimiliano Pinto</para></entry></row><row><entry><para>29th May 2014</para></entry><entry><para>Added troubleshooting section</para></entry><entry><para>Massimiliano Pinto</para></entry></row><row><entry><para>2nd June 2014</para></entry><entry><para><anchor id="h.efpyqzqpisll"/>Correction of some typos, clarification of the meaning of session modification statements and the default user for the CLI.</para><para>Addition of debugcli configuration option for developer and user modes.</para></entry><entry><para>Mark Riddoch</para></entry></row><row><entry><para>4th June 2014</para></entry><entry><para><anchor id="h.8yuafigxh61u"/>Addition of “monitor_interval” for monitors</para></entry><entry><para>Massimiliano Pinto</para></entry></row><row><entry><para>6th June 2014</para></entry><entry><para>Addition of filters sections</para></entry><entry><para>Mark Riddoch</para></entry></row><row><entry><para>27th June 2014</para></entry><entry><para>Addition of server weighting, the configuration for the maxadmin client</para></entry><entry><para>Mark Riddoch</para></entry></row><row><entry><para>2nd July 2014</para></entry><entry><para>Addition of new readwritesplit router options with description and examples.</para></entry><entry><para>Vilho Raatikka</para></entry></row></tbody></tgroup>
    </informaltable>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.g9ymbzaalazf"/><anchor id="h.y6q5rjfrde71"/>Introduction</title>
    <para/>
    <para>The purpose of this document is to describe how to configure MaxScale and to discuss some possible usage scenarios for MaxScale. MaxScale is designed with flexibility in mind, and consists of an event processing core with various support functions and plugin modules that tailor the behaviour of the MaxScale itself. </para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.k498ywyi4d7y"/>Terms</title>
    <para/>
    <informaltable frame="all">
      <tgroup cols="2"><tbody><row><entry><para>Term</para></entry><entry><para>Description</para></entry></row><row><entry><para>service</para></entry><entry><para>A service represents a set of databases with a specific access mechanism that is offered to clients of MaxScale. The access mechanism defines the algorithm that MaxScale will use to direct particular requests to the individual databases.</para></entry></row><row><entry><para>server</para></entry><entry><para>A server represents an individual database server to which a client can be connected via MaxScale.</para></entry></row><row><entry><para>router</para></entry><entry><para>A router is a module within MaxScale that will route client requests to the various database servers which MaxScale provides a service interface to.</para></entry></row><row><entry><para>connection routing</para></entry><entry><para>Connection routing is a method of handling requests in which MaxScale will accept connections from a client and route data on that connection to a single database using a single connection. Connection based routing will not examine individual quests on a connection and it will not move that connection once it is established.</para></entry></row><row><entry><para>statement routing</para></entry><entry><para>Statement routing is a method of handling requests in which each request within a connection will be handled individually. Requests may be sent to one or more servers and connections may be dynamically added or removed from the session.</para></entry></row><row><entry><para>protocol</para></entry><entry><para>A protocol is a module of software that is used to communicate with another software entity within the system. MaxScale supports the dynamic loading of protocol modules to allow for increased flexibility.</para></entry></row><row><entry><para>module</para></entry><entry><para>A module is a separate code entity that may be loaded dynamically into MaxScale to increase the available functionality. Modules are implemented as run-time loadable shared objects.</para></entry></row><row><entry><para>monitor</para></entry><entry><para>A monitor is a module that can be executed within MaxScale to monitor the state of a set of database. The use of an internal monitor is optional, monitoring may be performed externally to MaxScale.</para></entry></row><row><entry><para>listener</para></entry><entry><para>A listener is the network endpoint that is used to listen for connections to MaxScale from the client applications. A listener is associated to a single service, however a service may have many listeners.</para></entry></row><row><entry><para>connection failover</para></entry><entry><para>When a connection currently being used between MaxScale and the database server fails a replacement will be automatically created to another server by MaxScale without client intervention</para></entry></row><row><entry><para>backend database</para></entry><entry><para>A term used to refer to a database that sits behind MaxScale and is accessed by applications via MaxScale.</para></entry></row><row><entry><para>filter</para></entry><entry><para>A module that can be placed between the client and the MaxScale router module. All client data passes through the filter module and may be examined or modified by the filter modules.</para><para/><para>Filters may be chained together to form processing pipelines.</para></entry></row></tbody></tgroup>
    </informaltable>
    <para/>
    <para/>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.vk0ub0w64yy6"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.4o6tqejp081r"/><anchor id="h.ubko889dk8db"/>Configuration</title>
    <para/>
    <para>The MaxScale configuration is read from a file which can be located in a number of placing, MaxScale will search for the configuration file in a number of locations.</para>
    <para/>
    <orderedlist>
      <listitem>
        <para>If the environment variable MAXSCALE_HOME is set then MaxScale will look for a configuration file called MaxScale.cnf in the directory $MAXSCALE_HOME/etc</para>
      </listitem>
      <listitem>
        <para>If MAXSCALE_HOME is not set or the configuration file is not in the location above MaxScale will look for a file in /etc/MaxScale.cnf</para>
      </listitem>
    </orderedlist>
    <para/>
    <para>Alternatively MaxScale can be started with the -c flag and the path of the MaxScale home directory tree.</para>
    <para/>
    <para>An explicit path to a configuration file can be passed by using the -f option to MaxScale.</para>
    <para/>
    <para>The configuration file itself is based on the “ini” file format and consists of various sections that are used to build the configuration, these sections define services, servers, listeners, monitors and global settings.</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.w748vjpky28w"/>Global Settings</title>
    <para>The global settings,  in a section named [MaxScale], allow various parameters that affect MaxScale as a whole to be tuned. Currently the only setting that is supported is the number of threads to use to handle the network traffic. MaxScale will also accept the section name of [gateway] for global settings. This is for backward compatibility with versions prior to the naming of MaxScale.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.cc6sgznkcb5p"/>Threads</title>
    <para>To control the number of threads that poll for network traffic set the parameter threads to a number. It is recommended that you start with a single thread and add more as you find the performance is not satisfactory. MaxScale is implemented to be very thread efficient, so a small number of threads is usually adequate to support reasonably heavy workloads.  Adding more threads may not improve performance and can consume resources needlessly.</para>
    <para/>
    <para># Valid options are:</para>
    <para>#       threads=&lt;number of epoll threads&gt;</para>
    <para>[MaxScale]</para>
    <para>threads=1</para>
    <para/>
    <para>It should be noted that additional threads will be created to execute other internal services within MaxScale, this setting is merely used to configure the number of threads that will be used to manage the user connections.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.7t3508ifyp7e"/>Service</title>
    <para>A service represents the database service that MaxScale offers to the clients. In general a service consists of a set of backend database servers and a routing algorithm that determines how MaxScale decides to send statements or route connections to those backend servers.</para>
    <para/>
    <para>A service may be considered as a virtual database server that MaxScale makes available to its clients.</para>
    <para/>
    <para>Several different services may be defined using the same set of backend servers. For example a connection based routing service might be used by clients that already performed internal read/write splitting, whilst a different statement based router may be used by clients that are not written with this functionality in place. Both sets of applications could access the same data in the same databases.</para>
    <para/>
    <para>A service is identified by a service name, which is the name of the configuration file section and a type parameter of service</para>
    <para/>
    <para>[Test Service]</para>
    <para>type=service</para>
    <para/>
    <para>In order for MaxScale to forward any requests it must have at least one service defined within the configuration file. The definition of a service alone is not enough to allow MaxScale to forward requests however, the service is merely present to link together the other configuration elements.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.jmc3h9lmhkvo"/>Router</title>
    <para>The router parameter of a service defines the name of the router module that will be used to implement the routing algorithm between the client of MaxScale and the backend databases. Additionally routers may also be passed a comma separated list of options that are used to control the behaviour of the routing algorithm. The two parameters that control the routing choice are router and router_options. The router options are specific to a particular router and are used to modify the behaviour of the router. The read connection router can be passed options of master, slave or synced, an example of configuring a service to use this router and limiting the choice of servers to those in slave state would be as follows.</para>
    <para/>
    <para>router=readconnroute</para>
    <para>router_options=slave</para>
    <para/>
    <para>To change the router to connect on to servers in the  master state as well as slave servers, the router options can be modified to include the master state.</para>
    <para/>
    <para>router=readconnroute</para>
    <para>router_options=master,slave</para>
    <para/>
    <para>A more complete description of router options and what is available for a given router is included with the documentation of the router itself. </para>
  </sect1>
  <sect1>
    <title><anchor id="h.yy2uxdpf8a2h"/>Filters</title>
    <para>The filters option allow a set of filters to be defined for a service; requests from the client are passed through these filters before being sent to the router for dispatch to the backend server.  The filters parameter takes one or more filter names, as defined within the filter definition section of the configuration file. Multiple filters are separated using the | character.</para>
    <para/>
    <para>filters=counter | QLA</para>
    <para/>
    <para>The requests pass through the filters from left to right in the order defined in the configuration parameter.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.5ls02rb3i8o6"/>Servers</title>
    <para>The servers parameter in a service definition provides a comma separated list of the backend servers that comprise the service. The server names are those used in the name section of a block with a type parameter of server (see below).</para>
    <para/>
    <para>servers=server1,server2,server3</para>
  </sect1>
  <sect1>
    <title><anchor id="h.fo8xmknd8dhy"/>User</title>
    <para>The user parameter, along with the passwd parameter are used to define the credentials used to connect to the backend servers to extract the list of database users from the backend database that is used for the client authentication.</para>
    <para/>
    <para>user=maxscale</para>
    <para>passwd=Mhu87p2D</para>
    <para/>
    <para>Authentication of incoming connections is performed by MaxScale itself rather than by the database server to which the client is connected. The client will authenticate itself with MaxScale, using the username, hostname and password information that MaxScale has extracted from the backend database servers. For a detailed discussion of how this impacts the authentication process please see the “Authentication” section below.</para>
    <para/>
    <para>The host matching criteria is restricted to IPv4, IPv6 will be added in a future release.</para>
    <para/>
    <para>Existing user configuration in the backend databases must be checked and may be updated before successful MaxScale authentication:</para>
    <para/>
    <para/>
    <para>In order for MaxScale to obtain all the data it must be given a username it can use to connect to the database and retrieve that data. This is the parameter that gives MaxScale the username to use for this purpose.</para>
    <para/>
    <para>The account used must be able to select from the mysql.user table, the following is an example showing how to create this user.</para>
    <para/>
    <para>MariaDB [mysql]&gt; create user 'maxscale'@'maxscalehost' identified by 'Mhu87p2D';</para>
    <para>Query OK, 0 rows affected (0.01 sec)</para>
    <para/>
    <para>MariaDB [mysql]&gt; grant SELECT on mysql.user to 'maxscale'@'maxscalehost';</para>
    <para>Query OK, 0 rows affected (0.00 sec)</para>
  </sect1>
  <sect1>
    <title><anchor id="h.vrlqacwiw4jg"/>Passwd</title>
    <para>The auth parameter provides the password information for the above user and may be either a plain text password or it may be an encrypted password.  See the section on encrypting passwords for use in the MaxScale.cnf file. This user must be capable of connecting to the backend database and executing the SQL statement “SELECT user, host, password FROM mysql.user”.</para>
    <para/>
    <para>enable_root_user</para>
    <para>This parameter controls the ability of the root user to connect to MaxScale and hence onwards to the backend servers via MaxScale.</para>
    <para/>
    <para>The default value is 0, disabling the ability of the root user to connect to MaxScale.</para>
    <para/>
    <para>Example for enabling root user:</para>
    <para>enable_root_user=1</para>
    <para/>
    <para>Values of “on” or “true” may also be given to enable the root user and “off” or “false” may be given to disable the use of the root user.</para>
    <para>enable_root_user=true</para>
    <para/>
    <para>version_string</para>
    <para>This parameter sets a custom version string that is sent in the MySQL Handshake from MaxScale to clients.</para>
    <para/>
    <para>Example: </para>
    <para>version_string=5.5.37-MariaDB-RWsplit</para>
    <para/>
    <para>If not set, the default value is the server version of the embedded MySQL/MariaDB library. Example: 5.5.35-MariaDB</para>
  </sect1>
  <sect1>
    <title><anchor id="h.xj2swtiaru1h"/>weightby</title>
    <para>The weightby parameter is used in conjunction with server parameters in order to control the load balancing applied in the router in use by the service. This allows varying weights to be applied to each server to create a non-uniform distribution of the load amongst the servers.</para>
    <para/>
    <para>An example of this might be to define a parameter for each server that represents the amount of resource available on the server, we could call this serversize. Every server should then have a serversize parameter set for the server.</para>
    <para/>
    <para>serversize=10</para>
    <para/>
    <para>The service would then have the parameter weightby set. If there are 4 servers defined in the service, serverA, serverB, serverC and serverD, with the serversize set as shown in the table below, the connections would balanced using the percentages in this table.</para>
    <para/>
    <informaltable frame="all">
      <tgroup cols="4"><colspec colnum="1" colname="c1"/><colspec colnum="2" colname="c2"/><colspec colnum="3" colname="c3"/><colspec colnum="4" colname="c4"/><tbody><row><entry><para>Server</para></entry><entry><para>serversize</para></entry><entry><para>% connections</para></entry></row><row><entry><para>serverA</para></entry><entry><para>10</para></entry><entry><para>18%</para></entry></row><row><entry><para>serverB</para></entry><entry><para>15</para></entry><entry><para>27%</para></entry></row><row><entry><para>serverC</para></entry><entry><para>10</para></entry><entry><para>18%</para></entry></row><row><entry><para>serverD</para></entry><entry><para>20</para></entry><entry><para>36%</para></entry></row></tbody></tgroup>
    </informaltable>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.kd35wrn1e1ws"/>Server</title>
    <para/>
    <para>Server sections are used to define the backend database servers that can be formed into a service. A server may be a member of one or more services within MaxScale. Servers are identified by a server name which is the section name in the configuration file. Servers have a type parameter of server, plus address port and protocol parameters.</para>
    <para/>
    <para>[server1]</para>
    <para>type=server</para>
    <para>address=127.0.0.1</para>
    <para>port=3000</para>
    <para>protocol=MySQLBackend</para>
  </sect1>
  <sect1>
    <title><anchor id="h.cxj4lm9g1sy8"/>Address</title>
    <para>The IP address or hostname of the machine running the database server that is being defined. MaxScale will use this address to connect to the backend database server.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.ciwlfjhbqadx"/>Port</title>
    <para>The port on which the database listens for incoming connections. MaxScale will use this port to connect to the database server.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.5bsc6nq0s7v"/>Protocol</title>
    <para>The name for the protocol module to use to connect MaxScale to the database. Currently only one backend protocol is supported, the MySQLBackend module.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.3h2ruf9uyi6h"/>Monitoruser</title>
    <para>The monitor has a username and password that is used to connect to all servers for monitoring purposes, this may be overridden by supplying a monitoruser statement for each individual server</para>
    <para/>
    <para>monitoruser=mymonitoruser</para>
  </sect1>
  <sect1>
    <title><anchor id="h.mea194zh1ok7"/>MonitorPw</title>
    <para>The monitor has a username and password that is used to connect to all servers for monitoring purposes, this may be overridden by supplying a monpasswd statement for the individual servers</para>
    <para/>
    <para>monitorpw=mymonitorpasswd</para>
    <para/>
    <para>The monpasswd parameter may be either a plain text password or it may be an encrypted password.  See the section on encrypting passwords for use in the MaxScale.cnf file. </para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.klgpjo2v8n3j"/>Listener</title>
    <para/>
    <para>The listener defines a port and protocol pair that is used to listen for connections to a service. A service may have multiple listeners associated with it, either to support multiple protocols or multiple ports. As with other elements of the configuration the section name is the listener name and a type parameter is used to identify the section as a listener definition.</para>
    <para/>
    <para>[Test Listener]</para>
    <para>type=listener</para>
    <para>service=Test Service</para>
    <para>protocol=MySQLClient</para>
    <para>address=localhost</para>
    <para>port=4008</para>
    <para>socket=/tmp/testlistener.sock</para>
  </sect1>
  <sect1>
    <title><anchor id="h.fq271s2tm13u"/>Service</title>
    <para>The service to which the listener is associated. This is the name of a service that is defined elsewhere in the configuration file.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.fcq6bkajtpth"/>Protocol</title>
    <para>The name of the protocol module that is used for the communication between the client and MaxScale itself.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.7f2ts045r69r"/>Address</title>
    <para>The address option sets the address that will be used to bind the listening socket. The address may be specified as an IP address in ‘dot notation’ or as a hostname. If the address option is not included in the listener definition the listener will bind to all network interfaces.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.qpt43h1jgrjt"/>Port</title>
    <para>The port to use to listen for incoming connections to MaxScale from the clients. If the port is omitted from the configuration a default port for the protocol will be used.</para>
    <para/>
    <para>Socket</para>
    <para>The socket option may be included in a listener definition, this configures the listener to use Unix domain sockets to listen for incoming connections. The parameter value given is the name of the socket to use.</para>
    <para/>
    <para>If a socket option and an address option is given then the listener will listen on both the specific IP address and the Unix socket.</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.d83gvvdu0a6u"/>Filter</title>
    <para>Filters provide a means to manipulate or process requests as they pass through MaxScale between the client side protocol and the query router. A filter should be defined in a section with a type of filter.</para>
    <para/>
    <para>[QLA]</para>
    <para>type=filter</para>
    <para>module=qlafilter</para>
    <para>options=/tmp/QueryLog</para>
    <para/>
    <para>The section name may then be used in one or more services by using the filters= parameter in the service section. In order to use the above filter for a service called “QLA Service”, an entry of the following form would exist for that service.</para>
    <para/>
    <para>[QLA Service]</para>
    <para>type=service</para>
    <para>router=readconnroute</para>
    <para>router_options=slave</para>
    <para>servers=server1,server2,server3,server4</para>
    <para>user=massi</para>
    <para>passwd=6628C50E07CCE1F0392EDEEB9D1203F3</para>
    <para>filters=QLA</para>
    <para/>
    <para>See the Services section for more details on how to configure the various options of a service.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.yzitu3tel4mc"/>Module</title>
    <para>The module parameter defines the name of the loadable module that implements the filter.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.z2uocwc6sxb7"/>Options</title>
    <para>The options parameter is used to pass options to the filter to control the actions the filter will perform. The values that can be passed differ between filter implementation, the inclusion of an options parameter is optional.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.hf5x5mwdf6p9"/>Other Parameters</title>
    <para>Any other parameters present in the filters section will be passed to the filter to be interpreted by the filter. An example of this is the regexfilter that requires the two parameters match and replace</para>
    <para/>
    <para>[regex]</para>
    <para>type=filter</para>
    <para>module=regexfilter</para>
    <para>match=form</para>
    <para>replace=from</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.i06or51fzsfy"/>Monitor</title>
    <para/>
    <para>In order for the various router modules to function correctly they require information about the state of the servers that are part of the service they provide. MaxScale has the ability to internally monitor the state of the back-end database servers or that state may be feed into MaxScale from external monitoring systems. If automated monitoring and failover of services is required this is achieved by running a monitor module that is designed for the particular database architecture that is in use.</para>
    <para/>
    <para>Monitors are defined in much the same way as other elements in the configuration file, with the section name being the name of the monitor instance and the type being set to monitor.</para>
    <para/>
    <para>[MySQL Monitor]</para>
    <para>type=monitor</para>
    <para>module=mysqlmon</para>
    <para>servers=server1,server2,server3</para>
    <para>user=dbmonitoruser</para>
    <para>passwd=dbmonitorpwd</para>
    <para>monitor_interval=8000</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.gp2tqaepqn7z"/>Module</title>
    <para>The module parameter defines the name of the loadable module that implements the monitor. This module is loaded and executed on a separate thread within MaxScale. </para>
  </sect1>
  <sect1>
    <title><anchor id="h.ivnmlnywz8ns"/>Servers</title>
    <para>The servers parameter is a comma separated list of server names to monitor, these are the names defined elsewhere in the configuration file. The set of servers monitored by a single monitor need not be the same as the set of servers used within any particular server, a single monitor instance may monitor servers in multiple servers.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.3et4j1l44lwu"/>User</title>
    <para>The user parameter defines the username that the monitor will use to connect to the monitored databases. Depending on the monitoring module used this user will require specific privileges in order to determine the state of the nodes, details of those privileges can be found in the sections on each of the monitor modules.</para>
    <para/>
    <para>Individual servers may define override values for the user and password the monitor uses by setting the monuser and monpasswd parameters in the server section.</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.ipwrd09imfrk"/>Passwd</title>
    <para>The password parameter may be either a plain text password or it may be an encrypted password. See the section on encrypting passwords for use in the MaxScale.cnf file. </para>
    <para/>
    <para>Monitor_interval</para>
    <para>The monitor_interval parameter sets the sampling interval in milliseconds for each monitor, the default value is 10000 milliseconds.</para>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.69fdt08mh3yp"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.y6n2m34i2k5c"/><anchor id="h.ygst0hfs8omz"/>Protocol Modules</title>
    <para>The protocols supported by MaxScale are implemented as external modules that are loaded dynamically into the MaxScale core. These modules reside in the directory $MAXSCALE_HOME/module, if the environment variable $MAXSCALE_HOME is not set it defaults to /usr/local/skysql/MaxScale. It may also be set by passing the -c option on the MaxScale command line.</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.a4918nf156ek"/>MySQLClient</title>
    <para/>
    <para>This is the implementation of the MySQL protocol that is used by clients of MaxScale to connect to MaxScale.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.rldj49cubl6i"/>MySQLBackend</title>
    <para/>
    <para>The MySQLBackend protocol module is the implementation of the protocol that MaxScale uses to connect to the backend MySQL, MariaDB and Percona Server databases. This implementation is tailored for the MaxScale to MySQL Database traffic and is not a general purpose implementation of the MySQL protocol.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.58d5zioxsja5"/>Telnetd</title>
    <para/>
    <para>The telnetd protocol module is used for connections to MaxScale itself for the purposes of creating interactive user sessions with the MaxScale instance itself. Currently this is used in conjunction with a special router implementation, the debugcli.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.jdto0yzavzc9"/>maxscaled</title>
    <para>The protocol used used by the maxadmin client application in order to connect to MaxScale and access the command line interface.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.duyws6hxz60c"/>HTTPD</title>
    <para/>
    <para>This protocol module is currently still under development, it provides a means to create HTTP connections to MaxScale for use by web browsers or RESTful API clients.</para>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.jt9twr1lq0ka"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.gf20q4cljo58"/><anchor id="h.zgwd621heux4"/>Router Modules</title>
    <para>The main task of MaxScale is to accept database connections from client applications and route the connections or the statements sent over those connections to the various services supported by MaxScale.</para>
    <para/>
    <para>There are two flavours of routing that MaxScale can perform, connection based routing and statement based routine. These each have their own characteristics and costs associated with them.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.o5rkohp32mbd"/>Connection Based Routing</title>
    <para/>
    <para>Connection based routing is a mechanism by which MaxScale will, for each incoming connection decide on an appropriate outbound server and will forward all statements to that server without examining the internals of the statement. Once an inbound connection is associated to a particular backend database it will remain connected to that server until the connection is closed or the server fails.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.d8vwkqs1j4ew"/>Statement Based Routing</title>
    <para/>
    <para>Statement based routing is somewhat different, the routing modules examine every statement the client sends and determines, on a per statement basis, which of the set of backend servers in the service is best to execute the statement. This gives better dynamic balancing of the load within the cluster but comes at a cost. The query router must understand the statement that is being routing and will typically need to parse the statement in order to achieve this. This parsing within the router adds a significant overhead to the cost of routing and makes this type of router only really suitable for loads in which the gains outweigh this added cost.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.x51co1biupg7"/>Available Routing Modules</title>
    <para/>
    <para>Currently a small number of query routers are available, these are in different stages of completion and offer different facilities.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.j90bj6uoru33"/>Readconnroute</title>
    <para>This is a statement based query router that was originally targeted at environments in which the clients already performed splitting of read and write queries into separate connections.</para>
    <para/>
    <para>Whenever a new connection is received the router will examine the state of all the servers that form part of the service and route the connection to the server with least connections currently that matches the filter constraints given in the router options. This results in a balancing of the active connections, however different connections may have different lifetimes and the connections may become unbalanced when later viewed.</para>
    <para/>
    <para>The readconnroute router can be configured to balance the connections from the clients across all the backend servers that are running, just those backend servers that are currently replication slaves or those that are replication masters when routing to a master slave replication environment. When a Galera cluster environment is in use the servers can be filtered to just the set that are part of the cluster and in the ‘synced’ state. These options are configurable via the router_options that can be set within a service. The router_option strings supported are “master”, “slave” and “synced”.</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.wtxa4l6bwnfm"/>Master/Slave Replication Setup</title>
    <para/>
    <para>To setup MaxScale to route connections evenly between all the current slave servers in a replication cluster, a service entry of the form shown below is required.</para>
    <para/>
    <para>[Read Service]</para>
    <para>type=service</para>
    <para>router=readconnroute</para>
    <para>router_options=slave</para>
    <para>servers=server1,server2,server3,server4</para>
    <para>user=maxscale</para>
    <para>auth=thepasswd</para>
    <para/>
    <para>With the addition of a listener for this service, which defines the port and protocol that MaxScale uses</para>
    <para>[Read Listener]</para>
    <para>type=listener</para>
    <para>service=Read Service</para>
    <para>protocol=MySQLClient</para>
    <para>port=4006</para>
    <para/>
    <para>the client can now connect to port 4006 on the host which is running MaxScale. Statements sent using this connection will then be routed to one of the slaves in the server set defined in the Read Service. Exactly which is selected will be determined by balancing the number of connections to each of those whose current state is “slave”.</para>
    <para/>
    <para>Altering the router options to be slave, master would result in the connections being balanced between all the servers within the cluster.</para>
    <para/>
    <para>It is assumed that the client will have a separate connection to the master server, however this can be routed via MaxScale, allowing MaxScale to manage the determination of which server is master. To do this you would add a second service and listener definition for the master server.</para>
    <para/>
    <para>[Write Service]</para>
    <para>type=service</para>
    <para>router=readconnroute</para>
    <para>router_options=master</para>
    <para>servers=server1,server2,server3,server4</para>
    <para>user=maxscale</para>
    <para>auth=thepasswd</para>
    <para/>
    <para>[Write Listener]</para>
    <para>type=listener</para>
    <para>service=Write Service</para>
    <para>protocol=MySQLClient</para>
    <para>port=4007</para>
    <para/>
    <para>This allows the clients to direct write requests to port 4007 and read requests to port 4006 of the MaxScale host without the clients needing to understand the configuration of the Master/Slave replication cluster.</para>
    <para/>
    <para>Connections to port 4007 would automatically be directed to the server that is the master for replication at the time connection is opened. Whilst this is a simple mapping to a single server it does give the advantage that the clients have no requirement to track which server is currently the master, devolving responsibility for managing the failover to MaxScale.</para>
    <para/>
    <para>In order for MaxScale to be able to determine the state of these servers the mysqlmon monitor module should be run against the set of servers that comprise the service.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.ekf2nk2y5rdv"/>Galera Cluster Configuration</title>
    <para/>
    <para>Although not primarily designed for a multi-master replication setup, it is possible to use the readconnroute in this situation.  The readconnroute connection router can be used to balance the connections across a Galera cluster. A special monitor is available that detects if nodes are joined to a Galera Cluster, with the addition of a router option to only route connections to nodes marked as synced. MaxScale can ensure that users are never connected to a node that is not a full cluster member.</para>
    <para/>
    <para>[Galera Service]</para>
    <para>type=service</para>
    <para>router=readconnroute</para>
    <para>router_options=synced</para>
    <para>servers=server1,server2,server3,server4</para>
    <para>user=maxscale</para>
    <para>auth=thepasswd</para>
    <para/>
    <para>[Galera Listener]</para>
    <para>type=listener</para>
    <para>service=Galera Service</para>
    <para>protocol=MySQLClient</para>
    <para>port=3336</para>
    <para/>
    <para>[Galera Monitor]</para>
    <para>type=monitor</para>
    <para>module=galeramon</para>
    <para>servers=server1,server2,server3,server4</para>
    <para>user=galeramon</para>
    <para>passwd=galeramon</para>
    <para/>
    <para/>
    <para>The specialized Galera monitor can also select one of the node in the cluster as master, the others will be marked as slave.</para>
    <para>These roles are only assigned to synced nodes.</para>
    <para/>
    <para>It then possible to have services/listeners with router_options=master or slave accessing a subset of all galera nodes.</para>
    <para>The “synced” simply means: access all nodes.</para>
    <para/>
    <para>Examples:</para>
    <para/>
    <para>[Galera Master Service]</para>
    <para>type=service</para>
    <para>router=readconnroute</para>
    <para>router_options=master</para>
    <para/>
    <para>[Galera Slave Service]</para>
    <para>type=service</para>
    <para>router=readconnroute</para>
    <para>router_options=slave</para>
    <para/>
    <para>The Master and Slave roles are also available for the Read/Write Split router operation</para>
  </sect1>
  <sect1>
    <title><anchor id="h.xgjo4h9nd6wh"/>Readwritesplit</title>
    <para/>
    <para>The readwritesplit is a statement based router that has been designed for use within Master/Slave replication environments. It examines every statement, parsing it to determine if the statement falls into one of three categories; </para>
    <orderedlist>
      <listitem>
        <para>read only statement</para>
      </listitem>
      <listitem>
        <para>possible write statement</para>
      </listitem>
      <listitem>
        <para>session modification statement<footnote><para> A session modification statement is any statement that is executed that may affect the behaviour of subsequent statements within the current connection. Examples of such statements are the USE SQL statement or a SET statement using the SESSION scope. PREPARE STMT clauses are session statements in MaxScale since they are executed in every backend server.</para></footnote></para>
      </listitem>
    </orderedlist>
    <para>Each of these three categories has a different action associated with it. Read only statements are sent to a slave server in the replication cluster. Possible write statements, which may include read statements that have an undeterminable side effect, are sent to the current replication master. Statements that modify the session are sent to all the servers, with the result that is generated by the master server being returned to the user.</para>
    <para/>
    <para>Session modification statements must be replicated as they affect the future results of read and write operations, so they must be executed on all servers that could execute statements on behalf of this client.</para>
    <para/>
    <para>Currently the readwritesplit router module is under development and has the following limitations:</para>
    <orderedlist>
      <listitem>
        <para>Connection failover support has not yet been implemented. Client connections will fail if the master server fails over.</para>
      </listitem>
    </orderedlist>
  </sect1>
  <sect1>
    <title><anchor id="h.bfxsnbank28n"/>Master/Slave Replication Setup</title>
    <para/>
    <para>To setup the readwritesplit connection router in a master/slave failover environment is extremely simple, a service definition is required with the router defined for the service and an associated listener.</para>
    <para>The router_options parameter is not required but it can be used to specify how slave(s) are selected. Available option is slave_selection_criteria and possible value are LEAST_BEHIND_MASTER and LEAST_CURRENT_OPERATIONS. </para>
    <para>max_slave_connections is a readwritesplit-only option, which sets the upper limit for the number of slaves a router session can use. max_slave_replication_lag is (currently) another readwritesplit-specific option, which sets maximum allowed lag for slave in seconds. The criteria is checked when router chooses slaves and only slaves having smaller lag are eligible for selection. The lag is not checked after connection phase.</para>
    <para/>
    <para>[Split Service]</para>
    <para>type=service</para>
    <para>router=readwritesplit</para>
    <para>router_options=slave_selection_criteria=LEAST_BEHIND_MASTER</para>
    <para>max_slave_connections=50%</para>
    <para>max_slave_replication_lag=30</para>
    <para>servers=server1,server2,server3,server4</para>
    <para>user=maxscale</para>
    <para>auth=thepasswd</para>
    <para/>
    <para>[Split Listener]</para>
    <para>type=listener</para>
    <para>service=Split Service</para>
    <para>protocol=MySQLClient</para>
    <para>port=3336</para>
    <para/>
    <para>The client would merely connect to port 3336 on the MaxScale host and statements would be directed to the master or slave as appropriate. Determination of the master or slave status may be done via a monitor module within MaxScale or externally. In this latter case the server flags would need to be set via the MaxScale debug interface, in future versions an API will be available for this purpose.</para>
    <para/>
    <para>Galera Cluster Configuration</para>
    <para>Master and Slave roles that galera monitor assign to nodes make possible the Read Write split approach to Galera Cluster as well.</para>
    <para/>
    <para>Simply configure a Split Service with galera nodes:</para>
    <para/>
    <para>[Galera Split Service]</para>
    <para>type=service</para>
    <para>router=readwritesplit</para>
    <para>servers=galera_node1,galera_node2,galera_node3</para>
    <para/>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.ocyc3m30hnsp"/>Debugcli</title>
    <para/>
    <para>The debugcli is a special case of a statement based router. Rather than direct the statements at an external data source they are handled internally. These statements are simple text commands and the results are the output of debug commands within MaxScale. The service and listener definitions for a debug cli service only differ from other services in that they require no backend server definitions.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.hqwc7nucjb6n"/>Debug CLI Configuration</title>
    <para/>
    <para>The definition of the debug cli service is illustrated below</para>
    <para/>
    <para>[Debug Service]</para>
    <para>type=service</para>
    <para>router=debugcli</para>
    <para/>
    <para>[Debug Listener]</para>
    <para>type=listener</para>
    <para>service=Debug Service</para>
    <para>protocol=telnetd</para>
    <para>port=4442</para>
    <para/>
    <para>Connections using the telnet protocol to port 4442 of the MaxScale host will result in a new debug CLI session. A default username and password are used for this module, new users may be created using the add user command. As soon as any users are explicitly created the default username will no longer continue to work. The default username is admin with a password of skysql.</para>
    <para/>
    <para>The debugcli supports two modes of operation, developer mode and user mode. The mode is set via the router_options parameter of the debugcli. The user mode is more suited to end-users and administrators, whilst the develop mode is explicitly targeted to software developing adding or maintaining the MaxScale code base. Details of the differences between the modes can be found in the debugging guide for MaxScale. The default mode for the debugcli is user mode. The following service definition would enable a developer version of the debugcli.</para>
    <para/>
    <para>[Debug Service]</para>
    <para>type=service</para>
    <para>router=debugcli</para>
    <para>router_options=developer</para>
    <para/>
    <para>It should be noted that both a user and a developer version of the debugcli may be defined within the same instance of MaxScale, however they must be defined as two distinct services, each with a distinct listener.</para>
    <para/>
    <para>[Debug Service]</para>
    <para>type=service</para>
    <para>router=debugcli</para>
    <para>router_options=developer</para>
    <para/>
    <para>[Debug Listener]</para>
    <para>type=listener</para>
    <para>service=Debug Service</para>
    <para>protocol=telnetd</para>
    <para>port=4442</para>
    <para/>
    <para>[Admin Service]</para>
    <para>type=service</para>
    <para>router=debugcli</para>
    <para/>
    <para>[Admin Listener]</para>
    <para>type=listener</para>
    <para>service=Debug Service</para>
    <para>protocol=telnetd</para>
    <para>port=4242</para>
  </sect1>
  <sect1>
    <title><anchor id="h.eqh26vvsnoyx"/>CLI</title>
    <para>The command line interface as used by maxadmin. This is a variant of the debugcli that is built slightly differently so that it may be accessed by the client application maxadmin. The CLI requires the use of the maxscaled protocol.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.ufb8c39hpesa"/>CLI Configuration</title>
    <para>There are two components to the definition required in order to run the command line interface to use with MaxAdmin; a service and a listener.</para>
    <para>The default entries required are shown below.</para>
    <para/>
    <para>[CLI]</para>
    <para>type=service</para>
    <para>router=cli</para>
    <para/>
    <para>[CLI Listener]</para>
    <para>type=listener</para>
    <para>service=CLI</para>
    <para>protocol=maxscaled</para>
    <para>address=localhost</para>
    <para>port=6603</para>
    <para/>
    <para>Note that this uses the default port of 6603 and confines the connections to localhost connections only. Remove the address= entry to allow connections from any machine on your network. Changing the port from 6603 will mean that you must allows pass a -p option to the MaxAdmin command.</para>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.8jmljd5b73ch"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.dubkezlgyiet"/><anchor id="h.1et7gierken4"/>Monitor Modules</title>
    <para>Monitor modules are used by MaxScale to internally monitor the state of the backend databases in order to set the server flags for each of those servers. The router modules then use these flags to determine if the particular server is a suitable destination for routing connections for particular query classifications. The monitors are run within separate threads of MaxScale and do not affect the MaxScale performance.</para>
    <para/>
    <para>The use of monitors is optional, it is possible to run MaxScale with external monitoring, in which case arrangements must be made for an external entity to set the status of each of the servers that MaxScale can route to.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.dmyjk8rz7ujv"/>Mysqlmon</title>
    <para/>
    <para>The MySQLMon monitor is a simple monitor designed for use with MySQL Master/Slave replication cluster. To execute the mysqlmon monitor an entry as shown below should be added to the MaxScale configuration file.</para>
    <para/>
    <para>[MySQL Monitor]</para>
    <para>type=monitor</para>
    <para>module=mysqlmon</para>
    <para>servers=server1,server2,server3,server4</para>
    <para/>
    <para>This will monitor the 4 servers; server1, server2, server3 and server4. It will set the status of running or failed and master or slave for each of the servers.</para>
    <para/>
    <para>The monitor uses the username given in the monitor section or the server specific user that is given in the server section to connect to the server. This user must have sufficient permissions on the database to determine the state of replication. The roles that must be granted to this user are REPLICATION SLAVE and REPLICATION CLIENT.</para>
    <para/>
    <para>To create a user that can be used to monitor the state of the cluster, the following commands could be used.</para>
    <para/>
    <para>MariaDB [mysql]&gt; create user 'maxscalemon'@'maxscalehost' identified by 'Ha79hjds';</para>
    <para>Query OK, 0 rows affected (0.01 sec)</para>
    <para/>
    <para>MariaDB [mysql]&gt; grant REPLICATION SLAVE on *.* to 'maxscalemon'@'maxscalehost';</para>
    <para>Query OK, 0 rows affected (0.00 sec)</para>
    <para/>
    <para>MariaDB [mysql]&gt; grant REPLICATION CLIENT on *.* to 'maxscalemon'@'maxscalehost';</para>
    <para>Query OK, 0 rows affected (0.00 sec)</para>
    <para/>
    <para>MariaDB [mysql]&gt; </para>
    <para/>
    <para>Assuming that MaxScale is running on the host maxscalehost.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.wymeq7isxh75"/>Galeramon</title>
    <para/>
    <para>The Galeramon monitor is a simple router designed for use with MySQL Galera cluster. To execute the galeramon monitor an entry as shown below should be added to the MaxScale configuration file.</para>
    <para/>
    <para>[Galera Monitor]</para>
    <para>type=monitor</para>
    <para>module=galeramon</para>
    <para>servers=server1,server2,server3,server4</para>
    <para/>
    <para>This will monitor the 4 servers; server1, server2, server3 and server4. It will set the status of running or failed and joined for those servers that reported the Galera JOINED status.</para>
    <para/>
    <para>The user that is configured for use with the Galera monitor must have sufficient privileges to select from the information_schema database and GLOBAL_STATUS table within that database.</para>
    <para/>
    <para>To create a user that can be used to monitor the state of the cluster, the following commands could be used.</para>
    <para/>
    <para>MariaDB [mysql]&gt; create user 'maxscalemon'@'maxscalehost' identified by 'Ha79hjds';</para>
    <para>Query OK, 0 rows affected (0.01 sec)</para>
    <para/>
    <para>MariaDB [mysql]&gt; grant SELECT on INFORMATION_SCHEMA.GLOBAL_STATUS to 'maxscalemon'@'maxscalehost';</para>
    <para>Query OK, 0 rows affected (0.00 sec)</para>
    <para/>
    <para>MariaDB [mysql]&gt; </para>
    <para/>
    <para>Assuming that MaxScale is running on the host maxscalehost.</para>
    <para/>
    <para/>
    <para>The Galera monitor can also assign Master and Slave roles to the configured nodes:</para>
    <para/>
    <para>among the set of synced servers, the one with the lowest value of ‘wsrep_local_index’ is selected as the current master while the others are slaves.</para>
    <para/>
    <para>This way is possible to configure the node access based not only on ‘synced’ state but even on Master and Slave role enabling the use of Read Write split operation on a Galera cluster and avoiding any possible write conflict.</para>
    <para/>
    <para>Example status for a Galera server node is:</para>
    <para/>
    <para>Server 0x261fe50 (server2)</para>
    <para>        Server:                192.168.1.101</para>
    <para>        Status:         Master, Synced, Running</para>
    <para/>
    <para/>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.j1c67xshxln"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.sge7r9zx7x4"/><anchor id="h.qhqjtykx4m1m"/>Filter Modules</title>
    <para>Currently four example filters are included in the MaxScale distribution</para>
    <para/>
    <informaltable frame="all">
      <tgroup cols="2"><tbody><row><entry><para>Module</para></entry><entry><para>Description</para></entry></row><row><entry><para>testfilter</para></entry><entry><para>Statement counting Filter - a simple filter that counts the number of SQL statements executed within a session. Results may be viewed via the debug interface.</para></entry></row><row><entry><para>qlafilter</para></entry><entry><para>Query Logging Filter - a simple query logging filter that write all statements for a session into a log file for that session.</para></entry></row><row><entry><para>regexfilter</para></entry><entry><para>Query Rewrite Filter - an example of how filters can alter the query contents. This filter allows a regular expression to be defined, along with replacement text that should be substituted for every match of that regular expression.</para></entry></row><row><entry><para>tee</para></entry><entry><para>A filter that duplicates SQL requests and sends the duplicates to another service within MaxScale.</para></entry></row></tbody></tgroup>
    </informaltable>
    <para/>
    <para>These filters are merely examples of what may be achieved with the filter API and are not sophisticated or consider as suitable for production use, they merely illustrate the functionality possible.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.ysp4c1tvbz2t"/>Statement Counting Filter</title>
    <para>The statement counting filter is implemented in the module names testfilter and merely keeps a count of the number of SQL statements executed. The filter requires no options to be passed and takes no parameters. The statement count can be viewed via the diagnostic and debug interface of MaxScale.</para>
    <para/>
    <para>In order to add this filter to an existing service create a filter section to name the filter as follows</para>
    <para/>
    <para>[counter]</para>
    <para>type=filter</para>
    <para>module=testfilter</para>
    <para/>
    <para>Then add the filter to your service by including the filters= parameter in the service section.</para>
    <para/>
    <para>filters=counter</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.fsgdmoofnux2"/>Query Log All Filter</title>
    <para>The QLA filter simply writes all SQL statements to a log file along with a timestamp for the statement. An example of the file produced by the QLA filter is shown below</para>
    <para/>
    <para>00:36:04.922 5/06/2014, select @@version_comment limit 1</para>
    <para>00:36:12.663 5/06/2014, SELECT DATABASE()</para>
    <para>00:36:12.664 5/06/2014, show databases</para>
    <para>00:36:12.665 5/06/2014, show tables</para>
    <para/>
    <para>A new file is created for each client connection, the name of the logfile can be controlled by the use of the router options. No parameters are used by the QLA filter. The filter is implemented by the loadable module qlafilter.</para>
    <para/>
    <para>To add the QLA filter to a service you must create a filter section to name the filter, associated the loadable module and define the filename option.</para>
    <para/>
    <para>[QLA]</para>
    <para>type=filter</para>
    <para>module=qlafilter</para>
    <para>options=/tmp/QueryLog</para>
    <para/>
    <para>Then add the filters= parameter into the service that you wish to log by adding this parameter to the service section</para>
    <para/>
    <para>filters=QLA</para>
    <para/>
    <para>A log file will be created for each client connection, the name of that log file will be /tmp/QueryLog.&lt;number&gt;</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.uqxr7wxzkcl7"/>Regular Expression Filter</title>
    <para>The regular expression filter is a simple text based query rewriting filter. It allows a regular expression to be used to match text in a SQL query and then a string replacement to be made against that match. The filter is implemented by the regexfilter loadable module and is passed two parameters, a match string and a replacement string.</para>
    <para/>
    <para>To add the filter to your service you must first create a filter section to name the filter and give the match and replacement strings. Here we define a filter that will convert to MariaDB 10 command show all slaves status to the older form of show slave status for MariaDB 5.5.</para>
    <para/>
    <para>[slavestatus]</para>
    <para>type=filter</para>
    <para>module=regexfilter</para>
    <para>match=show *all *slaves</para>
    <para>replace=show slave</para>
    <para/>
    <para>You must then add this filter to your service by adding the filters= option</para>
    <para/>
    <para>filters=slavestatus</para>
    <para>Another example would be a filter to convert from the MySQL 5.1 create table syntax that used the TYPE keyword to the newer ENGINE keyword.</para>
    <para/>
    <para>[EnginerFilter]</para>
    <para>type=filter</para>
    <para>module=regexfilter</para>
    <para>match=TYPE</para>
    <para>replace=ENGINE</para>
    <para/>
    <para>This would then change the SQL sent by a client application written to work with MySQL 5.1 into SQL that was compliant with MySQL 5.5. The statement</para>
    <para/>
    <para>create table supplier(id integer, name varchar(80)) type=innodb</para>
    <para/>
    <para>would be replaced with</para>
    <para/>
    <para>create table supplier(id integer, name varchar(80)) ENGINE=innodb</para>
    <para/>
    <para>before being sent to the server. Note that the text in the match string is case independent.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.wle3ebajc9u7"/>Tee Filter</title>
    <para>The tee filter is a filter module for MaxScale is a “plumbing” fitting in the MaxScale filter toolkit. It can be used in a filter pipeline of a service to make a copy of requests from the client and dispatch a copy of the request to another service within MaxScale. </para>
    <para/>
    <para>The configuration block for the TEE filter requires the minimal filter parameters in it’s section within the MaxScale.cnf file that defines the filter to load and the service to send the duplicates to.</para>
    <para/>
    <para>[ArchieveFilter]</para>
    <para>type=filter</para>
    <para>module=tee</para>
    <para>service=Archieve</para>
    <para/>
    <para>In addition parameters may be added to define patterns to match against to either include or exclude particular SQL statements to be duplicated. You may also define that the filter is only active for connections from a particular source or when a particular user is connected.</para>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.f7y85in8tebq"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.9f32pn7wijl8"/><anchor id="h.dc263y31zsda"/>Encrypting Passwords</title>
    <para/>
    <para>Passwords stored in the MaxScale.cnf file may optionally be encrypted for added security. This is done by creation of an encryption key on installation of MaxScale. Encryption keys may be created manually by executing the maxkeys utility with the argument of the filename to store the key.</para>
    <para/>
    <para>maxkeys $MAXSCALE_HOME/etc/.secrets</para>
    <para/>
    <para>Changing the encryption key for MaxScale will invalidate any currently encrypted keys stored in the MaxScale.cnf file.</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.l0qb1nls7ei3"/>Creating Encrypted Passwords</title>
    <para/>
    <para>Encrypted passwords are created by executing the maxpasswd command with the password you require to encrypt as an argument. The environment variable MAXSCALE_HOME must be set, or MaxScale must be installed in the default location before maxpasswd can be executed.</para>
    <para/>
    <para>maxpasswd MaxScalePw001</para>
    <para>61DD955512C39A4A8BC4BB1E5F116705</para>
    <para/>
    <para>The output of the maxpasswd command is a hexadecimal string, this should be inserted into the MaxScale.cnf file in place of the ordinary, plain text, password. MaxScale will determine this as an encrypted password and automatically decrypt it before sending it the database server.</para>
    <para/>
    <para>[Split Service]</para>
    <para>type=service</para>
    <para>router=readwritesplit</para>
    <para>servers=server1,server2,server3,server4</para>
    <para>user=maxscale</para>
    <para>password=61DD955512C39A4A8BC4BB1E5F116705</para>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.4musj6ccb4a8"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.wm8guj3t9im2"/><anchor id="h.wnbvl0ktgm03"/>Configuration Updates</title>
    <para>The current MaxScale configuration may be updating by editing the configuration file and then forcing MaxScale to reread the configuration file. To force MaxScale to reread the configuration file a SIGTERM signal is sent to the MaxScale process.</para>
    <para/>
    <para>Some changes in configuration can not be dynamically changed and require a complete restart of MaxScale, whilst others will take some time to be applied.</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.5zjikdpkopj4"/>Limitations</title>
    <para>Services that are removed via the configuration update mechanism can not be physically removed from MaxScale until there are no longer any connections using the service.</para>
    <para/>
    <para>When the number of threads is decreased the threads will not actually be terminated until such time as they complete the current operation of that thread.</para>
    <para/>
    <para>Monitors can not be completely removed from the running MaxScale.</para>
  </sect1>
  <sect1>
    <title>
      <anchor id="h.usbajk3czrtm"/>
    </title>
  </sect1>
  <sect1>
    <title><anchor id="h.gaix3h5c8twh"/><anchor id="h.lwzmfeuphxuk"/>Authentication</title>
    <para>MySQL uses username, passwords and the client host in order to authenticate a user, so a typical user would be defined as user X at host Y and would be given a password to connect. MaxScale uses exactly the same rules as MySQL when users connect to the MaxScale instance, i.e. it will check the address from which the client is connecting and treat this in exactly the same way that MySQL would. MaxScale will pull the authentication data from one of the backend servers and use this to match the incoming connections, the assumption being that all the backend servers for a particular service will share the same set of user credentials.</para>
    <para/>
    <para>It is important to understand, however, that when MaxScale itself makes connections to the backend servers the backend server will see all connections as originating from the host that runs MaxScale and not the original host from which the client connected to MaxScale. Therefore the backend servers should be configured to allow connections from the MaxScale host for every user that can connect from any host. Since there is only a single password within the database server for a given host, this limits the configuration such that a given user name must have the same password for every host from which they can connect.</para>
    <para/>
    <para>To clarify, if a user X is defined as using password pass1 from host a and pass2 from host b then there must be an entry in the user table for user X form the MaxScale host, say pass1.</para>
    <para/>
    <para>This would result in rows in the user table as follows</para>
    <informaltable frame="all">
      <tgroup cols="4"><colspec colnum="1" colname="c1"/><colspec colnum="2" colname="c2"/><colspec colnum="3" colname="c3"/><colspec colnum="4" colname="c4"/><tbody><row><entry><para>Username</para></entry><entry><para>Password</para></entry><entry><para>Client Host</para></entry></row><row><entry><para>X</para></entry><entry><para>pass1</para></entry><entry><para>a</para></entry></row><row><entry><para>X</para></entry><entry><para>pass2</para></entry><entry><para>b</para></entry></row><row><entry><para>X</para></entry><entry><para>pass1</para></entry><entry><para>MaxScale</para></entry></row></tbody></tgroup>
    </informaltable>
    <para/>
    <para/>
    <para>In this case the user X would be able to connect to MaxScale from host a giving the password of pass1. In addition MaxScale would be able to create connections for this user to the backend servers using the username X and password pass1, since the MaxScale host is also defined to have password pass1. User X would not however be able to connect from host b since they would need to provide the password pass2 in order to connect to MaxScale, but then MaxScale would not be able to connect to the backends as it would also use the password pass2 for these connections.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.mmwkd4ufl8il"/>Wildcard Hosts</title>
    <para/>
    <para>Hostname mapping in MaxScale works in exactly the same way as for MySQL, if the wildcard is used for the host then any host other than the localhost (127.0.0.1) will match. It is important to consider that the localhost check will be performed at the MaxScale level and at the MySQL server level.</para>
    <para/>
    <para>If MaxScale and the databases are on separate hosts there are two important changes in behaviour to consider:</para>
    <para/>
    <orderedlist>
      <listitem>
        <para>Clients running on the same machine as the backend database now may access the database using the wildcard entry. The localhost check between the client and MaxScale will allow the use of the wildcard, since the client is not running on the MaxScale host. Also the wildcard entry can be used on the database host as MaxScale is making that connection and it is not running on the same host as the database.</para>
      </listitem>
      <listitem>
        <para>Clients running on the same host as MaxScale can not access the database via MaxScale using the wildcard entry since the connection to MaxScale will be from the localhost. These clients are able to access the database directly, as they will use the wildcard entry.</para>
      </listitem>
    </orderedlist>
    <para/>
    <para>If MaxScale is running on the same host as one or more of the database nodes to which it is acting as a proxy then the wildcard host entries can be used to connect to MaxScale but not to connect onwards to the database running on the same node.</para>
    <para/>
    <para>In all these cases the issue may be solved by adding an explicit entry for the localhost address that has the same password as the wildcard entry. This may be done using a statement as below for each of the databases that are required:</para>
    <para/>
    <para>MariaDB [mysql]&gt; GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP ON employee.* 'user1'@'localhost' IDENTIFIED BY ‘xxx’;</para>
    <para>Query OK, 0 rows affected (0.00 sec)</para>
    <para/>
  </sect1>
  <sect1>
    <title><anchor id="h.tkrwvuo1c0qp"/>Limitations</title>
    <para/>
    <para>At the time of writing the authentication mechanism within MaxScale does not support IPV6 address matching in connections rules. This is also in line with the current protocol modules that do not support IPV6.</para>
    <para/>
    <para>Partial address matching, such as 10.% is also not supported in the current version of MaxScale.</para>
  </sect1>
  <sect1>
    <title><anchor id="h.qk790nez3h72"/><anchor id="h.gaqtg0neens3"/>Error Reporting</title>
    <para>MaxScale is designed to be executed as a service, therefore all error reports, including configuration errors, are written to the MaxScale error log file. MaxScale will log to a set of files in the directory $MAXSCALE_HOME/log, the only exception to this is if the log directory is not writable, in which case a message is sent to the standard error descriptor.</para>
    <para/>
    <para/>
    <para/>
    <para>Troubleshooting</para>
    <para>MaxScale binds on TCP ports and UNIX sockets as well.</para>
    <para/>
    <para>If there is a local firewall in the server where MaxScale is installed, the IP and port must be configured in order to receive connections from outside.</para>
    <para/>
    <para>If the firewall is a network facility among all the involved servers, a configuration update is required as well.</para>
    <para/>
    <para>Example:</para>
    <para>[Galera Listener]</para>
    <para>type=listener</para>
    <para>        address=192.1681.3.33</para>
    <para>        port=4408</para>
    <para>        socket=/servers/maxscale/galera.sock</para>
    <para> </para>
    <para>TCP/IP Traffic must be permitted to 192.1681.3.33 port 4408</para>
    <para/>
    <para>For Unix socket, the socket file path (example: /servers/maxscale/galera.sock) must be writable by the Unix user MaxScale runs as.</para>
    <para/>
    <para/>
  </sect1>
  <para/>
  <para>Page: 4</para>
</article>
