1,257 瀏覽數

CentOS 7 編譯 MariaDB 10.1.16

以前要編譯 Linux 下的 source code 通常需要已經預先寫好的 Makefile ,然後透過 make , make install 來編譯.但現在都改成 cmake 的方式,查了一下關於 cmake 的說明!!

CMake (cross platform make) 並不是取代 make 這個工具,而他是會依照不同的平台編譯器出適合該環境的 Makefile (以前的 source code 會預先編寫不同作業平台的 Makefile ,編譯時會依據不同的作業平台用不同的 Makefile 來進行編譯).

詳細說明請參考 cmake 官方網站 https://cmake.org/

這次試著編譯 mariaDB 的 source code – https://mariadb.org/download/

參考下列網頁說明

MariaDB


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

[root@benjr ~]# yum update
[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-server 一些檔案,以方便後面的升級.

[root@benjr ~]# yum install mariadb-server
.....
Dependencies Resolved

================================================================================
 Package                     Arch       Version               Repository   Size
================================================================================
Installing:
 mariadb-server              x86_64     1:5.5.50-1.el7_2      updates      11 M
Installing for dependencies:
 mariadb                     x86_64     1:5.5.50-1.el7_2      updates     8.9 M
 perl-Compress-Raw-Bzip2     x86_64     2.061-3.el7           base         32 k
 perl-Compress-Raw-Zlib      x86_64     1:2.061-4.el7         base         57 k
 perl-DBD-MySQL              x86_64     4.023-5.el7           base        140 k
 perl-DBI                    x86_64     1.627-4.el7           base        802 k
 perl-IO-Compress            noarch     2.061-2.el7           base        260 k
 perl-Net-Daemon             noarch     0.48-5.el7            base         51 k
 perl-PlRPC                  noarch     0.2020-14.el7         base         36 k

編輯步驟很簡單,如下:
需要加入 -DWITHOUT_TOKUDB=1 取消對 TOKUDB 支援.才能編譯成功.

[root@benjr ~]# tar zxvf mariadb-10.1.16.tar.gz
[root@benjr ~]# cd  mariadb-10.1.16
[root@benjr mariadb-10.1.16]# cmake -DWITHOUT_TOKUDB=1 .
......
-- Build files have been written to: /root/mariadb-10.1.16

這樣就代表 cmake 已經產生了 MakeFile .可以繼續下面的步驟了.

如果你想要知道預設編輯時使用了哪一些參數,可以透過下面的方式來查詢.

[root@benjr mariadb-10.1.16]# cmake . -LH

從 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@benjr mariadb-10.1.16]# cmake -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW_WRITES=ON -DWITHOUT_TOKUDB=1 ./

關於編譯 MariaDB + Galera Cluster 請參考 http://benjr.tw/95300

[root@benjr mariadb-10.1.16]# make
......
Linking CXX executable my_safe_process
[root@benjr mariadb-10.1.16]# make install
......
-- Up-to-date: /usr/local/mysql/support-files/mysql.server

make , make install 終於也成功了.

編譯問題可以參考 MariaDB + Galera Cluster 常見問題 http://benjr.tw/95335

Testing MariaDB

[root@benjr mariadb-10.1.16]# make test
.....
100% tests passed, 0 tests failed out of 60

Total Test time (real) =  61.67 sec

或是

[root@benjr mariadb-10.1.16]# cd mysql-test
[root@benjr mysql-test]# ./mysql-test-run --force

編譯問題可以參考 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 不存會一併創建其內容.

  1. Installing MariaDB/MySQL system tables
  2. Filling help tables…
  3. Creating OpenGIS required SP-s…
