Support #380
Updated by Daniel Curtis about 10 years ago
This guide a is to show how to build MariaDB with WSREP and Galera for a Multi-Master SQL database cluster. It is assumed that a FreeNAS jail has been setup as per Issue #329 and root access has been obtained. * Update the ports tree: <pre> portsnap fetch extract </pre> * Once that is done, build mariadb55-server from the ports tree, the uninstall mariadb55-server. tree. This is to resolve the source dependencies for recompiling the MariaDB server later on with wsrep. <pre> cd /usr/ports/databases/mariadb55-server make install clean </pre> * Now uninstall MariaDB server: <pre> make deinstall clean </pre> * Install rsync <pre> pkg install rsync </pre> * And now resolve a few dependencies before compiling the new MariaDB server: <pre> pkg install bzr bison boost-all scons libcheck cmake bash rsync gcc48 </pre> h2. Download and compile MariaDB with wsrep * Download the latest Galera patched MariaDB from launchpad <pre> cd /usr/src bzr branch lp:~maria-captains/maria/maria-5.5-galera maria-5.5-galera </pre> * Compile MariaDB with wsrep: <pre> cd maria-5.5-galera cmake . -DBUILD_CONFIG=mysql_release -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW_WRITES=1 make make install cd .. </pre> h2. Download and compile Galera * Install Galera from the ports tree (recommended) <pre> cd /usr/ports/databases/galera make install clean </pre> h3. #* Or install from the developers tree: * Remove any existing galera packages: <pre> cd /usr/ports/databases/galera make deinstall clean pkg remove galera cd /usr/src bash </pre> * Modify the build environment <pre> export CC=gcc48 export CXX=c++48 export CPP=cpp48 </pre> * Download galera source <pre> bzr branch lp:galera/2.x galera-2.x cd galera-2.x bash ./scripts/build.sh scons </pre> * Copy the modules: <pre> cp garb/garbd /usr/local/mysql/bin/ cp libgalera_smm.so /usr/local/lib/ </pre> h3. Configure mysql * Copy mysql config sample: <pre> cp /usr/local/mysql/support-files/my-small.cnf /usr/local/etc/my.cnf </pre> * Edit the mysql config file: <pre> vi /usr/local/etc/my.cnf </pre> #* And add or modify the following: <pre> [mysqld] binlog_format=ROW default-storage-engine=innodb innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 # Galera Provider Configuration wsrep_provider=/usr/local/lib/libgalera_smm.so #wsrep_provider_options="gcache.size=32G" # Galera Cluster Configuration wsrep_cluster_name="example_cluster" # Initialize the cluster; switch after --wsrep-new-cluster has been run and other nodes have joined. wsrep_cluster_address="gcomm:// # Set cluster node addresses (hostnames work too) #wsrep_cluster_address="gcomm://192.168.0.1,192.168.0.2,192.168.0.3" # Galera Synchronization Congifuration wsrep_sst_method=rsync #wsrep_sst_auth=user:pass # Galera Node Configuration wsrep_node_address="192.168.0.1" wsrep_node_name="db1.example.com" </pre> h3. Setup the boot scripts * Copy the boot mariadb boot script <pre> cp /usr/local/mysql/support-files/mysql.server /usr/local/etc/rc.d/mysql.server.sh </pre> * The boot script also needs to be edited, like the following example: <pre> vi /usr/local/etc/rc.d/mysql.server.sh </pre> #* And modify the two configuration parameters: <pre> basedir=/usr/local/mysql datadir=/usr/local/mysql/data </pre> * Initialize and secure the MariaDB database <pre> cd /usr/local/mysql /usr/local/mysql/scripts/mysql_install_db chown -R mysql:mysql data/ </pre> * Bootstrap the new Galera cluster <pre> service mysql.server.sh bootstrap </pre> *# The alternate way to bootstrap the cluster is like so: <pre> /usr/local/mysql/bin/mysqld --user=mysql --wsrep-new-cluster </pre> * Now in a second terminal connection run the @mysql_secure_installation@ script to do some post-installation hardening: <pre> /usr/local/mysql/bin/mysql_secure_installation </pre> * By this point MariaDB should be able to be controlled by the service command: <pre> service mysql.server.sh stop service mysql.server.sh start </pre> * Check the wsrep status <pre> mysql -uroot -p -e "SHOW STATUS LIKE 'wsrep_%';" </pre> h2. Resources * https://mariadb.com/kb/en/getting-the-mariadb-source-code/ * https://mariadb.com/kb/en/generic-build-instructions/ * https://mariadb.com/kb/en/getting-started-with-mariadb-galera-cluster/ * https://code.launchpad.net/maria * http://www.fromdual.ch/building-galera-replication-from-scratch * https://mariadb.com/kb/en/starting-and-stopping-mariadb-automatically/ * http://planet.mysql.com/entry/?id=30931 * http://galeracluster.com/documentation-webpages/compiling.html http://www.fromdual.com/building-galera-replication-from-scratch