編譯安裝MariaDB-10.0.21


一、源碼編譯安裝gcc-5.1.0

1、下載gcc源碼包

 

2、解壓壓縮包

1
[root@example.com ~] # tar -xf  gcc-5.1.0.tar.gz

 

3、下載編譯所需的依賴包

這個步驟有兩種方式完成: 

a) 如果Linux有網絡連接,直接這樣:

1
2
[root@example.com ~] # cd gcc-5.1.0
[root@example.com gcc-5.1.0] # ./contrib/download_prerequisites

b) 如果Linux沒有網絡連接(我主機和虛擬機是Host-only,不能聯網,所以另外想辦法),則用Windows上網下載這幾個包:

ftp://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2

http://www.mpfr.org/mpfr-2.4.2/mpfr-2.4.2.tar.bz2

http://www.multiprecision.org/mpc/download/mpc-0.8.1.tar.gz

然后解壓並移動到gcc-4.8.1下面:

tar -xjf gmp-4.3.2.tar.bz2

tar -xjf mpfr-2.4.2.tar.bz2

tar -xzf mpc-0.8.1.tar.gz

mv gmp-4.3.2 gcc-4.8.1/gmp

mv mpfr-2.4.2 gcc-4.8.1/mpfr

mv mpc-0.8.1 gcc-4.8.1/mpc

   這樣的做法好處是,不用單獨編譯gmp、mpfr和mpc三個包,放在gcc源碼下面一起編譯(事實上這也是gcc-4.8.1/contrib/download_prerequisites腳本的做法,個人感覺更簡潔些)。我在編譯是選擇了第一種方法,第二種方法到底咋樣本人沒有實驗過。

 

4、編譯安裝gcc

1
2
3
4
[root@example.com gcc-5.1.0] # yum install -y  gcc-c++  glibc-static gcc //為避免出錯建議安裝此包
[root@example.com gcc-5.1.0] #  ./configure --prefix=/usr/local/gcc  --enable-bootstrap  --enable-checking=release --enable-languages=c,c++ --disable-multilib
[root@example.com gcc-5.1.0] # make
[root@example.com gcc-5.1.0] # make install

編譯參數說明:

  • --prefix=/usr/local/   指定安裝路徑

  • --enable-bootstrap  這里引用網上一些文獻對該參數的解釋:用第一次編譯生成的程序進行第二次編譯,然后用再次生成的程序進行第三次編譯,並且檢查比較第二次和第三次結果的正確性,也就是進行冗余的編譯檢查工作。 非交叉編譯環境下,默認已經將該值設為 enable,可以不用顯示指定;交叉編譯環境下,需要顯示將其值設為 disable。     

  • --enable-checking=release  以軟件發布版的標准來對編譯時生成的代碼進行一致性檢查;設置該選項為 enable並不會改變編譯器生成的二進制結果,但是會導致編譯的時間增加;該選項僅支持gcc編譯器; 總體而言,對於上面這個選項,機器的硬件配置較低,以及不願等待太久編譯時間的童鞋,可以設置為 disable;但是這會增加產生未預期的錯誤的風險,所以應該慎用。 可以同時設置 --disable-bootstrap 與  --disable-checking,這對編譯過程的提速很有幫助。

  • --enable-threads=posix   顧名思義,啟用posix標准的線程支持 ,要讓程序能在符合POSIX規范的linux發布版上正確運行,就應該啟用該選項,取決於宿主或目標操作系統的類型,其它可用值有:aix,dec,solaris,win32等,如果你是其它的類UNIX系統,就需要設置相應的值。

  • --enable-languages=c,c++   支持的高級語言類型和運行時庫,可以設置的所有語言包括 ada,c,c++,Fortran,java,objc,obj-c++,GO 等語言。這里只開啟了c和c++,因為支持的語言越多,就需要安裝越多的相應靜態與動態庫,還有五花八門的依賴庫,這會讓管理變得困難,體積也會變得龐大。

  • --disable-multilib    如果你的操作系統是32位,默認就已經設置為 disable,這意味着gcc僅能生成32位的可執行程序;如果你的操作系統是64位,默認就已經設置為 enable,這意味着用gcc編譯其它源文件時可以通過 -m32 選項來決定是否生成32位機器代碼。如果在64位系統上,要禁止生成32位代碼, 設置 --disable-multilib。

  • --enable-gather-detailed-mem-stats  允許收集詳細的內存使用信息,如果設置該參數為 enable,則將來編譯好的gcc可執行程序,可以通過 -fmem-report 選項來輸出編譯其它程序時的實時內存使用情況。

  • --with-long-double-128  指定 long double 類型為128位(16字節!);設置為 without,則 long double類型將為64位(8字節),這將與普通的 double 類型一樣。 基於 Glib 2.4以上版本編譯時,默認已經是128位。 

 

