Back to home
Galera on freebsd (11.1 and up) A complete galera cluster on freebsd!
Finally the guys and girls developing the excellent galera cluster ported it to freebsd!
Here's how to install it!

Initial setup Install 3 boxes or vm's with a basic freebsd 11.1 install, freely downloadable at www.freebsd.org
Assign an ip to each and boot them
Next, do all the necessary updates etc. on the ports and install some nice to have utilities:
installation commands
#portsnap fetch extract
#cd /usr/ports/ports-mgmt/portmaster
#make install clean
#portmaster databases/mariadb102-server (make sure to select SSL in the config!!!)
#portmaster devel/boost-libs sysutils/lsof net/rsync
#portmaster databases/galera
#echo mysql_enable="YES" >> /etc/rc.conf
UPDATE! With the newer releases of mariadb (specially as of freebsd 13.0 with the current ports), galera is included in the mariadb build, so you do not need to install databases/galera anymore.
After this, start the mysql server using 'service mysql-server start'. Mariadb will come up with a first time installer, securing the database etc.

Galera configuration Stop the sql server.
Download the file: wsrep_sst_rsync and overwrite the one in /usr/local/bin, it has an error!
or, if you like to do things yourself, change that file:
wsrep_sst_rsync patch
#nano /usr/local/bin/wsrep_sst_rsync

-- look for the line saying: local is_rsync="$(echo $port_info | \
--                           grep -w '[[:space:]]\+rsync[[:space:]]\+'"$rsync_pid" 2>/dev/null)"

-- replace with:
	local is_rsync="$(echo "$port_info" | grep -w rsync.*"$rsync_pid" 2>/dev/null)"
	
	
Then create a my.cnf file in the folder /var/db/mysql
Examples can be found in /usr/local/share/mysql/. If you like any one of these, just copy it to /var/db/mysql.

Make the correct changes to the file:
my.cnf
[mysqld]
user=mysql
default-storage-engine=innodb
binlog_format=ROW
innodb_autoinc_lock_mode=2
bind-address=0.0.0.0

[galera]
wsrep_on=ON
wsrep_provider = /usr/local/lib/libgalera_smm.so
wsrep_provider_options = "gmcast.segment=1;pc.weight=1"
wsrep_cluster_name = "mycluster"
wsrep_cluster_address = "gcomm://"
wsrep_sst_method = rsync
wsrep_node_address="this_node_ip"
wsrep_node_name="this_node_name"
		
	

On the FIRST galera server in the cluster, change /etc/rc.conf so it will accept the other galera servers:
rc.conf
mysql_args="--wsrep-on --wsrep-new-cluster"
mysql_db_dir="/var/db/mysql"
All the other galera servers in the cluster can be started after the first one is booted and running.

To verify if things are running, use the query:
Check cluster
SHOW STATUS LIKE 'wsrep_cluster_size'
-- or
SHOW STATUS LIKE 'wsrep_%'
The first query should be the correct amount of servers in the cluster if all are connected.