MariaDB ColumnStore をDockerでカジュアルに使い始めよう!
MariaDB ColumnStore(MCS)については、弊社ブログでも記事が増えてきました。
https://blog.s-style.co.jp/2017/07/621/
https://blog.s-style.co.jp/2017/11/1248/
https://blog.s-style.co.jp/2018/12/2972/
https://blog.s-style.co.jp/2018/12/3006/
今回は、MariaDB ColumnStoreをDockerで簡単に構築してしまう方法をご紹介します。
ドキュメント
MCSとDockerの組み合わせによる構築方法については、以下のマニュアルで紹介されています。
本手順は、事前にDocker、docker-composeがインストールされ、正常に動作することを前提としています。
https://www.docker.com/get-started
早速構築
MCSのDockerHub上のリポジトリは以下となります。
https://hub.docker.com/r/mariadb/ColumnStore
シングルノードのMCSの構築は、以下のコマンドを実行するのみです。
| 1 2 3 4 5 6 7 8 | $ docker run -d --name mcs mariadb/ColumnStore Unable to find image 'mariadb/ColumnStore:latest' locally latest: Pulling from mariadb/ColumnStore 256b176beaff: Pull complete   : $ docker ps CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS               NAMES 85fbb4ef572e        mariadb/ColumnStore   "docker-entrypoint.s…"   25 seconds ago      Up 23 seconds       3306/tcp            mcs | 
非常に簡単ですね!
ちゃんと利用できるか確認してみましょう。
| 1 2 3 4 5 6 7 8 | $ docker exec -it mcs /usr/local/mariadb/ColumnStore/mysql/bin/mysql Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.2.17-MariaDB-log ColumnStore 1.1.6-1 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. | 
接続することができました。
次にmcsadminツールで状態を確認してみます。
MCSでは、管理操作にmcsadminツールを使用します。
| 1 2 3 4 5 6 7 8 9 10 11 12 | $ docker exec -it mcs /usr/local/mariadb/ColumnStore/bin/mcsadmin getSystemStatus getsystemstatus   Mon Oct 15 00:54:05 2018 System ColumnStore-1 System and Module statuses Component     Status                       Last Status Change ------------  --------------------------   ------------------------ System        ACTIVE                       Mon Oct 15 00:54:05 2018 Module pm1    ACTIVE                       Mon Oct 15 00:53:57 2018 | 
Performance Moduleが1つのみ起動した状態であることが確認できました。
ただし、シングルノード構成では、一見Performance Moduleのみ起動している状態に見えても、
本来User Moduleで起動するプロセスもすべて集約されているので、通常通り処理を行えます。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $ docker exec -it mcs /usr/local/mariadb/ColumnStore/bin/mcsadmin getProcessStatus getprocessstatus   Mon Oct 15 00:54:14 2018 MariaDB ColumnStore Process statuses Process             Module    Status            Last Status Change        Process ID ------------------  ------    ---------------   ------------------------  ---------- ProcessMonitor      pm1       ACTIVE            Mon Oct 15 00:53:23 2018         577 ProcessManager      pm1       ACTIVE            Mon Oct 15 00:53:29 2018         756 DBRMControllerNode  pm1       ACTIVE            Mon Oct 15 00:53:36 2018        1135 ServerMonitor       pm1       ACTIVE            Mon Oct 15 00:53:36 2018        1163 DBRMWorkerNode      pm1       ACTIVE            Mon Oct 15 00:53:39 2018        1178 DecomSvr            pm1       ACTIVE            Mon Oct 15 00:53:40 2018        1233 PrimProc            pm1       ACTIVE            Mon Oct 15 00:53:44 2018        1275 ExeMgr              pm1       ACTIVE            Mon Oct 15 00:53:48 2018        1341 WriteEngineServer   pm1       ACTIVE            Mon Oct 15 00:53:52 2018        1419 DDLProc             pm1       ACTIVE            Mon Oct 15 00:53:56 2018        1474 DMLProc             pm1       ACTIVE            Mon Oct 15 00:54:04 2018        1539 mysqld              pm1       ACTIVE            Mon Oct 15 00:53:35 2018        1071 | 
Dockerfile
MariaDB社のgithubリポジトリにdocker用の設定ファイルがありこれらを使って環境を構築することも可能です。
| 1 | $ git clone https://github.com/mariadb-corporation/mariadb-ColumnStore-docker.git | 
リポジトリには基本構成の他にjupyter_notebook、Apache zepperinを同時に起動するための設定、サンドボックス(初期データがロードされる)構成があります。
今回はマルチノード構成を試してみました。
| 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 | $ tree . ├── LICENSE ├── Readme.md ├── ColumnStore │   ├── Dockerfile │   ├── Readme.MD │   ├── dbinit │   ├── docker-compose.yml │   ├── docker-entrypoint.sh │   ├── init.d-rsyslog │   ├── mariadb-ColumnStore.repo │   ├── multi_node_um1 │   │   └── add_gateway_repl_user.sql │   ├── runit.repo │   ├── runit_bootstrap │   ├── service │   │   ├── ColumnStore │   │   │   ├── finish │   │   │   └── run │   │   ├── rsyslogd │   │   │   ├── finish │   │   │   └── run │   │   └── systemd-journald │   │       └── run │   └── wait_for_ColumnStore_active  : | 
ColumnStore
基本となるMCSのDockerですが、docker-composeによるマルチノード構成が可能となっています。
また、起動時に以下の環境変数が使用可能です。
- CS_POSTCFG_INPUT
postConfigureの入力パラメータを変更することが可能です。
実際にpostConfigureを実行する部分は以下の様になっています。
| 1 2 3 4 5 6 7 8 |     # first time install with CS_POSTCFG_INPUT set then run postConfigure     # with this as input. Must stop ColumnStore service first as postConfigure     # will fail otherwise. The service is only used for restarted pm1 containers     # or non pm1 containers in a cluster.     if [ ! -z "$CS_POSTCFG_INPUT" ]; then         echo "Stopping ColumnStore service to run postConfigure"         /usr/sbin/sv stop ColumnStore         echo -e "$CS_POSTCFG_INPUT" | $MCSDIR/bin/postConfigure -n | 
単純に環境変数をechoして渡しているだけなので、CS_POSTCFG_INPUTの設定値は
| 1 | \n\n1\n\n\n\num1\n192.168.1.2.. | 
と選択肢の分の改行と入力値を設定することになります。
- CS_DATABASE
起動時に作成するデータベースを設定します。
また、上記の他に docker-entrypoint-initdb.d以下に.sh、.sql、.sql.gzのファイルを配置しておくことで柔軟に初期データをロード可能です。
マルチノード構成の起動
早速マルチノード構成で起動してみましょう。
テストのために、環境変数の設定と、確認用のスクリプトを置いておきます。
最初にmydbというデータベースを作成してみます。
docker-compose.yml
| 1 2 3 4 5 |   3   um1:   4     image: mariadb/ColumnStore:latest   5     environment:   6       - CS_POSTCFG_INPUT=   7       - CS_DATABASE=mydb | 
./multi_node_um1がdocker-entrypoint-initdb.dにマウントされますので、その配下にテストスクリプトを配置します。
| 1 2 3 4 | $ cat >> ./multi_node_um1/test.sql <<EOS create table mydb.test(i int) engine ColumnStore; insert into mydb.test values (1),(2),(3),(4),(5); EOS | 
docker-composeでマルチノードを起動してみましょう。
| 1 2 3 4 5 6 7 8 | $ docker-compose up -d $ docker-compose ps       Name                     Command               State            Ports          ------------------------------------------------------------------------------------ ColumnStore_pm1_1   docker-entrypoint.sh /usr/ ...   Up      3306/tcp                ColumnStore_pm2_1   docker-entrypoint.sh /usr/ ...   Up      3306/tcp                ColumnStore_um1_1   docker-entrypoint.sh /usr/ ...   Up      0.0.0.0:33306->3306/tcp ColumnStore_um2_1   docker-entrypoint.sh /usr/ ...   Up      0.0.0.0:33307->3306/tcp | 
接続して初期設定が行われているか確認します。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | $ docker-compose exec um1 bash [root@fd1da4684fd0 /]# mcsmysql MariaDB [(none)]> show databases like 'mydb'; +-----------------+ | Database (mydb) | +-----------------+ | mydb            | +-----------------+ MariaDB [(none)]> show tables from mydb; +----------------+ | Tables_in_mydb | +----------------+ | test           | +----------------+ MariaDB [(none)]> select * from mydb.test; +------+ | i    | +------+ |    1 | |    2 | |    3 | |    4 | |    5 | +------+ | 
状態を確認します。
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $ docker-compose exec pm1 /usr/local/mariadb/ColumnStore/bin/mcsadmin getsystems getsystemstatus   Mon Oct 15 02:49:55 2018 System ColumnStore-1 System and Module statuses Component     Status                       Last Status Change ------------  --------------------------   ------------------------ System        ACTIVE                       Mon Oct 15 02:21:34 2018 Module um1    ACTIVE                       Mon Oct 15 02:21:31 2018 Module um2    ACTIVE                       Mon Oct 15 02:21:26 2018 Module pm1    ACTIVE                       Mon Oct 15 02:21:07 2018 Module pm2    ACTIVE                       Mon Oct 15 02:21:21 2018 Active Parent OAM Performance Module is 'pm1' Primary Front-End MariaDB ColumnStore Module is 'um1' MariaDB ColumnStore Replication Feature is enabled | 
問題ないですね!
まとめ
とても簡単にマルチノード構成のMCS環境が手に入りました。
あくまで検証用途としての利用がメインになりますが、DWHをカジュアルに構築できるのは嬉しいですね。
ぜひ、導入を検討されているユーザ様は、カジュアルにMCSを構築してどんどん検証を行ってみてください!


 
		 
			 
			 
			 
			 
			 
			 
			 
			