[root@benjr ~]# cd /usr/local/mysql/
[root@benjr mysql]# ./scripts/mysql_install_db --user=mysql
./scripts/mysql_install_db --user=mysql
Installing MariaDB/MySQL system tables in '/var/lib/mysql' ...
2016-09-05 16:51:18 140651905369920 [Note] ./bin/mysqld (mysqld 10.1.16-MariaDB) starting as process 26091 ...
2016-09-05 16:51:19 140651905369920 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2016-09-05 16:51:19 140651905369920 [Note] InnoDB: The InnoDB memory heap is disabled
2016-09-05 16:51:19 140651905369920 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-09-05 16:51:19 140651905369920 [Note] InnoDB: Memory barrier is not used
2016-09-05 16:51:19 140651905369920 [Note] InnoDB: Compressed tables use zlib 1.2.7
2016-09-05 16:51:19 140651905369920 [Note] InnoDB: Using SSE crc32 instructions
2016-09-05 16:51:19 140651905369920 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-09-05 16:51:19 140651905369920 [Note] InnoDB: Completed initialization of buffer pool
2016-09-05 16:51:20 140651905369920 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-09-05 16:51:20 140651905369920 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-09-05 16:51:20 140651905369920 [Note] InnoDB: Database physically writes the file full: wait...
2016-09-05 16:51:20 140651905369920 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-09-05 16:51:21 140651905369920 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-09-05 16:51:23 140651905369920 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-09-05 16:51:23 140651905369920 [Warning] InnoDB: New log files created, LSN=45883
2016-09-05 16:51:23 140651905369920 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-09-05 16:51:23 140651905369920 [Note] InnoDB: Doublewrite buffer created
2016-09-05 16:51:23 140651905369920 [Note] InnoDB: 128 rollback segment(s) are active.
2016-09-05 16:51:23 140651905369920 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-09-05 16:51:23 140651905369920 [Note] InnoDB: Foreign key constraint system tables created
2016-09-05 16:51:23 140651905369920 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-09-05 16:51:23 140651905369920 [Note] InnoDB: Tablespace and datafile system tables created.
2016-09-05 16:51:23 140651905369920 [Note] InnoDB: Waiting for purge to start
2016-09-05 16:51:23 140651905369920 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.30-76.3 started; log sequence number 0
2016-09-05 16:51:23 140650934671104 [Note] InnoDB: Dumping buffer pool(s) not yet started
OK
Filling help tables...
2016-09-05 16:51:26 139853976782656 [Note] ./bin/mysqld (mysqld 10.1.16-MariaDB) starting as process 26120 ...
2016-09-05 16:51:26 139853976782656 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2016-09-05 16:51:26 139853976782656 [Note] InnoDB: The InnoDB memory heap is disabled
2016-09-05 16:51:26 139853976782656 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-09-05 16:51:26 139853976782656 [Note] InnoDB: Memory barrier is not used
2016-09-05 16:51:26 139853976782656 [Note] InnoDB: Compressed tables use zlib 1.2.7
2016-09-05 16:51:26 139853976782656 [Note] InnoDB: Using SSE crc32 instructions
2016-09-05 16:51:26 139853976782656 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-09-05 16:51:26 139853976782656 [Note] InnoDB: Completed initialization of buffer pool
2016-09-05 16:51:27 139853976782656 [Note] InnoDB: Highest supported file format is Barracuda.
2016-09-05 16:51:27 139853976782656 [Note] InnoDB: 128 rollback segment(s) are active.
2016-09-05 16:51:27 139853976782656 [Note] InnoDB: Waiting for purge to start
2016-09-05 16:51:27 139853976782656 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.30-76.3 started; log sequence number 1616799
2016-09-05 16:51:27 139853211293440 [Note] InnoDB: Dumping buffer pool(s) not yet started
OK
Creating OpenGIS required SP-s...
2016-09-05 16:51:29 140009341257536 [Note] ./bin/mysqld (mysqld 10.1.16-MariaDB) starting as process 26150 ...
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: The InnoDB memory heap is disabled
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Memory barrier is not used
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Compressed tables use zlib 1.2.7
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Using SSE crc32 instructions
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Completed initialization of buffer pool
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Highest supported file format is Barracuda.
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: 128 rollback segment(s) are active.
2016-09-05 16:51:29 140009341257536 [Note] InnoDB: Waiting for purge to start
2016-09-05 16:51:29 140009341257536 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.30-76.3 started; log sequence number 1616809
2016-09-05 16:51:29 140008576706304 [Note] InnoDB: Dumping buffer pool(s) not yet started
OK

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'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

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

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from MariaDB
Corporation Ab. You can contact us about this at sales@mariadb.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

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

要修改 /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 已經設定完成,你可以透過下面的指令來啟動服務.

[root@benjr ~]# /usr/local/mysql/bin/mysqld_safe --datadir='/var/lib/mysql' &
[1] 28830
[root@benjrmysql]# 160906 12:31:07 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
160906 12:31:07 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[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-09-04 13:45:21 CST; 31s ago
     Docs: man:systemd-sysv-generator(8)
  Control: 1153 (mysql)
   CGroup: /system.slice/mysql.service
           ├─1153 /bin/sh /etc/rc.d/init.d/mysql start
           ├─1174 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/lib...
           ├─1527 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/var/lib/mysql --plu...
           └─2602 sleep 1

 9月 04 13:45:21 benjr systemd[1]: Starting LSB: start and stop MySQL...

透過 #systemctl status mysql 會看到三個服務在裡面 mysql , mysqld , mysqld_safe , 他們所代表的是.

  • mysql
    mysql (MySQL command-line tool), mysql is a simple SQL shell
  • mysqld
    mysqld (MySQL server), also known as MySQL Server,
  • mysqld_safe
    mysqld_safe (MySQL server startup script) ,mysqld_safe is the recommended way to start a mysqld server on Unix and NetWare. mysqld_safe adds some safety features such as restarting the server when an error occursand logging runtime information to an error log file.

或是可以透過 netstat (package : net-tools) 來看狀態(MySQL port 3306).

[root@benjr ~]# netstat -anlp | grep -e 3306
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

設定 MySql

安裝完之後第一步就是要設定 MySQL ,我們可以透過 #mysql , #mysqladmin 指令或是透過 #mysql_secure_installation 來設定,透過指令可以參考這一篇的說明 http://benjr.tw/12461

[root@benjr ~]# mysql_secure_installation 
/usr/bin/mysql_secure_installation: line 379: find_mysql_client:命令找不到

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] 
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'benjr'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

設定完 Mariadb 的密碼後就需要透過密碼來登入 Mariadb 了.

[root@benjr ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.1.16-MariaDB Source distribution

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> quit;
Bye

發表迴響