はじめに
MySQLからの移行者も徐々に増え始めmariaDB。
MariaDB11.6.2をソースからコンパイルしてインストールする方法をメモしておきます。
MariaDB11.3系は、圧縮などの機能が強化されているようで、bzip2やsnappyなどのライブラリが必要になり、11.0系に比べて、必要なライブラリが増えています。こちらでは必要なライブラリも併せてビルドする内容にしています。
2024年5月現在、「11.3.2」が最新版です。
実践環境バージョン情報
ソフトウェア | バージョン |
---|---|
OpenSSL | 3.4.0 |
CMake | 3.29.2 |
ncruse | 6.3 |
libssh2 | 1.11.0 |
curl | 8.7.1 |
bzip2 | 1.0.8 |
lzo | 2.10 |
snappy | 1.2.1 |
MariDB | 11.6.2 |
OS | RockeyLinux 9.x and Ubuntu 22.04.2 |
準備
稼働用のユーザーを作成する
bash
useradd mysql
必要なライブラリを入れる
bash
dnf install libpsl libpsl-devel
Cmakeをインストールする
cd /usr/local/src
wget https://github.com/Kitware/CMake/archive/refs/tags/v3.31.5.tar.gz
tar xvzf v3.31.5.tar.gz
cd CMake-3.31.5
#環境変数を設定する
export OPENSSL_ROOT_DIR=/usr/local/ssl
export PKG_CONFIG_PATH=/usr/local/ssl/lib:$PKG_CONFIG_PATH
./configure
gmake -j 8
make install
もしエラーになった場合
rm CMakeCache.txt
を実行して再度行ってみましょう
ncruseをインストール
bash
cd /usr/local/src
wget https://invisible-island.net/datafiles/release/ncurses.tar.gz
tar xvzf ncurses.tar.gz
cd ncurses-6.3
./configure --with-shared
make
make install
libssh2を入れる
bash
#libssh2
cd /usr/local/src
wget https://libssh2.org/download/libssh2-1.11.1.tar.gz
tar xvzf libssh2-1.11.1.tar.gz
cd libssh2-1.11.1
export LDFLAGS="-L/usr/local/ssl/lib64"
export CPPFLAGS="-I/usr/local/ssl/include"
export CFLAGS="-I/usr/local/ssl/include"
./configure \
--with-openssl=/usr/local/ssl \
--with-libssl-prefix=/usr/local/ssl/include/openssl
make -j 8
make install
PSI
bash
#cd /usr/local/src
#wget https://github.com/osu-crypto/libPSI/archive/refs/tags/v1.1.0.tar.gz
#tar xvzf v1.1.0.tar.gz
#cd libPSI-1.1.0
curlを入れる
bash
cd /usr/local/src
wget https://github.com/curl/curl/releases/download/curl-8_11_1/curl-8.11.1.tar.gz
tar xvzf curl-8.11.1.tar.gz
cd curl-8.11.1
#OpenSSL3.2以下および3.4以上の場所を明示
CPPFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib"
#OpenSSL3.3系は以下を参照
CPPFLAGS="-I/usr/local/ssl/include" LDFLAGS="-L/usr/local/ssl/lib64"
./configure \
--enable-http \
--enable-ftp \
--enable-file \
--enable-proxy \
--enable-cookies \
--enable-ipv6 \
--with-zlib=/usr/local \
--with-libssh2=/usr/local \
--disable-openssl-auto-load-config \
--with-openssl=/usr/local/ssl #OpenSSL 3系など新しい場合はこちら
make -j 4
make install
bzip2を入れる
cd /usr/local/src
wget https://sourceware.org/pub/bzip2/bzip2-latest.tar.gz
tar xvzf bzip2-latest.tar.gz
cd bzip2-1.0.8
make -f Makefile-libbz2_so
make
make install
LZOを入れる
bash
cd /usr/local/src
wget https://www.oberhumer.com/opensource/lzo/download/lzo-2.10.tar.gz
tar xvzf lzo-2.10.tar.gz
cd lzo-2.10
./configure
make -j 4
make install
google snappyを入れる
cd /usr/local/src
mkdir snappy
cd snappy
wget https://github.com/google/snappy/archive/refs/tags/1.2.1.tar.gz
tar xvzf 1.2.1.tar.gz
cd snappy-1.2.1/third_party
mv benchmark benchmark.def
mv googletest googletest.def
#
#third_partyディレクトリにbenchmarkとgoogletestのソースを配置する
#
wget https://github.com/google/benchmark/archive/refs/tags/v1.9.1.tar.gz
tar xvzf v1.9.1.tar.gz
mv benchmark-1.9.1 benchmark
wget https://github.com/google/googletest/archive/refs/tags/v1.15.2.tar.gz
tar xvzf v1.15.2.tar.gz
mv googletest-1.15.2 googletest
cd ..
mkdir build
Sharedを有効化する
vi CMakeLists.txt
#これをONにして保存
option(BUILD_SHARED_LIBS "Build shared libraries(DLLs)." ON)
#以下を追加
set(CMAKE_C_FLAGS"${CMAKE_C_FLAGS}-fPIC")
set(CMAKE_CXX_FLAFS "${CMAKE_CXX_FLAGS}-fPIC")
cd build
/usr/local/bin/cmake ../ -DCMAKE_POSITION_INDEPENDENT_CODE=ON
make
make install
MariaDBをインストールする
bash
cd /usr/local/src
wget https://dlm.mariadb.com/3971300/MariaDB/mariadb-11.6.2/source/mariadb-11.6.2.tar.gz
wget https://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/mariadb-11.3.2/source/mariadb-11.3.2.tar.gz
tar xvzf mariadb-11.6.2.tar.gz
cd mariadb-11.6.2
#export OPENSSL_ROOT_DIR=/usr/local/ssl
#export OPENSSL_INCLUDE_DIR=/usr/local/ssl/include
#export OPENSSL_LIBRARIES=/usr/local/ssl/lib/
#export OPENSSL_ROOT_DIR=/usr/local/ssl
/usr/local/bin/cmake \
-DPLUGIN_TOKUDB=NO
##-DCMAKE_INSTALL_PREFIX=/usr/local/mysql9.1 #場所を指定する場合
#-OPENSSL_ROOT_DIR=/usr/local/ssl \
#-OPENSSL_INCLUDE_DIR=/usr/local/include \
#-OPENSSL_LIBRARIES=/usr/local/lib64 \
#-DDEFAULT_CHARSET=utf8 \
#-DDEFAULT_COLLATION=utf8_general_ci
make install -j 8
#
# もしくは、以下の方法でコンパイル
#
#BUILD/autorun.sh
#./configure --with-plugin-xtradb
#make
#make install
#オーナーを設定
chown mysql:mysql -R /usr/local/mysql/
#設定ファイルをコピーする
#cp support-files/my-medium.cnf /etc/my.cnf
#cp etc/my.cnf.d/server.cnf /etc/my.cnf
my.cnf
cat > /etc/my.cnf << EOF
# These groups are read by MariaDB server.
# Use it for options that only the server (but not clients) should see
#
# See the examples of server my.cnf files in /usr/share/mysql/
#
# this is read by the standalone daemon and embedded servers
[server]
# this is only for the mysqld standalone daemon
[mysqld]
datadir=/usr/local/mysql/data
lc_messages_dir = /usr/local/mysql/share
socket = /usr/local/mysql/run/mariadb/mysql.sock
bind-address = 0.0.0.0
innodb_compression_algorithm = none
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/usr/local/mysql/run/mariadb/mysql.pid
#
# * Galera-related settings
#
[galera]
# Mandatory settings
#wsrep_on=ON
#wsrep_provider=
#wsrep_cluster_address=
#binlog_format=row
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
#
# Allow server to accept connections on all interfaces.
#
#bind-address=0.0.0.0
#
# Optional setting
#wsrep_slave_threads=1
#innodb_flush_log_at_trx_commit=0
# this is only for embedded server
[embedded]
# This group is only read by MariaDB servers, not by MySQL.
# If you use the same .cnf file for MySQL and MariaDB,
# you can put MariaDB-only options here
[mariadb]
# This group is only read by MariaDB-10.4 servers.
# If you use the same .cnf file for MariaDB of different versions,
# use this group for options that older servers don't understand
[mariadb-10.4]
[client]
socket = /usr/local/mysql/run/mariadb/mysql.sock
EOF
初期DBファイルを作成
su mysql
cd /usr/local/mysql
#scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
#今後は、/mariadb_install_dbのスクリプト名になるらしい
scripts/mariadb-install-db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
exit
#ログの場所を作成
mkdir /var/log/mariadb
chown -R mysql:mysql /var/log/mariadb/
設定ファイルを用意する
起動スクリプト
mariadb.service
cat > /usr/lib/systemd/system/mariadb.service << EOF
[Unit]
Description=MariaDB 10.8.3 database server
Documentation=man:mysqld(8)
Documentation=https://mariadb.com/kb/en/library/systemd/
After=network.target
[Service]
User=mysql
Group=mysql
Restart=always
Type=simple
ExecStart=/usr/local/mysql/bin/mysqld
ExecStop=/bin/kill \${MAINPID}
PIDFile=/usr/local/mysql/run/mariadb/mysql.pid
[Install]
WantedBy=multi-user.target
EOF
設定ファイルの追加
・Can't find messagefile '/usr/share/errmsg.sys'と言われた時の対応
・/tmpのCentOS7からの動作挙動影響によるPIDファイルのパス変更
プロセス配置用のディレクトリも用意する
mkdir -p /usr/local/mysql/run/mariadb
chown mysql:mysql /usr/local/mysql/run/mariadb
初期パスワード設定
su mysql
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
/usr/local/mysql/bin/mysql -u root
use mysql;
select * from user;
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
create user admin@'%' identified by 'password';
grant all on *.* to admin@'%';
exit
##一度Mariadbを停止する
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
#パスワードを聞かれたら先ほど設定したパスワードを入力し、Enterキーを押す
サービスの設定
サービスの起動と自動起動登録
systemctl enable mariadb
systemctl start mariadb
起動後のユーザー設定
su mysql
./mysql -u mysql
alter user 'root'@'localhost' identified BY 'パスワード';
exit
inclundeファイルについて
PHP7.1.xをmysqliモジュールをコンパイルする際に、「my_list.h」が存在しないとエラーになることがあります。これは、インストール後のいくつかのヘッダーファイルが入っていないからです。
これに対応するため、以下の対策を入れておきます。
bash:includeファイルコピー
mv /usr/local/mysql/include /usr/local/mysql/include.def
mkdir -p /usr/local/mysql/include/mysql
chown -R mysql:mysql /usr/local/mysql/include
cd /usr/local/src/mariadb-10.5.10/include
cp -rf ./* /usr/local/mysql/include/mysql