Building MaxScale from source on CentOS 7
We’ve gotten a few questions on detailed installation tutorials for specific systems. So I decided to write one for CentOS 7 which is a pretty common OS. For this I’m using a fresh installation of CentOS 7 on a virtual machine.
Installing needed packages
The first things we need to get are tools required for getting MaxScale and building it. The Development Tools group in Yum has most of the required tools we need to build MaxScale. We also need a few other packages to build MaxScale.
The list of required packages for each distribution can be found from the documentation: Building-MaxScale-from-Source-Code
yum groupinstall "Development Tools" yum install gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc perl make libtool yum install openssl-devel libaio libaio-devel librabbitmq-devel libcurl-devel pcre-devel
The list of packages was copy-pasted from the RHEL/CentOS section in the Building From Source document.
Installing the MariaDB server
Usually it is recommended to install the required MariaDB packages on the system and let CMake figure where the needed headers and files are. Sometimes this is not an option and the packages are installed into a non-standard location. Instead of doing it the easy way, let’s extract the package into the /root/ folder!
We start by downloading the 10.0 version of MariaDB-server from mariadb.org. Pick the tarball to get everything as a nice, bundled package. CentOS 7 seems to lack wget on a fresh install so let’s install that:
yum install wget
And now for the packages:
cd /root/ wget --content-disposition https://downloads.mariadb.org/f/mariadb-10.0.22/bintar-linux-glibc_214-x86_64/mariadb-10.0.22-linux-glibc_214-x86_64.tar.gz/from/http%3A/mirror.netinch.com/pub/mariadb/?serve
After we have downloaded the package, extract it into to current folder, /root/.
tar -axf mariadb-10.0.22-linux-glibc_214-x86_64.tar.gz
Now we have the contents of the package extracted into /root/mariadb-10.0.22-linux-x86_64/. It should look something like this:
[root@localhost mariadb-10.0.22-linux-x86_64]# ls bin CREDITS EXCEPTIONS-CLIENT lib README sql-bench COPYING data include man scripts support-files COPYING.LESSER docs INSTALL-BINARY mysql-test share
Now that we have the server “installed”, we can go ahead and build MaxScale.
Finally, we’re ready to clone the MaxScale repo:
cd /root/ git clone https://github.com/mariadb-corporation/MaxScale.git mkdir build cd build
This creates a MaxScale folder in /root/, a build directory where MaxScale will be build and changes the current directory to the newly created build directory.
Next step is to invoke CMake. This is probably the most complicated phase of installing MaxScale because we need to define custom locations for some of the build parameters. For a complete list of configurable build parameters, we have the cmake -LAH command.
If we try CMake according to the guide:
... -- Looking for include file time.h - found -- Looking for include file unistd.h -- Looking for include file unistd.h - found CMake Error at cmake/macros.cmake:157 (message): Fatal Error: MySQL headers were not found. Call Stack (most recent call first): CMakeLists.txt:33 (check_dirs) -- Configuring incomplete, errors occurred!
Not good. We can remove the CMakeCache.txt to “reset” the build. We could also wipe the build directory clean, this is one of the many benefits of building “out-of-source”.
This is expected since we do not have the required packages installed in the default location. We need to tell CMake to look for the files at /root/mariadb-10.0.22-linux-x86_64/. We tell CMake where the headers are with -DMYSQL_DIR=/root/mariadb-10.0.22-linux-x86_64/include/, the embedded server with -DEMBEDDED_LIB=/root/mariadb-10.0.22-linux-x86_64/lib/libmysqld.a and finally, the errmsg.sys file with -DERRMSG=/root/mariadb-10.0.22-linux-x86_64/share/english/errmsg.sys.
We would also like to install MaxScale into /usr/ like normal packages do. We can do that by adding -DCMAKE_INSTALL_PREFIX=/usr to the CMake call.
Putting it all together:
cmake ../MaxScale -DCMAKE_INSTALL_PREFIX=/usr \ -DMYSQL_DIR=/root/mariadb-10.0.22-linux-x86_64/include \ -DEMBEDDED_LIB=/root/mariadb-10.0.22-linux-x86_64/lib/libmysqld.a \ -DERRMSG=/root/mariadb-10.0.22-linux-x86_64/share/english/errmsg.sys
This time we’re OK:
-- Using MySQL headers found at: /root/mariadb-10.0.22-linux-x86_64/include/mysql -- Using custom errmsg.sys found at: /root/mariadb-10.0.22-linux-x86_64/share/english/errmsg.sys -- Found OpenSSL: /usr/lib64/libssl.so;/usr/lib64/libcrypto.so (found version "1.0.1e") -- Valgrind not found. -- Dynamic MySQL client library not found. -- Static MySQL client library not found. -- Found mysql_version.h: /root/mariadb-10.0.22-linux-x86_64/include/mysql/mysql_version.h -- MySQL version: 10.0.22 -- MySQL provider: MariaDB -- Looking for pcre_stack_guard in /root/mariadb-10.0.22-linux-x86_64/lib/libmysqld.a -- Looking for pcre_stack_guard in /root/mariadb-10.0.22-linux-x86_64/lib/libmysqld.a - found -- Using embedded library: /root/mariadb-10.0.22-linux-x86_64/lib/libmysqld.a -- Pandoc not found. -- Could not find libtcmalloc, using system default malloc instead. -- Could not find libjemalloc, using system default malloc instead. -- Found Git: /usr/bin/git (found version "22.214.171.124") -- Found CURL: /usr/lib64/libcurl.so (found version "7.29.0") -- Found git 126.96.36.199 -- Commit ID: 7bfda81b098bfd0db3c306495725d1910294d2e8 -- C Compiler supports: -Werror=format-security -- C Compiler supports: -Wno-unused-but-set-variable -- Could not find editline library. MaxAdmin will be built without it. -- Installing maxscale.conf to: /etc/ld.so.conf.d -- Installing startup scripts to: /etc/init.d -- Installing systemd service files to: /usr/lib/systemd/system -- Found Doxygen: /usr/bin/doxygen (found version "1.8.5") -- Configuring done -- Generating done -- Build files have been written to: /root/build
We can see that the right headers and the embedded library was found and that the right errmsg.sys file is being used. Now the only thing left to do is to build and install MaxScale:
make make install
This will install MaxScale into /usr/ and the required system files to their right places.
NOTE: we need to run the post-installation script postinst once we’ve done a manual installation of MaxScale. This will create the required folders and copy scripts to their right locations.
Now that we have done all we need, we can try out our installation of MaxScale, let’s create a minimalistic maxscale.cnf to do that. Copy-pasting the following into/etc/maxscale.cnf will give us what we need.
[maxscale] threads=4 [my_monitor] type=monitor module=mysqlmon servers=local_server user=myuser passwd=mypwd [local_server] type=server address=127.0.0.1 port=3306 protocol=MySQLBackend [simple_service] type=service router=readconnroute servers=local_server user=myuser passwd=mypwd [simple_listener] type=listener service=simple_service protocol=MySQLClient port=4000 # This service allows us to use maxadmin [cli] type=service router=cli # The port for this should always be 6603 [cli_listener] type=listener service=cli protocol=maxscaled port=6603
Once we’ve copied that we can start MaxScale:
systemctl start maxscale
To confirm that MaxScale is running, we can use the maxadmin client to check the status of the servers.
[root@localhost build]# maxadmin -pmariadb list servers Servers. -------------------+-----------------+-------+-------------+-------------------- Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+-------------------- local_server | 127.0.0.1 | 3306 | 0 | Down -------------------+-----------------+-------+-------------+--------------------
Since there’s no server running on 127.0.0.1:3306 it’ll show as Down.
And that’s it! We have MaxScale built from source using a custom location for the MariaDB server binaries. Now you can start adding more to the configuration or read some of the tutorials found in the knowledgebase.