安装和配置Aerospike
Install Aerospike
wget -O aerospike.tgz 'https://www.aerospike.com/download/server/latest/artifact/ubuntu12'
# for ubuntu 14.04, replace ubuntu12 with ubuntu14
# for ubuntu 16.04, replace ubuntu12 with ubuntu16
tar -xvf aerospike.tgz
cd aerospike-server-community-*-ubuntu12*
# for ubuntu 14.04, replace "ubuntu12" with ubuntu14
sudo ./asinstall # will install the .deb packages
sudo service aerospike start && \
sudo tail -f /var/log/aerospike/aerospike.log | grep cake
# Wait for it. "service ready: soon there will be cake!"
# For systemd based installations, check in the journald facility.
Config Aerospike
Aerospike使用一个单独的配置文件来配置数据库,位置默认在/etc/aersopike/aerospike.conf
service {} # Tuning parameters and process owner
network { # Used to configure intracluster and application-node
# communications
service {} # Tools/Application communications protocol
fabric {} # Intracluster communications protocol
info {} # Administrator telnet console protocol
heartbeat {} # Cluster formation protocol
}
cluster {} # (Optional) Configure rack-aware clustering
xdr { # (Aerospike Enterprise only) Configure Cross
# Datacenter Replication
datacenter <name> {} # Remote datacenter node list
}
namespace <name> { # Define namespace record policies and storage engine
storage {} # Configure persistence or lack of persistence
set {} # (Optional) Set specific record policies
}
Aersopike的namespace需要在配置文件中进行配置,不能创建.
集群方式Config Aerospike
# Aerospike database configuration file for use with systemd.
service {
paxos-single-replica-limit 1 # Number of nodes where the replica count is automatically reduced to 1.
proto-fd-max 15000
}
logging {
file /opt/aerospike/log/aerospike.log {
context any info
}
}
network {
service {
address any
port 3000
}
heartbeat {
#mode multicast
#multicast-group 239.1.99.222
#port 9918
mode mesh
port 3002 # Heartbeat port for this node
# To use unicast-mesh heartbeats, remove the 3 lines above, and see
# aerospike_mesh.conf for alternative.
# add all cluster node address here
mesh-seed-address-port 10.*.*.* 3002
mesh-seed-address-port 10.*.*.* 3002
mesh-seed-address-port 10.*.*.* 3002
interval 150
timeout 10
}
fabric {
port 3001
}
info {
port 3003
}
}
namespace test {
replication-factor 1
memory-size 5G
default-ttl 0d # 30 days, use 0 to never expire/evict.
storage-engine memory
}
namespace bar {
replication-factor 2
memory-size 4G
default-ttl 30d # 30 days, use 0 to never expire/evict.
storage-engine memory
# To use file storage backing, comment out the line above and use the
# following lines instead.
# storage-engine device {
# file /opt/aerospike/data/bar.dat
# filesize 16G
# data-in-memory true # Store data in memory in addition to file.
# }
}
Network Configuration
Aerospike的数据库的网络配置有一些关键的端口,供其他节点或者工具使.
Name | Default Port | Description |
---|---|---|
Service | 3000 | Application, Tools, and Remote XDR use the Service port for database operations and cluster state. |
Fabric | 3001 | Intra-cluster communication port. Replica writes, migrations, and other node-to-node communications use the Fabric port. |
Mesh Heartbeat | 3002 | Heartbeat protocol ports are used to form and maintain the cluster. (Only one heartbeat port may be configured.) |
Multicast Heartbeat | 9918 | Heartbeat protocol ports are used to form and maintain the cluster. (Only one heartbeat port may be configured.) |
Info | 3003 | Telnet port that implements a plain text protocol for administrators to issue info commands. For more information, see asinfo documentation. |
Configuring Strong Consistency
通过处理配置namespace的强一致性,需要进行一下配置
- 确保NTP服务已经配置
- Make sure you have NTP configured
- 添加配置文件条目来表示强一直性namespace
- 配置初始的roster
- 配置节点的ID
sudo apt install ntp
vi /etc/ntp.conf
sudo systemctl reload ntp.service
sudo ntpq -p
添加节点ID,修改配置文件/etc/aerospike/aerospike.conf
,添加node-id
属性
service {
user root
group root
service-threads 4
transaction-queues 4
transaction-threads-per-queue 4
nsup-period 16
proto-fd-max 15000
node-id a1
}
在希望保持强一致性的节点上添加属性strong-consistency true
和属性default-ttl 0
namespace test {
replication-factor 2
memory-size 1G
default-ttl 0
strong-consistency true
storage-engine device {
file /var/lib/aerospike/test.dat
filesize 4G
data-in-memory true
}
}
配置日志
配置日志路径和级别
logging {
file /var/log/aerospike/aerospike.log {
context any info
}
}
查看存在的log路径
~$ asinfo -v logs
requested value logs
value is 0:/var/log/aerospike/aerospike.log
SQL语句操作
Aql 操作
查询结果以json输出
aql> set key_send true
aql> set output json
aql> set record_print_metadata true
.... Insert records ...
aql> select * from test.links
[
{
"PK": "key9",
"digest": "fLBhK40CvGA9J891weFg6dbysyE=",
"ttl": 2591983,
"gen": 1,
"bins": {
"id": 1,
"time": 1590,
"link_type": 0,
"visibility": 1,
"data": "abc81"
}
}
]
Truncate Set
deleting all the data in a namespace or a set TRUNCATE <ns>[.<set>] [upto <LUT>]
aql> show sets;
+------------------+--------+----------------+-----------+-------------------+-------------+-------------------+----------------+------------+
| disable-eviction | ns | set-enable-xdr | objects | stop-writes-count | set | memory_data_bytes | truncate_lut | tombstones |
+------------------+--------+----------------+-----------+-------------------+-------------+-------------------+----------------+------------+
| "false" | "ycsb" | "use-default" | "1000000" | "0" | "usertable" | "1172000000" | "265285359958" | "0" |
+------------------+--------+----------------+-----------+-------------------+-------------+-------------------+----------------+------------+
[127.0.0.1:3000] 1 row in set (0.001 secs)
OK
aql> TRUNCATE ycsb.usertable;
OK
aql> show sets;
+------------------+--------+----------------+---------+-------------------+-------------+-------------------+----------------+------------+
| disable-eviction | ns | set-enable-xdr | objects | stop-writes-count | set | memory_data_bytes | truncate_lut | tombstones |
+------------------+--------+----------------+---------+-------------------+-------------+-------------------+----------------+------------+
| "false" | "ycsb" | "use-default" | "0" | "0" | "usertable" | "0" | "265356458309" | "0" |
+------------------+--------+----------------+---------+-------------------+-------------+-------------------+----------------+------------+
[127.0.0.1:3000] 1 row in set (0.001 secs)
Install Aerospike AMC
- 下载AMC文件
- 安装
使用root用户
sudo tar -xvf aerospike-amc-<version>.tar.gz -C /
- 卸载
sudo /opt/amc/bin/uninstall
默认端口是8081
sudo /etc/init.d/amc start
sudo /etc/init.d/amc stop
sudo /etc/init.d/amc restart
操作命令
aql> TRUNCATE ycsb.usertable
OK
aql> show sets;