2,866 瀏覽數

CentOS 7 編譯 MariaDB + Galera Cluster

這次試著編譯 MariaDB (5.5.51) + Galera (25.3.17) cluster 的 source code (兩個都需要額外編譯)
參考下列網頁說明 https://mariadb.com/kb/en/mariadb/installating-galera-from-source/

MariaDB with wsrep (Write-Set Replication) API


MariaDB 下載點 – https://mariadb.org/download/

我們要先安裝下面的套件

[root@benjr ~]# yum update
[root@benjr ~]# yum install mariadb-server

測試環境為 CentOS 7 (最小安裝),因為我的 CentOS 7 是最小安裝,所以需要一些額外的套件 CMake , GCC , GCC-C++ , Automake , Autoconf , Bison , libaio , ncurses , ncurses-devel 以及 zlib-devel.

[root@benjr ~]# yum install -y cmake gcc gcc-c++ automake autoconf bison libaio ncurses ncurses-devel zlib-devel
[root@benjr ~]# yum install -y git wget make tar boost-devel check-devel openssl-devel perl-CPAN 'perl(Test::More)'

什麼是 MariaDB database server with wsrep API?
MariaDB database server with wsrep API 與 MariaDB database server 版本主要的差別是他支援了 Galera Cluster the wsrep (Write-Set Replication) API patch. 只需要在 CMake 編譯的時候加入參數 WITH_WSREP 與 WITH_INNODB_DISALLOW_WRITES 即可支援.
到了 MariaDB database server 10.1 就沒有分成兩種版本,預設都有支援 wsrep api . 關於 WSREP 參數 請參考 http://galeracluster.com/documentation-webpages/mysqlwsrepoptions.html

[root@benjr ~]# tar zxvf mariadb-galera-5.5.51.tar.gz
[root@benjr ~]# cd mariadb-5.5.51
[root@benjr mariadb-5.5.51]# cmake -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW_WRITES=ON .
......
-- Build files have been written to: /root/mariadb-5.5.51

這樣就代表 cmake 已經產生了 MakeFile .透過下面的方式可以讓我們查詢編輯時是否確定有加入支援 wsrep 的參數.

[root@benjr mariadb-5.5.51]# 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

確定無誤就可以繼續下面 make 與 make install 步驟了.

[root@benjr mariadb-5.5.51]# make
......
[100%] Building CXX object mysql-test/lib/My/SafeProcess/CMakeFiles/my_safe_process.dir/safe_process.cc.o
Linking CXX executable my_safe_process
[100%] Built target my_safe_process

[root@benjr mariadb-5.5.51]# 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-5.5.51]# make test
.....
100% tests passed, 0 tests failed out of 49

Total Test time (real) =  29.40 sec

Galera cluster

  1. SCons
    編譯 Galera 需要透過 Scons ,而編譯 Scons 需要下列的套件. Boost , Boost-devel , Check , Check-devel and OpenSSL , Openssl-devel (剛剛在編譯 Mariadb 前已經安裝過了)

    SCons 是什麼?
    SCons is an Open Source software construction tool—that is, a next-generation build tool.

    在 Scons 網站下載 http://scons.org/pages/download.html

    [root@benjr ~]# tar zxvf scons-2.5.0.tar.gz
    [root@benjr ~]# cd scons-2.5.0
    [root@benjr 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/man1
    
  2. Galera cluster
    這邊主要是要產生 libgalera_smm.so 檔案,需要套件 gcc 與 gcc-c++ (剛剛在編譯 Mariadb 前已經安裝過了)
    在 galeracluster 網站下載 http://galeracluster.com/downloads/

    [root@benjr ~]# tar zxvf galera-3-25.3.17.tar.gz
    [root@benjr ~]# cd galera-3-25.3.17
    [root@benjr galera-3-25.3.17]# ./scripts/build.sh
    ......
    100%: Checks: 79, Failures: 0, Errors: 0
    scons: done building targets.
    [root@benjr galera-3-25.3.17]# mkdir /usr/lib64/galera
    [root@benjr 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 http://benjr.tw/95335 , Galera Cluster http://benjr.tw/95551 常見問題

Configuration


該安裝,編輯的套件都裝了,接下來是設定.

新增 mysql user 與 group:

[root@benjr ~]# groupadd mysql
[root@benjr ~]# useradd -g mysql mysql

useradd -g 設定 mysql 的初始群組

mysql_install_db 會初始化 MySQL 資料目錄 (data directory),如果 系統 table 不存會一併創建其內容.

[root@benjr ~]# cd /usr/local/mysql/
[root@benjr mysql]# ./scripts/mysql_install_db --user=mysql
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
160904 12:37:24 [Note] ./bin/mysqld (mysqld 5.5.51-MariaDB-wsrep) starting as process 2767 ...
160904 12:37:24 [Note] WSREP: Read nil XID from storage engines, skipping position init
160904 12:37:24 [Note] WSREP: wsrep_load(): loading provider library 'none'
160904 12:37:24 [Note] WSREP: Service disconnected.
160904 12:37:25 [Note] WSREP: Some threads may fail to exit.
......
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h benjr password 'new-password'

Alternatively you can run:
'./bin/mysql_secure_installation'

......

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl
......

上面有提醒我們後續需要做的動作,

要修改 /usr/local/mysql 目錄的 user 與 group 權限.

[root@benjr ~]# chown -R mysql /usr/local/mysql
[root@benjr ~]# chgrp -R mysql /usr/local/mysql

需要將 /usr/local/mysql/support-files/mysql.server 複製到 /etc/init.d/mysql,並透過 system V 的方式來啟動.

[root@benjr ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
[root@benjr ~]# chmod +x /etc/init.d/mysql
[root@benjr ~]# chkconfig --add mysql

基本上 MariaDB + Galera 已經編譯完成,你可以透過下面的指令來啟服務,但我卻遇到服務無法啟動,不過重新開機會就正常了.

[root@benjr ~]# /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@benjr ~]# reboot
[root@benjr ~]# 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 設定請參考 – http://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

之前我一直遇到 MariaDB 5.5.50 , 5.5.51 與 Galera (25.3.17) 版本的一些問題,比如 MariaDB 啟動有問題,或是新的 node 無法加入到 Cluster 裡.

[root@benjr ~]# systemctl restart mysql
Job for mysql.service failed because the control process exited with error code. See "systemctl status mysql.service" and "journalctl -xe" for details.
[root@benjr ~]# service mysql restart
Shutting down MySQL. SUCCESS! 
Starting MySQL................................... ERROR! 
 ERROR! Failed to restart server.

最後是換成 MySQL 5.5.50 server with wsrep patch + Galera (25.3.17) – 檔案下載點 http://galeracluster.com/downloads/ 才沒有這些錯誤發生.編譯 Mysql 的方式和 MariaDB 步驟一樣.但設定方式就不一樣了.

2 個網友的想法 “CentOS 7 編譯 MariaDB + Galera Cluster

  1. 自動參照通知: 編譯 MariaDB 5.5.51 – Benjr.tw

  2. 自動參照通知: 編譯 MariaDB 10.1.16 – Benjr.tw

發表迴響