悪戦苦闘しながらCentOS8上でMySQL8.0をビルドして使えるようにする
実はそろそろ今の会社を辞めるので、絶賛自宅PC上で環境構築中です。
今回はMySQLの環境構築です。せっかくなのでソースコードからビルドしよーと軽い気持ちで始めたら思った以上に時間がかかってしまいました。
MySQLをソースコードからビルドするとき毎回調べながらやってしまうので、備忘録もかねて記事に書こうと思います。
途中エラー等多々発生したので戒めもかねて・・・
とりあえず結論が知りたいって人はまとめをご覧ください。
今回の目標はCentOS8上にMySQL8.0.19をソースからビルドしてログインできるところまで構築することです。
環境とか
Host : Windows 10(Home)
Guest : CentOS8
MySQL 8.0.19
なおCentOS8のインストールには
http://isoredirect.centos.org/centos/8/isos/x86_64/CentOS-8.1.1911-x86_64-dvd1.iso
から取得できるイメージを使い、サーバ(GUI)でインストールをしています。
ソースコードを取得する
https://dev.mysql.com/downloads/mysql/
まずはこちらからソースコードを取得します。
Select Operating System → [Source Code]を選択します。
Select OS Version → [Generic Linux]を選択します。
Includes Boost Headersと書いてある方法を選択します。
[No thanks, just start my download.]をクリックするとダウンロードが始まります。
今回はVM上に設置したCentOS8上でビルドを行いたいため、リンクアドレスをコピーしておきwgetでソースコードを取得します。
[root@centos8:/mysql/source/80]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.19.tar.gz --2020-04-15 23:31:36-- https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-boost-8.0.19.tar.gz dev.mysql.com (dev.mysql.com) をDNSに問いあわせています... 137.254.60.11 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 302 Found 場所: https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.19.tar.gz [続く] --2020-04-15 23:31:37-- https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-boost-8.0.19.tar.gz cdn.mysql.com (cdn.mysql.com) をDNSに問いあわせています... 42.125.202.44 cdn.mysql.com (cdn.mysql.com)|42.125.202.44|:443 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... 200 OK 長さ: 264147972 (252M) [application/x-tar-gz] `mysql-boost-8.0.19.tar.gz' に保存中 mysql-boost-8.0.19.tar.gz 100%[=========================================================================>] 251.91M 241KB/s 時間 6m 43s 2020-04-15 23:38:20 (640 KB/s) - `mysql-boost-8.0.19.tar.gz' へ保存完了 [264147972/264147972]
解凍しておきます。
[root@centos8:/mysql/source/80]# tar zxf mysql-boost-8.0.19.tar.gz [root@centos8:/mysql/source/80]# ll 合計 257964 drwxr-xr-x. 33 7161 31415 4096 12月 10 05:12 mysql-8.0.19 -rw-r--r--. 1 root root 264147972 12月 10 04:13 mysql-boost-8.0.19.tar.gz
準備
実際にビルドを行う前に、公式リファレンスからビルドに必要なツール等について確認しておきます。
MySQL :: MySQL 8.0 Reference Manual :: 2.9.2 Source Installation Prerequisites
- cmake
- make(3.75以降)
- gcc(5.3以降)
- ncursesライブラリ
- git
- bison(2.1以降)
- openssl(1.0.1以降)
あたりが必要とのことです。
追記
実際にビルドをしていくうちに下記についても必要であることがわかりました。
追記ここまで
必要なモジュールのインストール
CentOS8からyumの代わりにdnfをパッケージ管理システムとして利用します。
なぜdnfなのかというと、yumはPython2系で書かれているのですが、Python2系と3系では互換性がありません。 OSのデフォルトをPython3系にするとyumが利用できなくなるため、代替となるシステムが必要になったのです。 yumをPython3系で書くより新しいものを用意したほうがいいという判断なのでしょうね。
なおyumとdnfはどちらも、dnf-3を実行しているようです。
[root@centos8:/mysql/source/80]# ll /usr/bin/yum lrwxrwxrwx. 1 root root 5 11月 13 00:35 /usr/bin/yum -> dnf-3 [root@centos8:/mysql/source/80]# ll /usr/bin/dnf lrwxrwxrwx. 1 root root 5 11月 13 00:35 /usr/bin/dnf -> dnf-3
とりあえずupdateをしておきます。
[root@centos8:/mysql/source/80]# dnf update -y : : インストール済み: kernel-4.18.0-147.8.1.el8_1.x86_64 kernel-core-4.18.0-147.8.1.el8_1.x86_64 kernel-modules-4.18.0-147.8.1.el8_1.x86_64 conmon-2:2.0.6-1.module_el8.1.0+298+41f9343a.x86_64 grub2-tools-efi-1:2.02-78.el8_1.1.x86_64 完了しました!
必要なモジュールをインストールしていきます。
[root@centos8:/mysql/source/80]# dnf install -y cmake make ncurses-devel gcc git bison
opensslに関しては既にインストールされているようでした。
バージョンを確認したところ下記のようになりました。
[root@centos8:/mysql/source/80]# dnf list installed | grep ncurses ncurses.x86_64 6.1-7.20180224.el8 @anaconda ncurses-base.noarch 6.1-7.20180224.el8 @anaconda ncurses-c++-libs.x86_64 6.1-7.20180224.el8 @BaseOS ncurses-devel.x86_64 6.1-7.20180224.el8 @BaseOS ncurses-libs.x86_64 6.1-7.20180224.el8 @anaconda
git version 2.18.2
bison (GNU Bison) 3.0.4
ビルド
準備が整いましたのでビルドしていきます。
MySQLのインストールは下記の流れで行っていきます。
cmake → make → make install
cmake
cmake時に利用できるオプションは下記から確認できます。
https://dev.mysql.com/doc/refman/8.0/en/source-configuration-options.html
[root@centos8:/mysql/source/80/mysql-8.0.19]# cmake . -LH -- Running cmake version 3.11.4 -- MySQL 8.0.19 -- The CXX compiler identification is unknown CMake Error at CMakeLists.txt:322 (PROJECT): No CMAKE_CXX_COMPILER could be found. Tell CMake where to find the compiler by setting either the environment variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. :
今回は次のようにオプションを指定してcmakeします。
cmake . \ -DCMAKE_INSTALL_PREFIX=/mysql/mysql_home \ -DMYSQL_DATADIR=/mysql/mysql_home/data \ -DMYSQL_UNIX_ADDR=/mysql/mysql_home/tmp \ -DWITH_BOOST=./boost \ -DWITH_DEBUG=ON \ -DWITH_INNODB_EXTRA_DEBUG=ON
とりあえず-DWITH_BOOST
は指定する必要があると思います。
ネットワーク越しにBoostライブラリをダウンロードすることもできますが、最初からBoostライブラリが入っているtarボールをダウンロードしたほうが速いと思います。
(そのためソースファイルを選択するときにIncludes Boost Headersと書いてあるものを選びました)
[root@centos8:/mysql/source/80/mysql-8.0.19]# cmake . \ > -DCMAKE_INSTALL_PREFIX=/mysql/mysql_home \ > -DMYSQL_DATADIR=/mysql/mysql_home/data \ > -DMYSQL_UNIX_ADDR=/mysql/mysql_home/tmp \ > -DWITH_BOOST=./boost \ > -DWITH_DEBUG=ON \ > -DWITH_INNODB_EXTRA_DEBUG=ON -- Running cmake version 3.11.4 -- Found Git: /usr/bin/git (found version "2.18.2") -- MySQL 8.0.19 -- The C compiler identification is GNU 8.3.1 -- The CXX compiler identification is unknown -- Check for working C compiler: /usr/bin/cc -- Check for working C compiler: /usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done CMake Error at CMakeLists.txt:322 (PROJECT): No CMAKE_CXX_COMPILER could be found. Tell CMake where to find the compiler by setting either the environment variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler name if it is in the PATH. -- Configuring incomplete, errors occurred! See also "/mysql/source/80/mysql-8.0.19/CMakeFiles/CMakeOutput.log". See also "/mysql/source/80/mysql-8.0.19/CMakeFiles/CMakeError.log".
エラー。。。
g++
も入れなきゃいけませんでしたね・・・
[root@centos8:/mysql/source/80/mysql-8.0.19]# dnf install -y gcc-c++ [root@centos8:/mysql/source/80/mysql-8.0.19]# g++ --version g++ (GCC) 8.3.1 20190507 (Red Hat 8.3.1-4) Copyright (C) 2018 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.
満を持してー
[root@centos8:/mysql/source/80/mysql-8.0.19]# cmake . \ > -DCMAKE_INSTALL_PREFIX=/mysql/mysql_home \ > -DMYSQL_DATADIR=/mysql/mysql_home/data \ > -DMYSQL_UNIX_ADDR=/mysql/mysql_home/tmp \ > -DWITH_BOOST=./boost \ > -DWITH_DEBUG=ON \ > -DWITH_INNODB_EXTRA_DEBUG=ON -- Running cmake version 3.11.4 -- MySQL 8.0.19 -- Source directory /mysql/source/80/mysql-8.0.19 -- Binary directory /mysql/source/80/mysql-8.0.19 CMake Error at CMakeLists.txt:352 (MESSAGE): Please do not build in-source. Out-of source builds are highly recommended: you can have multiple builds for the same source, and there is an easy way to do cleanup, simply remove the build directory (note that 'make clean' or 'make distclean' does *not* work)
ソースコードの外でビルドしないといけないみたいです。
これでどうだー
[root@centos8:/mysql/source/80]# rm -f mysql-8.0.19/CMakeCache.txt [root@centos8:/mysql/source/80]# cmake /mysql/source/80/mysql-8.0.19 \ > -DCMAKE_INSTALL_PREFIX=/mysql/mysql_home \ > -DMYSQL_DATADIR=/mysql/mysql_home/data \ > -DMYSQL_UNIX_ADDR=/mysql/mysql_home/tmp \ > -DWITH_BOOST=/mysql/source/80/mysql-8.0.19/boost \ > -DWITH_DEBUG=ON \ > -DWITH_INNODB_EXTRA_DEBUG=ON : CMake Error at cmake/ssl.cmake:64 (MESSAGE): Please install the appropriate openssl developer package. :
オフッ...やっぱりopenssl-devel
のインストールが必要みたいです。
[root@centos8:/mysql/source/80]# dnf install -y openssl-devel [root@centos8:/mysql/source/80]# dnf list installed | grep openssl openssl.x86_64 1:1.1.1c-2.el8_1.1 @BaseOS openssl-devel.x86_64 1:1.1.1c-2.el8_1.1 @BaseOS openssl-libs.x86_64 1:1.1.1c-2.el8_1.1 @BaseOS openssl-pkcs11.x86_64 0.4.8-2.el8 @anaconda xmlsec1-openssl.x86_64 1.2.25-4.el8 @AppStream
再度cmake...
: CMake Error at cmake/rpc.cmake:65 (MESSAGE): Could not find rpc/rpc.h in /usr/include or /usr/include/tirpc
(´;ω;`)ウッ…ツライ
(このあたりでヤケになると同時にカレントディレクトリを間違えていることに気づく)
以下ダイジェスト・・・もといdieジェストです・・・
[root@centos8:/mysql/source/80]# dnf install -y libtirpc-devel [root@centos8:/mysql/source/80]# dnf list installed | grep libtirpc libtirpc.x86_64 1.1.4-4.el8 @anaconda libtirpc-devel.x86_64 1.1.4-4.el8 @BaseOS cmake : Could not find rpcgen :
rpcgenが無い
[root@centos8:/mysql/source/80/tmp_work]# dnf --enablerepo=PowerTools install -y rpcgen [root@centos8:/mysql/source/80/tmp_work]# dnf list installed | grep rpcgen rpcgen.x86_64 1.3.1-4.el8 @PowerTools
こちらを参考にさせていただきました。
How to install rpcgen for CentOS 8 - CentOS
[root@centos8:/mysql/source/80/tmp_work]# time cmake /mysql/source/80/mysql-8.0.19 \ > -DCMAKE_INSTALL_PREFIX=/mysql/mysql_home \ > -DMYSQL_DATADIR=/mysql/mysql_home/data \ > -DMYSQL_UNIX_ADDR=/mysql/mysql_home/tmp \ > -DWITH_BOOST=/mysql/source/80/mysql-8.0.19/boost \ > -DWITH_DEBUG=ON \ > -DWITH_INNODB_EXTRA_DEBUG=ON -- Running cmake version 3.11.4 : : -- CMAKE_SHARED_LINKER_FLAGS -- Configuring done -- Generating done -- Build files have been written to: /mysql/source/80/tmp_work real 0m48.639s user 0m34.505s sys 0m13.872s
ようやくcmakeできました・・・
make & make install
ここまでくれば後はmakeしてmake installすればビルドできます
といってっもmakeは比較的時間がかかりますので、気長に待ちましょう。
最後はmake install
です。
なお次のようにmake
とmake install
を続けて行っても問題ありません。
# make && make install
無事ビルドが完了しました!
[root@centos8:/mysql/mysql_home]# ll 合計 936 -rw-r--r--. 1 root root 405571 12月 10 04:53 LICENSE -rw-r--r--. 1 root root 405571 12月 10 04:53 LICENSE-test -rw-r--r--. 1 root root 102977 12月 10 04:53 LICENSE.router -rw-r--r--. 1 root root 687 12月 10 04:53 README -rw-r--r--. 1 root root 687 12月 10 04:53 README-test -rw-r--r--. 1 root root 700 12月 10 04:53 README.router drwxr-xr-x. 2 root root 4096 4月 17 14:08 bin drwxr-xr-x. 2 root root 86 4月 17 14:08 docs drwxr-xr-x. 3 root root 4096 4月 17 14:07 include drwxr-xr-x. 6 root root 4096 4月 17 14:08 lib drwxr-xr-x. 4 root root 30 4月 17 14:08 man drwxr-xr-x. 10 root root 4096 4月 17 14:08 mysql-test drwxrwxr-x. 2 root root 6 4月 17 14:08 run drwxr-xr-x. 28 root root 4096 4月 17 14:08 share drwxr-xr-x. 2 root root 77 4月 17 14:08 support-files drwxr-xr-x. 3 root root 17 4月 17 14:08 var
MySQLのセットアップ
mysqlユーザの作成
[root@centos8:/mysql/mysql_home]# groupadd mysql [root@centos8:/mysql/mysql_home]# useradd -r -g mysql -s /bin/false mysql [root@centos8:/mysql/mysql_home]# mkdir logs -- (オプション)log用のディレクトリを作成 [root@centos8:/mysql/mysql_home]# chown -R mysql:mysql .
mysqld --initializeでデータディレクトリの初期化
最低限のオプションを書いてmy.cnfを作っておきます。
[root@centos8:/mysql/mysql_home]# ll /etc/my.cnf -rw-r--r--. 1 mysql mysql 350 4月 17 16:11 /etc/my.cnf
個人的にlog-error
, log-error-verbosity = 3
, log-timestamps=SYSTEM
あたりは入れておくと良いかなと思います。
[root@centos8:/mysql/mysql_home]# bin/mysqld --initialize --user=mysql \ > --basedir=/mysql/mysql_home \ > --datadir=/mysql/mysql_home/data [root@centos8:/mysql/mysql_home]# ll data 合計 155704 drwxr-x---. 2 mysql mysql 6 4月 17 16:24 '#innodb_temp' -rw-r-----. 1 mysql mysql 56 4月 17 16:24 auto.cnf -rw-------. 1 mysql mysql 1680 4月 17 16:24 ca-key.pem -rw-r--r--. 1 mysql mysql 1112 4月 17 16:24 ca.pem -rw-r--r--. 1 mysql mysql 1112 4月 17 16:24 client-cert.pem -rw-------. 1 mysql mysql 1680 4月 17 16:24 client-key.pem -rw-r-----. 1 mysql mysql 5514 4月 17 16:24 ib_buffer_pool -rw-r-----. 1 mysql mysql 50331648 4月 17 16:24 ib_logfile0 -rw-r-----. 1 mysql mysql 50331648 4月 17 16:24 ib_logfile1 -rw-r-----. 1 mysql mysql 12582912 4月 17 16:24 ibdata1 drwxr-x---. 2 mysql mysql 143 4月 17 16:24 mysql -rw-r-----. 1 mysql mysql 25165824 4月 17 16:24 mysql.ibd drwxr-x---. 2 mysql mysql 8192 4月 17 16:24 performance_schema -rw-------. 1 mysql mysql 1676 4月 17 16:24 private_key.pem -rw-r--r--. 1 mysql mysql 452 4月 17 16:24 public_key.pem -rw-r--r--. 1 mysql mysql 1112 4月 17 16:24 server-cert.pem -rw-------. 1 mysql mysql 1676 4月 17 16:24 server-key.pem drwxr-x---. 2 mysql mysql 28 4月 17 16:24 sys -rw-r-----. 1 mysql mysql 10485760 4月 17 16:24 undo_001 -rw-r-----. 1 mysql mysql 10485760 4月 17 16:24 undo_002
この時点で$PREFIX/data
にデータディレクトリができます。(今回のケースではPREFIX=/mysql/mysql_home
)
またroot@localhost
用のパスワードはログファイルに書き込まれます。
なお、log-errorを指定しなかった場合は標準出力に出力されます。
[root@centos8:/mysql/mysql_home]# grep "temporary password" logs/mysqld.err 2020-04-17T16:24:22.794692+09:00 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 4Nx1jU%9(Qud
MySQLの起動
$PREFIX/support-files/mysql.server
を使ってmysqldを起動することができます。
[root@centos8:/mysql/mysql_home]# support-files/mysql.server start Starting MySQL..... SUCCESS! [root@centos8:/mysql/mysql_home]# ps -ef | grep mysq[l] root 23381 1 0 16:31 pts/0 00:00:00 /bin/sh /mysql/mysql_home/bin/mysqld_safe --datadir=/mysql/mysql_home/data --pid-file=/mysql/mysql_home/data/centos8.pid mysql 23571 23381 6 16:31 pts/0 00:00:07 /mysql/mysql_home/bin/mysqld --basedir=/mysql/mysql_home --datadir=/mysql/mysql_home/data --plugin-dir=mysql/mysql_home/lib/plugin --user=mysql --log-error=/mysql/mysql_home/logs/mysqld.err --pid-file=/mysql/mysql_home/data/centos8.pid
先ほどのroot@localhost
のパスワードを使ってログインができます。
[root@centos8:/mysql/mysql_home]# bin/mysql -uroot -p'4Nx1jU%9(Qud' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.19-debug Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
ただしこの状態ではコマンドを実行することができませんので、パスワードを変える必要があります。
mysql> show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
ALTERコマンドで変えてもいいのですが、ここではmysql_secure_installationを使います。
[root@centos8:/mysql/mysql_home]# bin/mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: -- 1 The existing password for the user account root has expired. Please set a new password. New password: -- 2 Re-enter new password: VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: n -- 3 Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : n -- 4 ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : y -- 5 Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y -- 6 Success. By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y -- 7 - 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? (Press y|Y for Yes, any other key for No) : y -- 8 Success. All done!
root@localhostのパスワードを入力
新しいパスワードを入力
パスワード検証コンポーネントをセットアップするか
rootのパスワードを変えるか
匿名ユーザを削除するか
ローカルホスト以外からのrootでのログインを禁止するか
testデータベースを削除するか
権限テーブルをリロードするか
5以降は基本的にYesを選択したほうがよいでしょう。
以上でMySQLにログインしコマンドを実行できるようになりました!
[root@centos8:/mysql/mysql_home]# bin/mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 14 Server version: 8.0.19-debug Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> select version(); +--------------+ | version() | +--------------+ | 8.0.19-debug | +--------------+ 1 row in set (0.00 sec)
プラスアルファの作業
パスを通す
いちいちパスを選択してログインするのも面倒なので、$PREFIX/binをPATHに通しておきます。
[root@centos8:/mysql/mysql_home]# cat ~/.bash_profile | grep PATH PATH=$PATH:$HOME/bin PATH=$PATH:/mysql/mysql_home/bin export PATH [root@centos8:/mysql/mysql_home]# source ~/.bash_profile [root@centos8:/mysql/mysql_home]# which mysql /mysql/mysql_home/bin/mysql
自動起動を有効にする
<注意> ここあたりは、すでにyumでmysqldをインストールした環境のmysqld.serviceを参考にしています。 僕自身よく分かっていないところがあります。
[root@centos8:~]# cat /etc/systemd/system/mysqld.service [Unit] Description=MySQL Server [Install] WantedBy=multi-user.target [Service] User=mysql Group=mysql Type=notify TimeoutSec=0 PermissionStartOn=true ExecStart=/mysql/mysql_home/bin/mysqld LimitNOFile = 10000 Restart=on-failure RestartPreventExitStatus=1 Environment=MYSQLD_PARENT_ID=1 PrivateTmp=false
systemctlでmysqldを起動させます。
[root@centos8:/etc/selinux]# systemctl start mysqld [root@centos8:/etc/selinux]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/etc/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-04-17 20:21:25 JST; 3s ago Main PID: 2939 (mysqld) Status: "Server is operational" Tasks: 42 (limit: 23978) Memory: 588.9M CGroup: /system.slice/mysqld.service └─2939 /mysql/mysql_home/bin/mysqld 4月 17 20:21:15 centos8 systemd[1]: Starting MySQL Server... 4月 17 20:21:25 centos8 systemd[1]: Started MySQL Server.
無事起動できたようです。
自動起動を有効にします。
[root@centos8:~]# systemctl enable mysqld Synchronizing state of mysqld.service with SysV service script with /usr/lib/systemd/systemd-sysv-install. Executing: /usr/lib/systemd/systemd-sysv-install enable mysqld
なお僕の環境では(おそらく)SELinuxが原因でsystemctlからmysqldを起動できませんでした。
[root@centos8:~]# sealert -l 8f5c3838-8847-492e-b7a4-9a334fe08593 SELinux により、/usr/lib/systemd/systemd による execute アクセスが、ファイル mysqld で拒否されました。
そのためSELinuxを無効にしてから再度mysqldの自動起動設定を試みています。
[root@centos8:/etc/selinux]# cd /etc/selinux [root@centos8:/etc/selinux]# cp config{,.bk} [root@centos8:/etc/selinux]# vim config [root@centos8:/etc/selinux]# diff config config.bk 7,8c7 < #SELINUX=enforcing < SELINUX=disable --- > SELINUX=enforcing
OSを再起動してみます。
[root@centos8:/etc/selinux]# shutdown -r now : [root@centos8:~]# [root@centos8:~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/etc/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2020-04-17 20:25:03 JST; 16s ago Main PID: 1116 (mysqld) Status: "Server is operational" Tasks: 42 (limit: 23978) Memory: 668.4M CGroup: /system.slice/mysqld.service └─1116 /mysql/mysql_home/bin/mysqld 4月 17 20:24:56 centos8 systemd[1]: Starting MySQL Server... 4月 17 20:25:03 centos8 systemd[1]: Started MySQL Server.
ちゃんと自動で起動してくれてますね!
まとめ
ここまでの流れをまとめます。
必要なモジュール等をインストールする
make, make install
mysql用のユーザを作成
mysqld --initializeでデータディレクトリを初期化(このときrootのパスワードが生成される)
mysql_secure_installationでセキュリティ向上を図る
感想とか
というわけで今回はCentOS8上でMySQL8.0.19をビルドしてログインできるまでにしました。
悪戦苦闘しましたが、なんとかビルドからインストールできてよかったです。 やっぱり自分で手を動かさないと覚えませんね。
お次はもう1つ仮想インスタンスを立ててPrometheusをインストールしてモニタリングできる環境でも構築してみましょうかね。
今回はこのあたりで。