LoginSignup
1
1

More than 5 years have passed since last update.

Raspbian Jessi Lite にMaria DB 10.1.22をソースビルドインストール

Last updated at Posted at 2017-01-22

過去記事:CentOS 6.3 に MariaDB をインストール

概要

Raspberry Pi Model 3 を自宅サーバ化すべくMariaDBをインストールします。
OSが変わってもやることは同じですので、
基本的には以前に自分が書いた記事の焼き直しです。

※実際にやりながら書いており、グダグダな状況になってます。
 いつか整理して書き直します。

環境

主に下記の様な環境で行なっていきます。

ソフト  バージョン
OS Raspbian Jessi Lite
DB MariaDB 10.1.22
CMake 3.7.2
porg 0.10

インストールの方針

  • MariaDB用のアカウント(mariadb:MariaDB)を作成する。
  • インストール先は/opt/mariaDB配下とする。
  • データベースの出力先も/opt/mariaDB/data 配下とする。
  • porgにてインストール時に配置したソフトを管理する。

準備

CMakeインストール

インストールにはCMakeが必要になる。
こちら(自分の過去記事)を参考にインストールしてください。

システムアカウントの作成

システムアカウントの作成
$ sudo bash
$ groupadd -r MariaDB
$ useradd -r -g MariaDB -d /opt/mariaDB -s /usr/sbin/nologin mariadb
$ mkdir /opt/mariaDB
$ chown mariadb:MariaDB /opt/mariaDB
$ exit

インストール

まずソースをGitHubからダウンロードします。
GithubのURIと作成しているディレクトリのバージョン番号が違いますが、これについては最後に記述します。1
その後、cmakeを行います。

ソースのコンパイル準備
$ git clone https://github.com/MariaDB/server.git /home/pi/MariaDB-10.1
$ cd MariaDB-10.1
$ cmake .

エラーが出てしまいました。