5、后續操作

導出環境變量:

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@example.com ~] # gcc --version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16)
Copyright  2010 Free Software Foundation, Inc.
本程序是自由軟件;請參看源代碼的版權聲明。本軟件沒有任何擔保;
包括沒有適銷性和某一專用目的下的適用性擔保。
[root@example.com ~] # vim /etc/profile.d/gcc.sh
export  PATH= /usr/local/gcc/bin :$PATH
[root@example.com ~] # source /etc/profile.d/gcc.sh
[root@example.com ~] # gcc --version
gcc (GCC) 5.1.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is  free  software; see the  source  for  copying conditions.  There is NO
warranty; not even  for  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

 

導出頭文件:

1
2
[root@example.com ~] # ln -sv /usr/local/gcc/include/ /usr/include/gcc
"/usr/include/gcc"  ->  "/usr/local/gcc/include/"

 

導出庫文件:

1
2
3
4
[root@example.com ~] # vim /etc/ld.so.conf.d/gcc.conf
/usr/local/gcc/lib64
[root@example.com ~] # ldconfig -v
[root@example.com ~] # ldconfig -p |grep gcc  //驗證是否導出

 

二、源碼編譯MariaDB

為啥開頭要安裝gcc-5.1,就是因為我在第一次編譯mariadb時,到make的時候報錯,在網上找到的這么一句哈:

http://www.linuxfromscratch.org/blfs/view/svn/server/mariadb.html

MariaDB is a community-developed fork and a drop-in replacement for the MySQL relational database management system.

This package is known to build and work properly using an LFS-7.7 platform.

This package is known to build and work properly using the gcc-5 compiler.

MariaDB是一個由社區開發的叉和MySQL的替代關系數據庫管理系統。

這個包是構建和使用lfs - 7.7平台正常工作。

這個包是構建和使用gcc-5編譯器正常工作。

 

1、創建數據存放目錄

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@example.com mysql] # yum install -y lvm2
[root@example.com ~] # fdisk /dev/sdb
n
p
1
  
+10G
t
8e
w
[root@example.com ~] # pvcreate /dev/sdb1
   Physical volume  "/dev/sdb1"  successfully created
[root@example.com ~] # vgcreate data /dev/sdb1
   Volume group  "data"  successfully created
[root@example.com ~] # lvcreate -L 2G -n mydata data
   Logical volume  "mydata"  created.
[root@example.com ~] # mke2fs -t ext4 -L MYDATA -b 4096 -m 3 /dev/data/mydata 
[root@example.com ~] # vim /etc/fstab 
LABEL=MYDATA             /data/mydata             ext4    defaults,noatime 0 0
[root@example.com ~] # mount -a
[root@example.com ~] # chown -R mysql.mysql /data/mydata/

 

2、創建mysql用戶

1
2
3
4
5
[root@example.com ~] # groupadd mysql 
[root@example.com ~] # useradd -s /sbin/nologin -g mysql -M mysql
[root@example.com ~] # id mysql
uid=1001(mysql) gid=1001(mysql) 組=1001(mysql)
[root@example.com ~] # mkdir -pv  /data/mydata

 

3、安裝mariadb

1
2
3
4
5
6
[root@example.com ~] # tar -xf mariadb-10.0.21.tar.gz 
[root@example.com ~] # yum install -y ncurses-devel openssl-devel openssl gcc-c++ cmake
[root@example.com ~] # cd mariadb-10.0.21
[root@example.com mariadb-10.0.21] # cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata -DSYSCONFDIR=/etc  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
[root@example.com mariadb-10.0.21] #make
[root@example.com mariadb-10.0.21] #make  install

 

4、參數說明

# 安裝根目錄

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql

# 數據存儲目錄

