使用Docker镜像在本地环境构建Aerospike的开始指南

首先

因为工作需要,我需要学习一下如何使用Aerospike?
首先了解一下Aerospike是什么,
然后在本地环境中进行简单的功能验证。

Aerospike是什么?

总结

一种快速分布式KVS型NoSQL数据库。它被优化为SSD,因此具有高速和可扩展性功能,这是其卖点。

image.png

从Aerospike实际应用案例中

而且,与Memcache和Redis相比,Aerospike内置了集群功能,可以使用高性能的闪存存储(SSD)。根据基准测试,Aerospike单个服务器的速度与Redis和Memcache相媲美,但Aerospike还包括自动集群和透明的重分片功能。这意味着只需启动节点就可以增加容量。还提供了持续的碎片整理和数据擦除,以及像Memcache一样的检查与设置操作,以提供用户熟悉且需要的功能。

数据结构

image.png

根据RDB的替换,似乎可以得到以下的图像。

AerospikeRDBNamespaceDatabaseSetTableRecordRowBinColumn

暂时先在本地运行,所以只需掌握这些基础知识。

安装环境

ソフトウェアバージョンOSWindows10Docker Engine20.10.5

安装

1. DockerイメージDL

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

由于以下是类似于免费的Community Edition,请执行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镜像中有以下的Aerospike,就可以接受。

>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 ps上运行着aerospike,则表示正常。

>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

如果仅仅需要通过指定键来进行数据的注册、查询等操作的话,你可以使用名为ascli的命令行界面工具来进行简单的命令确认。但是,这个Docker镜像中没有包含它吗?作为替代,可以使用类似于SQL的Aerospike专有查询语言AQL(Aerospike Query Language)。在容器内使用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查询,可以按照以下方式。

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

暂时尝试插入、引用和删除。

插入

[句子]
插入到<命名空间>[.<集合>]中,構造一個SQL語句:INSERT INTO (主鍵, <欄位>) 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.

请参考

[语法]
从[.]选择,其中PK =

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

OK

删除

【句子】
从[.]表中删除WHERE PK = 的记录。

【翻译】
删除[.]表中主键为的记录。

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查询的感觉一样。

在上面的查询语句中,test是指命名空间,并且是默认安装时的命名空间。
可以通过以下的配置文件来确认、添加和修改各种设置。

/aerospike.conf的路径为/etc/aerospike/aerospike.conf。

顺带一提,你可以使用quit命令从aql提示符中退出。

暂时只到今天为止,因为还没有安装好。
下次想尝试从程序中访问Aerospike。

请参考

https://aerospike.com/jp/home/ – 该网址为Aerospike的官方首页。
https://docs.aerospike.com/docs/tools/aql/#starting-aql-and-running-commands – 此链接为Aerospike官方文档中有关AQL工具的使用指南。
https://blog.idcf.jp/entry/2016/08/10/122055 – 该文章介绍了高速键值存储系统Aerospike的特点和用户案例。
https://recruit.gmo.jp/engineer/jisedai/blog/introducing-high-speed-kvs-aerospike-features-and-user-cases/ – 这篇博文在GMO招聘网站上介绍了高速键值存储系统Aerospike的特点和用户案例。
https://tech-blog.fancs.com/entry/aerospike-introduction – 此篇技术博文详细介绍了Aerospike的概述和特点。
https://qiita.com/amotz/items/b8f52e9e09bce1ddea6b – 这篇文章在Qiita上介绍了Aerospike,并提供了使用案例。

广告
将在 10 秒后关闭
bannerAds