-- Running cmake version 3.7.2
-- The C compiler identification is GNU 4.9.2
-- The CXX compiler identification is GNU 4.9.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
:
:
-- Packaging as: mariadb-10.1.22-Linux-armv7l
-- Performing Test HAVE_VISIBILITY_HIDDEN
:
:
-- Could NOT find Curses (missing:  CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:85 (MESSAGE):
  Curses library not found.  Please install appropriate package,

      remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu, package name is libncurses5-dev, on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
  cmake/readline.cmake:196 (FIND_CURSES)
  CMakeLists.txt:338 (MYSQL_CHECK_READLINE)

-- Configuring incomplete, errors occurred!
See also "/home/pi/MariaDB-10.2/CMakeFiles/CMakeOutput.log".
See also "/home/pi/MariaDB-10.2/CMakeFiles/CMakeError.log".

Cursesライブラリが無かったそうでエラーを出した様です。
ライブラリを追加してから、ログに従って CMakeCache.txt を消してやり直します。

$ sudo apt-get install ncurses-dev
$ rm CMakeCache.txt
$ cmake .

次はbisonが無いと警告が出ました。

:
:
Warning: Bison executable not found in PATH
CMake Error at cmake/bison.cmake:78 (MESSAGE):
  Bison (GNU parser generator) is required to build MySQL.Please install
  bison.
Call Stack (most recent call first):
  sql/CMakeLists.txt:271 (RUN_BISON)

-- Configuring incomplete, errors occurred!

bsionパッケージをさらに追加します。

$ sudo apt-get install flex bison
$ rm CMakeCache.txt
$ cmake .

3度目の正直。出来ました!

:
:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pi/MariaDB-10.2

カスタマイズ

make、make installに進む前に出力先等のカスタマイズを行う。
(configure みたいに引数を渡すのではなく、後からカスタマイズする)

主なカスタマイズポイントは以下のとおり。

  • インストールディレクトリの変更
  • データベースのデータ格納先の変更
  • かっちょ悪いので mysql を MariaDB に書き換えた

もしここでエラーが出た場合、おそらくインストールしていないパッケージがあるのか疑ってみる。
(ncurses-devel とか libaio-devel とか・・・)

編集コマンド
vi CMakeCache.txt
CMakeCache.txt
...
//install prefix
//CMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql
CMAKE_INSTALL_PREFIX:PATH=/opt/mariaDB/10.1
...
//groonga default document root
//GRN_DEFAULT_DOCUMENT_ROOT:PATH=/usr/local/mysql/share/groonga/html/admin
GRN_DEFAULT_DOCUMENT_ROOT:PATH=/opt/mariaDB/share/groonga/html/admin
...
//Value Computed by CMake
//CMAKE_PROJECT_NAME:STATIC=MySQL
CMAKE_PROJECT_NAME:STATIC=MariaDB
...
//UNIX_ADDR installation directory
//INSTALL_UNIX_ADDRDIR:STRING=/tmp/mysql.sock
INSTALL_UNIX_ADDRDIR:STRING=/tmp/mariadb.sock
...
//INCLUDE installation directory
//INSTALL_INCLUDEDIR:STRING=include/mysql
INSTALL_INCLUDEDIR:STRING=include/mariadb
...
//MYSQLTEST installation directory
//INSTALL_MYSQLTESTDIR:STRING=mysql-test
INSTALL_MYSQLTESTDIR:STRING=mariadb-test
...
//default MySQL data directory
//MYSQL_DATADIR:PATH=/usr/local/mysql/data
MYSQL_DATADIR:PATH=/opt/mariaDB/data
...
//MySQL project name
//MYSQL_PROJECT_NAME:STRING=MySQL
MYSQL_PROJECT_NAME:STRING=MariaDB
...

コンパイル

※6時間くらいかかります。

makeコマンド
$ make VERBOSE=1 2>&1 | tee make_log.txt
...
[100%] Linking CXX executable my_safe_process
cd /home/pi/MariaDB-10.2/mysql-test/lib/My/SafeProcess && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/my_safe_process.dir/link.txt --verbose=1
/usr/bin/c++    -pie -fPIC -Wl,-z,relro,-z,now -fstack-protector --param=ssp-buffer-size=4 -DWITH_INNODB_DISALLOW_WRITES -fno-exceptions -fno-rtti -O2 -g -DNDEBUG -D_FORTIFY_SOURCE=2 -DDBUG_OFF   CMakeFiles/my_safe_process.dir/safe_process.cc.o  -o my_safe_process  -lpthread
make[2]: Leaving directory '/home/pi/MariaDB-10.2'
[100%] Built target my_safe_process
make[1]: Leaving directory '/home/pi/MariaDB-10.2'
/usr/local/bin/cmake -E cmake_progress_start /home/pi/MariaDB-10.2/CMakeFiles 0
$
$ grep error make_log.txt
...
troff: fatal error: can't find macro file m
troff: fatal error: can't find macro file m
...
$ grep warn make_log.txt
/home/pi/MariaDB-10.2/sql/sql_yacc.yy:1025.1-12: warning: deprecated directive, use ‘%pure-parser’ [-Wdeprecated]
/home/pi/MariaDB-10.2/storage/connect/ha_connect.cc:5176:20: warning: variable ‘spc’ set but not used [-Wunused-but-set-variable]
/home/pi/MariaDB-10.2/storage/connect/ha_connect.cc:5176:30: warning: variable ‘qch’ set but not used [-Wunused-but-set-variable]
...
/home/pi/MariaDB-10.2/storage/mroonga/vendor/groonga/include/groonga/groonga.h:1532:34: warning: cast increases required alignment of target type [-Wcast-align]
/home/pi/MariaDB-10.2/storage/mroonga/vendor/groonga/plugins/suggest/suggest.c:864:8: warning: cast increases required alignment of target type [-Wcast-align]
/home/pi/MariaDB-10.2/storage/mroonga/vendor/groonga/plugins/suggest/suggest.c:865:8: warning: cast increases required alignment of target type [-Wcast-align]
/home/pi/MariaDB-10.2/storage/mroonga/vendor/groonga/include/groonga/groonga.h:1533:33: warning: cast increases required alignment of target type [-Wcast-align]
/home/pi/MariaDB-10.2/storage/mroonga/vendor/groonga/include/groonga/groonga.h:1537:34: warning: cast increases required alignment of target type [-Wcast-align]
/home/pi/MariaDB-10.2/storage/mroonga/vendor/groonga/include/groonga/groonga.h:1537:34: warning: cast increases required alignment of target type [-Wcast-align]

(補足 VERBOSE=1 が無い場合、makeコマンドの表示がなくなる。)

一応エラー、警告を確認してみたところ、少しありました。
とりあえず異常終了しないので、そのまま見なかったことにします(ー_ー)

インストール

インストール
sudo porg -lD make install

動作確認

動作確認
$ /opt/mariaDB/10.1/bin/mysql --version
/opt/mariaDB/10.1/bin/mysql  Ver 15.1 Distrib 10.1.22-MariaDB, for Linux (armv7l) using readline 5.1

起動準備

データディレクトリの作成

$ mkdir /var/lib/mysql
$ chown -R chown mariadb:MariaDB /var/lib/mysql

ログディレクトリの作成

$ mkdir /var/log/mysql
$ chwon -R mariadb:MariaDB /var/log/mysql

ソケット、PIDディレクトリの作成

$ mkdir /var/rum/mysqld
$ chwon -R mariadb:MariaDB /var/rum/mysqld

設定ファイルのコピー

$ cd /opt/mariaDB/10.1/suport-files
$ sudo cp ./my-small.cnf /etc/my.cnf
$ vi /etc/my.cnf
# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3306
socket          = /tmp/mariadb.sock
default-character-set=utf8              #追記

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3306
socket          = /tmp/mariadb.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 1M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 240K
default-character-set=utf8              #追記

MariaDBのデータベース作成

$ cd /opt/mariaDB/10.1/scripts/
$ ./scripts/mysql_install_db --user=mariadb --basedir=/opt/mariaDB/10.2 --datadir=/var/lib/mysql
2017-02-08 16:28:21 1522054224 [Note] InnoDB: Dumping buffer pool(s) not yet started
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:

'/opt/mariaDB/10.2/bin/mysqladmin' -u root password 'new-password'
'/opt/mariaDB/10.2/bin/mysqladmin' -u root -h raspberrypi password 'new-password'

Alternatively you can run:
'/opt/mariaDB/10.2/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 '/opt/mariaDB/10.2' ; /opt/mariaDB/10.2/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/opt/mariaDB/10.2/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

後少しです。ログに出てきた手順に従います。

サービス起動

$ cd '/opt/mariaDB/10.2' ; sudo /opt/mariaDB/10.2/bin/mysqld_safe --datadir='/var/lib/mysql'
170210 14:46:45 mysqld_safe Logging to '/var/lib/mysql/raspberrypi.err'.
170210 14:46:45 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
/opt/mariaDB/10.2/bin/mysqld_safe_helper: Can't change to run as user 'mysql'.  Please check that the user exists!

サービスを起動しようとしたら、エラーが出てしまいました。
どうやらmysqlユーザが必要な様ですorz
mariadbユーザをmysqlユーザに変更します。

$ sudo usermod -l mysql mariadb

変更が確認できたらサービス起動に挑戦

$ cd '/opt/mariaDB/10.2' ; sudo /opt/mariaDB/10.2/bin/mysqld_safe --datadir='/var/lib/mysql' 
170210 15:46:02 mysqld_safe Logging to '/var/lib/mysql/raspberrypi.err'.
170210 15:46:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

うまくいきました。

パスワード設定

$ /opt/mariaDB/10.2/bin/mysqladmin -u root password 'new-password'

初期DB、ゲストログインの削除

セキュリティーを高める目的で、推奨のセキュア導入コマンドを実施する。
項目
・パスワードの変更
・rootでのリモートログインの禁止
・初期DBの削除

$ sudo '/opt/mariaDB/10.2/bin/mysql_secure_installation'
:
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):
:
Change the root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

Remove anonymous users? [Y/n]Y
Disallow root login remotely? [Y/n]Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y

最後に

以下はサイトはmariaDBを構築する際大変お世話になりました。
MariaDB はじめてのMariaDB 【第2回 CentOSにインストールしてみよう (前編)】
MariaDB はじめてのMariaDB 【第3回 CentOSにインストールしてみよう (後編)】
はじめてのMARIADB 【第4回 ユーザを作成してみよう



  1. ※実はところどころmariaDBの格納先のディレクトリが10.2となっております。これは私がgithubのURIを見て、ディレクトリを作った結果、実バージョンと異なるディレクトリで作業を進めてしまったログです m(_ _)m 10.1に読み替えてください。 

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1