雖然 MariaDB 與 Galera 皆編輯成功,但不知道為什麼卻沒有真正把 MariaDB 從 10.0.25 升級到 10.1.16 .
這次試著編譯 MariaDB (10.1.16) source code 參考 https://mariadb.com/kb/en/mariadb/installating-galera-from-source/ 網頁說明
MariaDB
MariaDB 下載點 – https://mariadb.org/download/
測試環境為 Ubuntu 16.04 Desktop,因為要編譯所以還需要一些額外的套件 cmake libncurses5-dev libpcre++-dev libssl-dev zlib1g-dev 以及 bison.
root@ubuntu:~# apt-get update root@ubuntu:~# apt-get upgrade root@ubuntu:~# apt-get install cmake libncurses5-dev libpcre++-dev libssl-dev zlib1g-dev bison
我們還需要安裝預設的 mariadb-server (Ubuntu 16.04 預設的版本為 10.0.25) 一些檔案,以方便後面的升級.
root@ubuntu:~# apt-get install mariadb-server
編輯步驟很簡單,如下:
root@ubuntu:~# tar zxvf mariadb-10.1.16.tar.gz root@ubuntu:~# cd mariadb-10.1.16 root@ubuntu:~/mariadb-10.1.16# cmake . ...... -- Configuring done -- Generating done -- Build files have been written to: /root/mariadb-10.1.16
這樣就代表 cmake 已經產生了 MakeFile .可以繼續下面 make 與 make install 步驟了.
如果你想要知道預設編輯時使用了哪一些參數,可以透過下面的方式來查詢.
root@ubuntu:~/mariadb-10.1.16# cmake . -LH ..... // InnoDB freeze writes patch from Google WITH_INNODB_DISALLOW_WRITES:BOOL=ON ..... // WSREP replication API (to use, e.g. Galera Replication library) WITH_WSREP:BOOL=ON
從 MariaDB database server 10.1 之後的版本有支援 wsrep api 可以使用,預設已經包含這一些參數 -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW_WRITES=ON ,這個參數可以讓 MariaDB 支援 Galera Cluster the wsrep (Write-Set Replication) API.
root@ubuntu:~/mariadb-10.1.16# make ...... [100%] Built target my_safe_process root@ubuntu:~/mariadb-10.1.16# make install ...... -- Installing: /usr/local/mysql/man/man1/mysqltest_embedded.1 -- Installing: /usr/local/mysql/man/man1/mysql_client_test_embedded.1
make , make install 終於也成功了.
Testing MariaDB
[root@benjr mariadb-10.1.16]# make test ..... 100% tests passed, 0 tests failed out of 58 Total Test time (real) = 61.67 sec
Galera cluster
- SCons
編譯 Galera 需要透過 Scons ,而編譯 Galera , Scons 需要下列的套件.root@ubuntu:~# apt-get install build-essential git wget gcc make tar libboost-all-dev libpcre3-dev scons libboost-dev libboost-program-options-dev openssl dh-autoreconf libssl-dev
SCons 是什麼?
SCons is an Open Source software construction tool—that is, a next-generation build tool.在 Scons 網站下載 http://scons.org/pages/download.html
root@ubuntu:~# tar zxvf scons-2.5.0.tar.gz root@ubuntu:~# cd scons-2.5.0 root@ubuntu:~/scons-2.5.0# python setup.py install running install running build running build_py running build_scripts running install_lib running install_scripts copying script/scons -> /usr/bin/scons-2.5.0 copying script/scons -> /usr/bin copying script/sconsign -> /usr/bin/sconsign-2.5.0 copying script/sconsign -> /usr/bin copying script/scons-time -> /usr/bin/scons-time-2.5.0 copying script/scons-time -> /usr/bin running install_data running install_egg_info Removing /usr/lib/scons-2.5.0/scons-2.5.0-py2.7.egg-info Writing /usr/lib/scons-2.5.0/scons-2.5.0-py2.7.egg-info Installed SCons library modules into /usr/lib/scons-2.5.0 Installed SCons scripts into /usr/bin Installed SCons man pages into /usr/man/
- Install makeinfo
root@ubuntu:~# wget http://ftp.gnu.org/gnu/texinfo/texinfo-5.0.tar.gz root@ubuntu:~# tar -xvf texinfo-5.0.tar.gz root@ubuntu:~# cd texinfo-5.0 root@ubuntu:~/texinfo-5.0# ./configure --prefix=/usr root@ubuntu:~/texinfo-5.0# make root@ubuntu:~/texinfo-5.0# make install
- Install check dependency
root@ubuntu:~# sudo apt-get install libsubunit-dev libsubunit0 pkg-config root@ubuntu:~# git clone https://github.com/libcheck/check root@ubuntu:~# cd check/ root@ubuntu:~/check# git checkout 0.10.0 root@ubuntu:~/check# autoreconf --install root@ubuntu:~/check# export LD_LIBRARY_PATH=/usr/lib/s390x-linux-gnu/openssl-1.0.0/engines:/usr/lib/s390x-linux-gnu/:/usr/local/lib/ root@ubuntu:~/check# ./configure root@ubuntu:~/check# make root@ubuntu:~/check# make install
- Galera cluster
這邊主要是要產生 libgalera_smm.so 檔案,在 galeracluster 網站下載 http://galeracluster.com/downloads/root@ubuntu:~# tar zxvf galera-3-25.3.17.tar.gz root@ubuntu:~# cd galera-3-25.3.17 root@ubuntu:~/galera-3-25.3.17# scons strict_build_flags=0 --config=force ...... 100%: Checks: 79, Failures: 0, Errors: 0 scons: done building targets. root@ubuntu:~/galera-3-25.3.17# mkdir -p /usr/lib64/galera root@ubuntu:~/galera-3-25.3.17# cp libgalera_smm.so /usr/lib64/galera/
成功編譯出 libgalera_smm.so 這個檔案主要就是 wsrep (Write-Set Replication) provider so 檔 ,檔案置於 /usr/lib64/galera ,未來設定 /etc/my.cnf.d/server.cnf 時需要填寫這個路徑.
編譯問題可以參考 MariaDB https://benjr.tw/95335 , Galera Cluster https://benjr.tw/95551 常見問題
Configuration
該安裝,編輯的套件都裝了,接下來是設定.
新增 mysql user 與 group:
root@ubuntu:~# groupadd mysql root@ubuntu:~# useradd -g mysql mysql
useradd -g 設定 mysql 的初始群組
要修改 /usr/local/mysql 目錄的 user 與 group 權限.
root@ubuntu:~# chown -R mysql /usr/local/mysql root@ubuntu:~# chgrp -R mysql /usr/local/mysql
需要將 /usr/local/mysql/support-files/mysql.server 複製到 /etc/init.d/mysql,並透過 system V 的方式來啟動.
root@ubuntu:~# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql root@ubuntu:~# chmod +x /etc/init.d/mysql
基本上 MariaDB 已經編譯完成,你可以透過下面的指令來啟服務,但我卻遇到服務無法啟動,不過重新開機會就正常了.
root@ubuntu:~# /usr/local/mysql/bin/mysqld_safe --datadir='/var/lib/mysql' & 160818 03:41:35 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'. 160818 03:41:35 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 160818 03:43:48 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended root@ubuntu:~# reboot root@ubuntu:~# systemctl status mysql ● mysql.service - LSB: start and stop MySQL Loaded: loaded (/etc/rc.d/init.d/mysql) Active: activating (start) since 五 2016-08-26 14:13:37 CST; 1min 14s ago Docs: man:systemd-sysv-generator(8) Control: 1518 (mysql) CGroup: /system.slice/mysql.service ├─1518 /bin/sh /etc/rc.d/init.d/mysql start ├─1553 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql ... ├─2872 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/... └─3189 sleep 1
目前只會看到 Mysql 有啟動 (port 3306), 後續的 MariaDB Galera Cluster Server 設定請參考 – https://benjr.tw/95381
[root@benjr ~]# netstat -anlp | grep -e 4567 -e 3306 -e 4568 -e 4444 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN
- 3306 – MySQL port
- 4567 – Galera Cluster
- 4568 – IST (Incremental State Transfers) port
- 4444 – SST (state snapshot transfer) port
參考文章 :
- https://github.com/linux-on-ibm-z/docs/wiki/Building-MariaDB-10.1-on-RHEL-7,-RHEL6,-SLES-12-and-Ubuntu-16.04
- https://vexxhost.com/resources/tutorials/how-to-deploy-a-mariadb-galera-cluster-on-ubuntu-14-04/
- https://www.digitalocean.com/community/tutorials/how-to-configure-a-galera-cluster-with-mariadb-10-1-on-ubuntu-16-04-servers
- https://www.digitalocean.com/community/tutorials/how-to-create-a-multi-node-mysql-cluster-on-ubuntu-16-04