CentOS 7 編譯 MariaDB 5.5.51

Loading

以前要編譯 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 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 update
[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

編輯步驟很簡單,如下:

[root@benjr ~]# tar mariadb-5.5.51.tar.gz
[root@benjr ~]# cd  mariadb-5.5.51
[root@benjr mariadb-5.5.51]# cmake .
......
-- Configuring done
-- Generating done
-- Build files have been written to: /root/mariadb-5.5.51

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

如果你要支援 wsrep api 請選擇 MariaDB database server 10.1 之後的版本或是 MariaDB Galera 的版本,並需要在編譯的時候還是加入這一些參數 -DWITH_WSREP=ON -DWITH_INNODB_DISALLOW_WRITES=ON ,這個參數可以在編譯的時候讓 MariaDB 支援 Galera Cluster the wsrep (Write-Set Replication) API.

[root@benjr mariadb-5.5.51]# make 
.....
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/mysql_client_test_embedded.1

make , make install 終於也成功了.

編譯問題可以參考 MariaDB 常見問題 https://benjr.tw/95335

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

或是

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

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 13:38:13 [Note] ./bin/mysqld (mysqld 5.5.51-MariaDB) starting as process 25196 ...
OK
Filling help tables...
160904 13:38:13 [Note] ./bin/mysqld (mysqld 5.5.51-MariaDB) starting as process 25204 ...
OK
Creating OpenGIS required SP-s...

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' &
160904 13:41:22 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
160904 13:41:22 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 

設定 MySql

安裝完之後第一步就是要設定 MySQL ,我們可以透過 #mysql , #mysqladmin 指令或是透過 #mysql_secure_installation 來設定,透過指令可以參考這一篇的說明 https://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 2
Server version: 5.5.51-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
沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料