Installing a Percona Node and Galera Replication On A FreeNAS Jail
While increasing availability of the web services provided, I have created a jail for compiling and installing Percona package, with . Once ssh access has been enabled, log in and install the percona client and server:
ssh db.example.com su
Currently there is no Galera in the ports tree, however since percona provides its software source code, I can download the source from them and compile in replication. First update the pkg list:
And resolve some dependencies for building wsrep:
pkg install bash bison gcc48 libexecinfo lsof sudo rsync openssl boost-libs cmake flex libcheck scons autoconf automake gmake help2man libtool bzr subversion libevent
/bin/bash is often used as interpreter for scripts, you should link bash to that path:
sudo ln -s /usr/local/bin/bash /bin/bash
Galera is written with the modern version of C++ standard, and its code is not fully compatible with default g++ 4.2.1 compiler. You should have at least g++ 4.7, but g++ 4.8 is highly recommended. Also, you should specify version of libstdc++ library, which is used for program execution through LD_LIBRARY_PATH environment variable. You should assign the following environment variables.
bash LD_LIBRARY_PATH=/usr/local/lib/gcc48 CC=gcc48 CXX=g++48 export LD_LIBRARY_PATH CC CXX
It is recommended to add them to your login shell script (
.shrc, .cshrc, .bashrc).
Download and compile Percona Server with wsrep 5.5:
mkdir /usr/local/src cd /usr/local/src wget http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster/LATEST/source/Percona-XtraDB-Cluster-5.5.34.tar.gz tar xzf Percona-XtraDB-Cluster-5.5.34.tar.gz cd Percona-XtraDB-Cluster-5.5.34 ./BUILD/compile-pentium-wsrep make install
Add a new user to run the Percona Server as mysql.
Full name: Percona Server
Login group [mysql]:
Login group is mysql. Invite mysql into other groups? :
Login class [default]:
Shell (sh csh tcsh bash rbash git-shell nologin) [sh]: csh
Home directory [/home/mysql]: /usr/local/mysql/data
Home directory permissions (Leave empty for default):
Use password-based authentication? [no]: no
Lock out the account after creation? [no]: no
Username : mysql
Full Name : Percona Server
Uid : 1002
Groups : mysql
Home : /usr/local/mysql/data
Home Mode :
Shell : /bin/csh
Locked : no
OK? (yes/no): yes
adduser: INFO: Successfully added (mysql) to the user database.
Change the permissions of your data directory to the newly created mysql user with the following line:
chown -R mysql:mysql /usr/local/mysql/data
Update your PATH variable to open the MySQL console with mysql.
Note you may need to setting a the PATH variable at the top of
/etc/rc.conf, similar to the following:
Configure the setup script and change the
Now, we can create the database by executing the setup script. Finally, we will start the Percona Server.
cp /usr/local/mysql/support-files/mysql.server /usr/local/etc/rc.d/ mv /usr/local/etc/rc.d/mysql.server /usr/local/etc/rc.d/mysql /usr/local/etc/rc.d/mysql start
NOTE: I needed to replace the pidof command with the pgrep command on FreeBSD, I just commented out the previous command and set a new command in the pid variable:
#! Try to find appropriate mysqld process
#! mysqld_pid=`pidof $libexecdir/mysqld`
#! FreeBSD fix to try to find appropriate mysqld process
mysqld_pid=`pgrep -d' ' $libexecdir/mysqld`
Now initialize the database system tables:
cd /usr/local/mysql /usr/local/mysql/scripts/mysql_install_db
Run the MySQL secure script to harden your environment.
Add MySQL to your system configuration to start it on your system start.
Now test start the service:
service mysql start
SUCCESS! MySQL (Percona XtraDB Cluster) running (20263)
And stop the service:
service mysql stop
Download and compile Galera 2.x:
cd /usr/local/src wget http://www.percona.com/redir/downloads/Percona-XtraDB-Cluster/LATEST/source/percona-xtradb-cluster-galera.tar.gz tar xzf percona-xtradb-cluster-galera.tar.gz cd percona-xtradb-db-cluster-galera scons
And manually install the Galera plugin:
cp garb/garbd /usr/local/mysql/bin/ cp libgalera_smm.so /usr/local/mysql/lib/mysql/plugin/
Copy an example mysql configuration to the
cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf
And make the following changes to /etc/my.cnf:
[mysqld] # Percona XtraDB Cluster binlog_format=ROW wsrep_provider=/usr/local/mysql/lib/mysql/plugin/libgalera_smm.so wsrep_cluster_address=gcomm:// log_slave_updates wsrep_slave_threads=2 wsrep_cluster_name=unique_cluster_name wsrep_sst_method=rsync wsrep_node_name=node2 innodb_locks_unsafe_for_binlog=1 innodb_autoinc_lock_mode=2 [mysqld_safe] wsrep_urls=gcomm://