centos7編譯安裝mariadb-10.4.6

centos7編譯安裝mariadb-10.4.6

在centos7.3, centos7.6上都試過了,都可以安裝成功,並隱藏版本號。
下載相關依賴:https://download.csdn.net/download/paincupid/11388112

一、安裝依賴(準備工作)

1、安裝gcc等依賴

yum install openssl openssl-devel ncurses ncurses-devel bison bison-devel jemalloc jemalloc-devel centos-release-scl devtoolset-7  gcc gcc-c++

2、安裝cmake

cmake版本要高於3.10

https://cmake.org/download/

./bootstrap && 
gmake && 
gmake install

查看編譯後的cmake版本

/usr/local/bin/cmake --version

如果存在舊版本,移除原來的cmake版本並新建軟鏈接

yum remove cmake -y
ln -s /usr/local/bin/cmake /usr/bin/

cmake --version

如果萬一執行中有了錯誤,可以執行:rm -f CMakeCache.txt 刪除編譯緩存

3、安裝libevent

libevent-2.1.10

./configure --prefix=/usr --disable-static &&
make
make install

2、安裝C++高版本

MariaDB 編譯 TokuDB 引擎時會用到 C++11 標準,系統裏 GCC 最高版本 4.8.5 是支持 C++11 標準的,可就算指定了 -DCMAKE_CXX_FLAGS=-std=c++11 也不行。手動編譯更高版本的 GCC 又太麻煩,這裏直接安裝了 devtoolset-7,當然你禁用 TokuDB 引擎也無可厚非。

yum install centos-release-scl devtoolset-7
gcc --version
// gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-28)
// Copyright © 2015 Free Software Foundation, Inc.

scl enable devtoolset-7 bash
// or
. /opt/rh/devtoolset-7/enable

gcc --version
// gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

scl enable devtoolset-7 bash 命令重啓後會失效

二、編譯安裝mariadb

1、下載mariadb

下載地址:

https://downloads.mariadb.org/

https://downloads.mariadb.org/interstitial/mariadb-10.4.6/source/mariadb-10.4.6.tar.gz

2、解壓文件

tar -zxvf mariadb-10.4.6.tar.gz
cd mariadb-10.4.6

3、修改版本號

vi VERSION

修改爲

MYSQL_VERSION_MAJOR=101
MYSQL_VERSION_MINOR=42
MYSQL_VERSION_PATCH=63
SERVER_MATURITY=stable

4、爲mariadb創建用戶組和用戶

groupadd -g 41 mysql &&
useradd -c "MySQL Server" -d /srv/mysql -g mysql -s /bin/false -u 41 mysql

5、安裝mariadb

sed -i "s@data/test@\${INSTALL_MYSQLTESTDIR}@g" sql/CMakeLists.txt &&

mkdir build &&
cd    build &&

cmake -DCMAKE_BUILD_TYPE=Release                      \
      -DCMAKE_INSTALL_PREFIX=/usr                     \
      -DINSTALL_DOCDIR=share/doc/mariadb-10.4.6       \
      -DINSTALL_DOCREADMEDIR=share/doc/mariadb-10.4.6 \
      -DINSTALL_MANDIR=share/man                      \
      -DINSTALL_MYSQLSHAREDIR=share/mysql             \
      -DINSTALL_MYSQLTESTDIR=share/mysql/test         \
      -DINSTALL_PLUGINDIR=lib/mysql/plugin            \
      -DINSTALL_SBINDIR=sbin                          \
      -DINSTALL_SCRIPTDIR=bin                         \
      -DINSTALL_SQLBENCHDIR=share/mysql/bench         \
      -DINSTALL_SUPPORTFILESDIR=share/mysql           \
      -DMYSQL_DATADIR=/srv/mysql                      \
      -DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock       \
      -DWITH_EXTRA_CHARSETS=complex                   \
      -DWITH_EMBEDDED_SERVER=ON                       \
      -DSKIP_TESTS=ON                                 \
      -DTOKUDB_OK=0                                   \
      .. &&
make

-DCMAKE_INSTALL_PREFIX= 指向mysql安裝目錄
-DINSTALL_SBINDIR=sbin 指向可執行文件目錄(prefix/sbin)
-DMYSQL_DATADIR=/var/lib/mysql 指向mysql數據文件目錄(/var/lib/mysql)
-DSYSCONFDIR=/etc/mysql 指向mysql配置文件目錄(/etc/mysql)
-DINSTALL_PLUGINDIR=lib/mysql/plugin 指向插件目(prefix/lib/mysql/plugin)
-DINSTALL_MANDIR=share/man 指向man文檔目錄(prefix/share/man)
-DINSTALL_SHAREDIR=share 指向aclocal/mysql.m4安裝目錄(prefix/share)
-DINSTALL_LIBDIR=lib/mysql 指向對象代碼庫目錄(prefix/lib/mysql)
-DINSTALL_INCLUDEDIR=include/mysql 指向頭文件目錄(prefix/include/mysql)
-DINSTALL_INFODIR=share/info 指向info文檔存放目錄(prefix/share/info)
prefix官方推薦設爲/usr

結果