-DMYSQL_DATADIR=/data/mydata

# UNIX socket文件

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock

# 配置文件(my.cnf)目錄

-DSYSCONFDIR=/etc

# 默認字符集

-DDEFAULT_CHARSET=utf8

# 默認字符校對

-DDEFAULT_COLLATION=utf8_general_ci

# TCP/IP端口

-DMYSQL_TCP_PORT=3306 

# * ARCHIVE 引擎支持

-DWITH_ARCHIVE_STORAGE_ENGINE=1 

# * ARIA 引擎支持

-DWITH_ARIA_STORAGE_ENGINE=1

# * BLACKHOLE 引擎支持

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 

# * FEDERATEDX 引擎支持

-DWITH_FEDERATEDX_STORAGE_ENGINE=1

# * PARTITION 引擎支持

-DWITH_PARTITION_STORAGE_ENGINE=1 

# * PERFSCHEMA 引擎支持

-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 

# * SPHINX 引擎支持

-DWITH_SPHINX_STORAGE_ENGINE=1

# * XTRADB 支持

-DWITH_XTRADB_STORAGE_ENGINE=1 

# * innoDB 引擎支持

-DWITH_INNOBASE_STORAGE_ENGINE=1

# * Myisam 引擎支持

-DWITH_MYISAM_STORAGE_ENGINE=1

# readline庫

-DWITH_READLINE=1 

# 啟用加載本地數據

-DENABLED_LOCAL_INFILE=1

# 擴展支持編碼 ( all | utf8,gbk,gb2312 | none )

-DWITH_EXTRA_CHARSETS=all

# 擴展字符支持

-DEXTRA_CHARSETS=all

# 系統傳輸使用SSL加密

-DWITH_SSL=system

# 系統傳輸使用zlib壓縮,節約帶寬

-DWITH_ZLIB=system

# libwrap庫

-DWITH_LIBWRAP=0

# 運行用戶

-DMYSQL_USER=mysql

# 調試模式

-DWITH_DEBUG=0

 

5、編譯引擎選項說明

默認編譯的存儲引擎包括:csv、myisam、myisammrg和heap。若要安裝其它存儲引擎,可以使用類似如下編譯選項:

-DWITH_INNOBASE_STORAGE_ENGINE=1

-DWITH_ARCHIVE_STORAGE_ENGINE=1

-DWITH_BLACKHOLE_STORAGE_ENGINE=1

-DWITH_FEDERATED_STORAGE_ENGINE=1

若要明確指定不編譯某存儲引擎,可以使用類似如下的選項:

-DWITHOUT_<ENGINE>_STORAGE_ENGINE=1

比如:

-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1

-DWITHOUT_FEDERATED_STORAGE_ENGINE=1

-DWITHOUT_PARTITION_STORAGE_ENGINE=1

 

6、編譯時錯誤解決方法

重新編譯時,需要清除舊的對象文件和緩存信息。

#make clean

#rm -f CMakeCache.txt

#rm -rf /etc/my.cnf

錯誤:Curses library not found.  Please install appropriate package,

解決方案:

先安裝 ncurses-devel 包

yum install ncurses-devel

再刪除剛才編譯生成的 CMakeCache.txt 文件

rm CMakeCache.txt

再次執行一次cmake ...

一般都可以順利安裝的。

 

7、配置MariaDB

初始化數據庫:

1
2
3
4
5
[root@example.com mariadb-10.0.21] # cd /usr/local/mysql/
[root@example.com mysql] # scripts/mysql_install_db --user=mysql --datadir=/data/mydata/
[root@example.com mysql] # ls /data/mydata/
aria_log.00000001  ibdata1      ib_logfile1  mysql              
testaria_log_control   ib_logfile0  lost+found   performance_schema

 

設置配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@example.com mysql] # vim /etc/my.cnf
[mysqld]
port            = 3306
socket          =  /tmp/mysql .sock
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 4
datadir= /data/mydata    // 需要添加此項

 

設置啟動腳本:

1
2
3
4
[root@example.com mysql] # cp support-files/mysql.server /etc/init.d/mysqld
[root@example.com mysql] # chkconfig --add mysqld
[root@example.com mysql] # chkconfig --list mysqld
mysqld         0:關閉1:關閉2:啟用3:啟用4:啟用5:啟用6:關閉

 

