Building MaxScale from source on Ubuntu 14.04
Having written the Building MaxScale from source on Centos7 tutorial, we have received requests about writing one for Ubuntu. It seems the most mentioned version is the 14.04 LTS version so we’re going to go with that. For the purpose of this tutorial, I’ve installed a fresh installation of Ubuntu 14.04.3 LTS (Trusty Tahr) on a VM.
MaxScale is a bit more complicated to build on Ubuntu and Debian, but should still be something almost everyone can do.
Installing basic packages
We start off by installing tools that we will need when building MaxScale. The list of required packages for each distribution can be found from the documentation: Building-MaxScale-from-Source-Code
sudo apt-get install build-essential libssl-dev \ libaio-dev ncurses-dev bison cmake perl libtool \ librabbitmq-dev libcurl4-openssl-dev libpcre3-dev
If we would have used the exact list of packages the source building guide tells us, we would have noticed that libcurl-dev is a virtual package and we would have needed to choose a specific one.
Installing the MariaDB server
The recommended way to build MaxScale is by downloading and installing the packages from mariadb.org. This way the configuration is much simpler and CMake will find the required libraries automatically.
As we did with the CentOS 7 installation, we’ll use a non-standard location for the MariaDB server binaries. This way we can build MaxScale with any version of the MariaDB server without affecting the system we are building it in.
The first thing we do is download the MariaDB 10.0 tarball since it has all the required files in it. We’ll pick the GLIBC_2.14+ one since Ubuntu 14.04 has GLIBC version 2.19.
wget --content-disposition https://downloads.mariadb.org/interstitial/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
Next step is to extract the package into a directory. Since I’m doing this on a VM, I’ll just extract it into the user’s home directory.
cd tar -axf mariadb-10.0.22-linux-glibc_214-x86_64.tar.gz
After that’s done we have the mariadb-10.0.22-linux-x86_64 folder in our home directory with all the needed files. Now we can actually start building MaxScale.
Now that we have all the required packages, we can clone the MaxScale repo.
git clone https://github.com/mariadb-corporation/MaxScale.git The program 'git' is currently not installed. You can install it by typing: sudo apt-get install git
It seems Ubuntu doesn’t have git installed so let’s fix that by installing it.
sudo apt-get install git
Now we continue.
git clone https://github.com/mariadb-corporation/MaxScale.git mkdir build cd build
We cloned the MaxScale repo and created a build directory. It is always recommended to build “out-of-source” when using CMake. This way we keep the source tree clean and avoid doing anything harmful to it.
The next step is to configure MaxScale’s build with CMake. This is usually the part where people run into trouble since some of the CMake parameters aren’t so self-explanatory. Let’s try following the Building from source guide to the letter.
cmake ../Maxscale -- 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!
This was expected since we don’t have the MariaDB server files in the standard location. Let’s start over by removing the CMakeCache.txt file, this “resets” the configuration process.
We could have also deleted everything in the folder and started over again. This is one of the benefits of building out-of-source.
Since our MariaDB server is not in the standard location, we need to tell CMake where to look for the files. We can tell CMake where to look for the header files with -DMYSQL_DIR=/home/user/mariadb-10.0.22-linux-x86_64/include/. Next we need to tell CMake where the embedded server library is and we can do that with -DEMBEDDED_LIB=/home/user/mariadb-10.0.22-linux-x86_64/lib/libmysqld.a. This should point to the actual library, not the folder it resides in. Finally, we need to tell CMake where to look for the language file errmsg.sys with -DERRMSG=/home/user/mariadb-10.0.22-linux-x86_64/share/english/errmsg.sys.
We also want to install MaxScale like it would have been installed from a package so we’ll add -DCMAKE_INSTALL_PREFIX=/usr to install into /usr/ instead of /usr/local/.
Putting it all together we get this:
cmake ../MaxScale/ \ -DCMAKE_INSTALL_PREFIX=/usr \ -DMYSQL_DIR=/home/user/mariadb-10.0.22-linux-x86_64/include/ \ -DEMBEDDED_LIB=/home/user/mariadb-10.0.22-linux-x86_64/lib/libmysqld.a \ -DERRMSG=/home/user/mariadb-10.0.22-linux-x86_64/share/english/errmsg.sys
-- CMake version: 188.8.131.52 -- Using MySQL headers found at: /home/user/mariadb-10.0.22-linux-x86_64/include/mysql -- Using custom errmsg.sys found at: /home/user/mariadb-10.0.22-linux-x86_64/share/english/errmsg.sys -- Valgrind not found. -- Dynamic MySQL client library not found. -- Static MySQL client library not found. -- Found mysql_version.h: /home/user/mariadb-10.0.22-linux-x86_64/include/mysql/mysql_version.h -- MySQL version: 10.0.22 -- MySQL provider: MariaDB -- Using embedded library: /home/user/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 1.9.1 -- 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 -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- Configuring done -- Generating done -- Build files have been written to: /home/user/build
The configuration is successful and we can see that the right headers were found as was the embedded library and the errmsg.sys file. The final thing to do is to build and install MaxScale and run the post-installation script which will create the required directories and copy system scripts into their right places.
make sudo make install sudo ./postinst
Now MaxScale should be installed and working. We can do a quick test to see which version we’ve installed.
maxscale --version MaxScale 1.2.1
Now that we have done all we need, we can try out our installation of MaxScale. We can do that by creating a minimalistic maxscale.cnf. Copy-pasting the following into /etc/maxscale.cnf will give us what we need.
[maxscale] threads=1 [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 the maxscale.cnf is created, we can start MaxScale: sudo service maxscale start * Starting MaxScale * maxscale is running
We can confirm that MaxScale is up and running by using MaxAdmin:
maxadmin -pmariadb list servers Servers. -------------------+-----------------+-------+-------------+-------------------- Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+-------------------- local_server | 127.0.0.1 | 3306 | 0 | Down -------------------+-----------------+-------+-------------+--------------------
And that’s it, MaxScale is running! Since we don’t have a MariaDB server running on the same machine, the local server is shown as Down. You start adding to the configuration file or read some of the tutorials on the MariaDB knowledge base.