Scanning dependencies of target SYM_mariadb-fix-extensions
[100%] mklink mysql_fix_extensions -> mariadb-fix-extensions
[100%] Built target SYM_mariadb-fix-extensions
Scanning dependencies of target symlink_wsrep_sst_rsync
[100%] Generating wsrep_sst_rsync_wan
[100%] Built target symlink_wsrep_sst_rsync
Scanning dependencies of target SYM_mariadb-secure-installation
[100%] mklink mysql_secure_installation -> mariadb-secure-installation
[100%] Built target SYM_mariadb-secure-installation
Scanning dependencies of target SYM_mariadb-access
[100%] mklink mysqlaccess -> mariadb-access
[100%] Built target SYM_mariadb-access
Scanning dependencies of target SYM_mariadb-hotcopy
[100%] mklink mysqlhotcopy -> mariadb-hotcopy
[100%] Built target SYM_mariadb-hotcopy
Scanning dependencies of target SYM_mariadb-convert-table-format
[100%] mklink mysql_convert_table_format -> mariadb-convert-table-format
[100%] Built target SYM_mariadb-convert-table-format
Scanning dependencies of target SYM_mariadb-dumpslow
[100%] mklink mysqldumpslow -> mariadb-dumpslow
[100%] Built target SYM_mariadb-dumpslow
Scanning dependencies of target SYM_mariadb-setpermission
[100%] mklink mysql_setpermission -> mariadb-setpermission
[100%] Built target SYM_mariadb-setpermission
Scanning dependencies of target SYM_mariadb-install-db
[100%] mklink mysql_install_db -> mariadb-install-db
[100%] Built target SYM_mariadb-install-db
Scanning dependencies of target SYM_mariadbd-multi
[100%] mklink mysqld_multi -> mariadbd-multi
[100%] Built target SYM_mariadbd-multi
Scanning dependencies of target SYM_mariadb-find-rows
[100%] mklink mysql_find_rows -> mariadb-find-rows
[100%] Built target SYM_mariadb-find-rows
Scanning dependencies of target SYM_mariadbd-safe
[100%] mklink mysqld_safe -> mariadbd-safe
[100%] Built target SYM_mariadbd-safe
Scanning dependencies of target mariadb-pp
[100%] Generating mariadb.pp
/usr/bin/checkmodule:  loading policy configuration from /root/mariadb-10.4.6/support-files/policy/selinux/mariadb.te
/usr/bin/checkmodule:  policy configuration loaded
/usr/bin/checkmodule:  writing binary representation (version 19) to /root/mariadb-10.4.6/build/support-files/CMakeFiles/mariadb-pp.dir/mariadb.mod
[100%] Built target mariadb-pp
[root@localhost build]#

make install 

6、創建文件/etc/mysql/my.cnf

install -v -dm 755 /etc/mysql &&
cat > /etc/mysql/my.cnf << "EOF"
# Begin /etc/mysql/my.cnf

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /run/mysqld/mysqld.sock

# The MySQL server
[mysqld]
port            = 3306
socket          = /run/mysqld/mysqld.sock
datadir         = /srv/mysql
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 16K
myisam_sort_buffer_size = 8M

# Don't listen on a TCP/IP port at all.
skip-networking

# required unique id between 1 and 2^32 - 1
server-id       = 1

# Uncomment the following if you are using BDB tables
#bdb_cache_size = 4M
#bdb_max_lock = 10000

# InnoDB tables are now used by default
innodb_data_home_dir = /srv/mysql
innodb_log_group_home_dir = /srv/mysql
# All the innodb_xxx values below are the default ones:
innodb_data_file_path = ibdata1:12M:autoextend
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 128M
innodb_log_file_size = 48M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates

[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

# End /etc/mysql/my.cnf
EOF

7、初始化數據庫以及修改所有者權限

mysql_install_db --basedir=/usr --datadir=/srv/mysql --user=mysql &&
chown -R mysql:mysql /srv/mysql

如果執行的報以下錯誤

[root@localhost build]# mysql_install_db --basedir=/usr --datadir=/srv/mysql --user=mysql &&
> chown -R mysql:mysql /srv/mysql
chown: cannot access ‘/auth_pam_tool_dir’: No such file or directory
Cannot change ownership of the '/auth_pam_tool_dir' directory
 to the 'mysql' user. Check that you have the necessary permissions and try again.

解決方案:可以複製一份mysql_install_db替換它,再執行上面的命令。mysql_install_dbscript目錄下。mysql_install_db在分享的下載包中。

cd /usr/bin
mv mysql_install_db mysql_install_db_bak
cp /root/mysql_install_db /usr/bin

執行成功,會有以下提示

[root@localhost bin]# mysql_install_db --basedir=/usr --datadir=/srv/mysql --user=mysql &&
> chown -R mysql:mysql /srv/mysql
Installing MariaDB/MySQL system tables in '/srv/mysql' ...
2019-07-17  7:42:53 0 [Note] /usr/sbin/mysqld (mysqld 101.42.63-MariaDB) starting as process 6129 ...
OK
Filling help tables...
2019-07-17  7:42:53 0 [Note] /usr/sbin/mysqld (mysqld 101.42.63-MariaDB) starting as process 6136 ...
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:

'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
'/usr/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 '/usr' ; /usr/bin/mysqld_safe --datadir='/srv/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/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
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/

8、啓動mysql

 cp /root/mariadb-10.4.6/build/support-files/mysql.server /etc/init.d/mysqld
 chmod +x /etc/init.d/mysqld
 update-rc.d mysqld defaults
 chkconfig --add mysqld
 /etc/init.d/mysqld restart
 systemctl status mysqld

9、爲root用戶設置密碼

'/usr/bin/mysqladmin' -u root password 'root'

10、登陸

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

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

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

MariaDB [(none)]> select version();
+-------------------+
| version()         |
+-------------------+
| 101.42.63-MariaDB |
+-------------------+
1 row in set (0.000 sec)

MariaDB [(none)]>

參考:

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章