啟動服務:

1
2
3
4
[root@example.com mysql] # service mysqld start
Starting MySQL. SUCCESS! 
[root@example.com mysql] # ss -tunl |grep 3306
tcp    LISTEN     0      128                   :::3306                 :::*

 

導出環境變量:

1
2
3
[root@example.com mysql] # vim /etc/profile.d/mysql.sh
export  PATH= /usr/local/mysql/bin :$PATH
[root@example.com mysql] # source /etc/profile.d/mysql.sh

 

導出頭文件:

1
2
[root@example.com mysql] # ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
"/usr/local/include/mysql"  ->  "/usr/local/mysql/include/"

 

導出庫文件:

1
2
3
4
5
6
7
8
[root@example.com mysql] # vim /etc/ld.so.conf.d/mysql.conf
/usr/local/mysql/lib
[root@example.com mysql] # ldconfig -v
[root@example.com mysql] # ldconfig -p |grep mysql
libmysqlclient_r.so.16 (libc6,x86-64) =>  /usr/lib64/mysql/libmysqlclient_r .so.16
libmysqlclient.so.18 (libc6,x86-64) =>  /usr/local/mysql/lib/libmysqlclient .so.18
libmysqlclient.so.16 (libc6,x86-64) =>  /usr/lib64/mysql/libmysqlclient .so.16
libmysqlclient.so (libc6,x86-64) =>  /usr/local/mysql/lib/libmysqlclient .so

 

設置數據庫用戶密碼:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[root@example.com mysql] # mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id  is 4
Server version: 10.0.21-MariaDB-log Source distribution
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
MariaDB [(none)]> GRANT ALL PRIVILEGES on *.* to root@ 'localhost'  IDENTIFIED BY  'redhat' ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL PRIVILEGES on *.* to root@ '127.0.0.1'  IDENTIFIED BY  'redhat' ;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> use mysql
Database changed
MariaDB [mysql]> SET PASSWORD FOR root@ 'example.com'  =PASSWORD( 'redhat' );
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> SELECT Host,User,Password FROM user ;
+-------------+------+-------------------------------------------+
| Host        | User | Password                                  |
+-------------+------+-------------------------------------------+
| localhost   | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| example.com | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| 127.0.0.1   | root | *84BB5DF4823DA319BBF86C99624479A198E6EEE9 |
| ::1         | root |                                           |
| localhost   |      |                                           |
| example.com |      |                                           |
+-------------+------+-------------------------------------------+
6 rows  in  set  (0.00 sec)

 

使用mysql_secure_installation這個腳本來進行安全配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
[root@example.com bin] # mysql_secure_installation
/usr/local/mysql/bin/mysql_secure_installation : line 379: find_mysql_client:  command  not found
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.
You already have a root password  set , so you can safely answer  'n' .
#改變root用戶的密碼;
Change the root password? [Y /n ] Y
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 ] Y
  ... Success!
Normally, root should only be allowed to connect from  'localhost' .  This
ensures that someone cannot guess at the root password from the network.
#禁止root用戶遠程登錄;
Disallow root login remotely? [Y /n ] Y
  ... 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.
#不移除test數據庫;
Remove  test  database and access to it? [Y /n ] n
  ... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
#重載授權表生效;
Reload privilege tables now? [Y /n ] Y
  ... 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!

 

現mysql不輸入用戶名密碼直接登錄數據庫

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@example.com ~] # vim .my.cnf
[mysql]
user = root
password = redhat
host = localhost
[root@example.com ~] # mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection  id  is 14
Server version: 10.0.21-MariaDB-log Source distribution
 
Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
 
Type  'help;'  or  '\h'  for  help. Type  '\c'  to  clear  the current input statement.
 
MariaDB [(none)]>

 

8、小技巧

由於make時間較久,一般可以使用-j 選項在加CPU核心說就能加速,下面就是自動查看當前系統CPU核心並根據核心數進行編譯。

[ "`cat /proc/cpuinfo |grep 'processor'|wc -l`" = "1" ] && make

[ "`cat /proc/cpuinfo |grep 'processor'|wc -l`" != "1" ] && make -j`cat /proc/cpuinfo |grep 'processor'|wc -l`

 

本文出自http://cuchadanfan.blog.51cto.com/9940284/1689556


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM