LoginSignup
1
0

More than 3 years have passed since last update.

Aerospikeことはじめ ~DockerイメージでAerospikeをローカル環境構築~

Last updated at Posted at 2021-05-02

はじめに

お仕事でAerospikeを使うことになったので勉強めも👊
まずはAerospikeとはなんぞやを知ることとと
ローカル環境で簡単に動作確認するところまで。

Aerospikeとは?

概要

高速な分散KVS型のNoSQLデータベース。
SSDに最適化されてるから早いのとスケーラビリティの機能があるよというようなことがウリらしい。

【引用】
Aerospike概要から
image.png

Aerospikeユースケースから

また、MemcacheやRedisと比較すると、Aerospikeにはクラスタリング機能が組み込まれており、高性能なフラッシュストレージ(SSD)を使用できます。ベンチマークによると、Aerospikeの単一サーバの速度はRedisやMemcacheの両方に匹敵することが示されていますが、Aerospikeには自動クラスタリングと透過的なリシャーディングの機能が含まれています。これにより、ノードを起動するだけで容量を追加できます。継続的なデフラグとデータ消去、Memcacheのようなチェック&セット操作により、使い慣れた、かつ、必要な機能が提供されます。

データ構造

公式ページ Data Modelより
image.png

RDBに置き換えると下記のようなイメージらしい

Aerospike RDB
Namespace Database
Set Table
Record Row
Bin Column

とりあえず今回はローカルで動かすだけなので
この程度の知識だけ押さえておく。

インストール環境

ソフトウェア バージョン
OS Windows10
Docker Engine 20.10.5

インストール

1. DockerイメージDL

今回はAerospike公式が配布しているDockerイメージをDLして構築する。
Aerospike公式DockerHub

以下が無料のCommunityEditionっぽいのでdocker pull

コマンド
docker pull aerospike:ce-5.5.0.9
実行結果
ce-5.5.0.9: Pulling from library/aerospike
62deabe7a6db: Pull complete
6b52c9d72afa: Pull complete
6d38b2c09d49: Pull complete
7bcce1b84cb4: Pull complete
Digest: sha256:a26a8b17bded550b130952bc012d435e52326de11fbe003f7e2dbc4d42006e9d
Status: Downloaded newer image for aerospike:ce-5.5.0.9
docker.io/library/aerospike:ce-5.5.0.9

docker imagesで以下のaerospikeがあればOK。

DockerイメージDL確認
>docker images
REPOSITORY               TAG          IMAGE ID       CREATED       SIZE
aerospike                ce-5.5.0.9   76214490c04c   2 weeks ago   195MB

2. Aerospike起動

以下のdocker runコマンドで起動。
EnterpriseEditionならFEATURE_KEY_FILEなるものが必要だが、CommunityEditionは不要。

起動コマンド
docker run -d -v DIR:/opt/aerospike/etc/ --name aerospike -p 3000:3000 -p 3001:3001 -p 3002:3002 aerospike:ce-5.5.0.9

docker psaerospikeが動いてたらOK。

起動確認
>docker ps
CONTAINER ID   IMAGE                  COMMAND                  CREATED          STATUS          PORTS                                        NAMES
8064986acda1   aerospike:ce-5.5.0.9   "/usr/bin/dumb-init …"   16 minutes ago   Up 16 minutes   0.0.0.0:3000-3002->3000-3002/tcp, 3003/tcp   aerospike

3. Aerospike動作確認

以下のコマンドでコンテナにログイン

ログインコマンド
docker exec -it aerospike /bin/bash

Keyを指定してデータの登録、参照などをするだけなら
ascliというCLIを使えばシンプルなコマンドで確認できるのだが、このDockerイメージに入ってなかった?ので
その代わりにSQLのようなAerospike独自のクエリ言語AQL(Aerospike Query Language)を使用する。
コンテナ内でaqlコマンドを叩けばaqlプロンプトモードになる。

aqlコマンド実行
# aql
Seed:         127.0.0.1
User:         None
Config File:  /etc/aerospike/astools.conf /root/.aerospike/astools.conf
Aerospike Query Client
Version 5.0.1
C Client Version 4.6.17
Copyright 2012-2020 Aerospike. All rights reserved.
aql>

AQLの各クエリ構文を知りたかったら、
aqlプロンプトモードでHELP 〇〇〇を叩けば説明文が出る。
例えば、INSERTクエリを知りたければ下記の通り。

HELP文実行
aql> HELP INSERT
  DML
      INSERT INTO <ns>[.<set>] (PK, <bins>) VALUES (<key>, <values>)
      DELETE FROM <ns>[.<set>] WHERE PK = <key>
      TRUNCATE <ns>[.<set>] [upto <LUT>]

          <ns> is the namespace for the record.
          <set> is the set name for the record.
          <key> is the record's primary key.
          <bins> is a comma-separated list of bin names.
          <values> is comma-separated list of bin values, which may include type cast expressions. Set to NULL (case insensitive & w/o quotes) to delete the bin.
          <LUT> is last update time upto which set or namespace needs to be truncated. LUT is either nanosecond since Unix epoch like 1513687224599000000 or in date string in format like "Dec 19 2017 12:40:00".

          ~省略~

こんな感じでメチャクチャ長い説明文が出てくる。
他のクエリのHELPコマンドは下記を参照。
https://docs.aerospike.com/docs/tools/aql#starting-aql-and-running-commands

とりあえず、挿入・参照・削除をしてみる。

挿入

[構文]
INSERT INTO <ns>[.<set>] (PK, <bins>) VALUES (<key>, <values>)

挿入例
aql> INSERT INTO test.NintenGames (PK, Name, Release) VALUES ('SMB', 'SuperMarioBros', 1983)
OK, 1 record affected.

aql> INSERT INTO test.NintenGames (PK, Name, Release) VALUES ('LOZ', 'LegendOfZelda', 1986)
OK, 1 record affected.

aql> INSERT INTO test.NintenGames (PK, Name, Release) VALUES ('PKM', 'Pockemon', 1998)
OK, 1 record affected.

参照

[構文]
SELECT <bins> FROM <ns>[.<set>] WHERE PK = <key>

参照例
aql> SELECT Name, Release FROM test.NintenGames WHERE PK = 'LOZ'
+-----------------+----------+
| Name            | Release  |
+-----------------+----------+
| "LegendOfZelda" | 1986     |
+-----------------+----------+
1 row in set (0.000 secs)

OK

削除

[構文]
DELETE FROM <ns>[.<set>] WHERE PK = <key>

削除例
aql> DELETE FROM test.NintenGames WHERE PK = 'PKM'
OK, 1 record affected.

aql> SELECT Name, Release FROM test.NintenGames
+------------------+----------+
| Name             | Release  |
+------------------+----------+
| "LegendOfZelda"  | 1986     |
| "SuperMarioBros" | 1983     |
+------------------+----------+
2 rows in set (0.094 secs)

OK

おぉ~できた!🤞
これだけならRBDにSQLクエリを投げてるのと同じ感覚。

上記クエリ文中のtestNamespaceで、インストール時のデフォルトのもの。
以下の設定ファイルで確認、および各種設定の追加・変更などができる。

/etc/aerospike/aerospike.conf

ちなみにquitコマンドでaqlプロンプトから抜けられる。

ひとまず今日はインストールまでなのでここまで。
次回はプログラムからAerospikeにアクセスしてみたいところ。

参考

https://aerospike.com/jp/home/
https://docs.aerospike.com/docs/tools/aql/#starting-aql-and-running-commands
https://blog.idcf.jp/entry/2016/08/10/122055
https://recruit.gmo.jp/engineer/jisedai/blog/introducing-high-speed-kvs-aerospike-features-and-user-cases/
https://tech-blog.fancs.com/entry/aerospike-introduction
https://qiita.com/amotz/items/b8f52e9e09bce1ddea6b

1
0
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
0