Aerospike数据库配置

Aerospike数据库配置

AS数据库由一个单独的文件配置,位置在:/etc/aerospike/aerospike.conf,linux上直接编辑修改就可以,注意权限,如果用的vagrant虚拟机,就用如下命令修改:

vagrant ssh -c "sudo vi /etc/aerospike/aerospike.conf"
  • 1

结构如下:

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
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

service配置一些服务参数。network配置网络参数,namespace配置数据库参数,后两者的配置较为复杂,接下来简单介绍一下。

网络配置

network {
  service {
    address any                  # IP of the NIC on which the service is
                               # listening.
    port 3000                    # port on which the service is listening.
    access-address 192.168.1.100 # IP address exported to clients that access
                               # the service.
  }

  fabric {
    address any
    port 3001   # Intra-cluster communication port (migrates, replication, etc).
  }

  info {
    address any
    port 3003   # Plain text telnet management port.
  }

  heartbeat {
    mode multicast                  # Send heartbeats using Multicast
    address 239.1.99.2              # multicast address
    port 9918                       # multicast port
    interface-address 192.168.1.100 # IP of the NIC to use to send out heartbeat
                                    # and bind fabric ports
    interval 150                    # Number of milliseconds between heartbeats
    timeout 10                      # Number of heartbeat intervals to wait
                                    # before timing out a node
  }

#  heartbeat {
#    mode mesh                   # Send heartbeats using Mesh (Unicast) protocol
#    address 192.168.1.100       # IP of the NIC on which this node is listening
#                                # to heartbeat
#    port 3002                   # port on which this node is listening to
#                                # heartbeat
#    mesh-seed-address-port 192.168.1.101 3002 # IP address for seed node in the cluster
#    mesh-seed-address-port 192.168.1.102 3002 # IP address for seed node in the cluster
#    interval 150                # Number of milliseconds between heartbeats
#    timeout 20                  # Number of heartbeat intervals to wait before
#                                # timing out a node
#  }
}
  • 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
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • server 
    server服务端口:应用、工具、远程XDR通过此端口访问AS集群。

  • Fabric 
    Fabric端口:集群内部通讯、备份等操作用此端口。

  • info 
    Telnet端口,实现了管理员发布信息的命令文本协议端口。

  • Heartbeat 
    集群心跳端口,用来构建和维护集群。AS为我们提供了两种心跳模式:

    1. Multicast Heartbeat:基于UDP的模式
    2. Mesh (Unicast) Heartbeat 基于TCP的模式

    上述两种模式只能选其一,官方推荐使用Multicast Heartbeat模式。

namespace配置

一个namespace相当于一个数据库,最简单的配置(如下所示):必须有一个namespace名称,这将创建一个内存中的命名空间的名称与4GB容量。注释的参数表示默认值。

namespace <namespace-name> {
    # memory-size 4G           # 4GB of memory to be used for index and data
    # replication-factor 2     # For multiple nodes, keep 2 copies of the data
    # high-water-memory-pct 60 # Evict non-zero TTL data if capacity exceeds
                               # 60% of 4GB
    # stop-writes-pct 90       # Stop writes if capacity exceeds 90% of 4GB
    # default-ttl 0            # Writes from client that do not provide a TTL
                               # will default to 0 or never expire
    # storage-engine memory    # Store data in memory only
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

存储方式

namespace里的存储方式决定了这个namespace里的数据是存在内存里还是存在磁盘上还是两者混合存储。这也将影响AS的性能、成本和可持久性。

SSD存储方案

SSD存储方案必须配置SSD设备,每个设备最大支持2TB,如果有大于2TB的设备,那么把它进行分区,配置为多个设备。同时,我们建议将write-block-size配置从默认的1M减少到128K。

namespace <namespace-name> {
    memory-size <SIZE>G         # Maximum memory allocation for primary
                                # and secondary indexes.
    storage-engine device {     # Configure the storage-engine to use persistence
        device /dev/<device>    # raw device. Maximum size is 2 TiB
        # device /dev/<device>  # (optional) another raw device.
        write-block-size 128K   # adjust block size to make it efficient for SSDs.
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
HDD及内存混合存储方案

HDD及内存混合存储方案必须配置数据存储的文件路径、每个文件大小(通常是内存大小的4倍,最大为2TB)。同时设置data-in-memory设置为true,开启内存存储机制。

namespace <namespace-name> {
    memory-size <SIZE>G             # Maximum memory allocation for data and
                                    # primary and secondary indexes.
    storage-engine device {         # Configure the storage-engine to use
                                    # persistence. Maximum size is 2 TiB
    file /opt/aerospike/<filename>  # Location of data file on server.
    # file /opt/aerospike/<another> # (optional) Location of data file on server.
    filesize <SIZE>G                # Max size of each file in GiB.
    data-in-memory true             # Indicates that all data should also be
                                    # in memory.
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
纯内存数据储存方案

如果你的数据不需要持久化,只需要配置储存引擎:storage-engine memory,再设置一下内存大小就可以了。

namespace <namespace-name> {
    memory-size <SIZE>G   # Maximum memory allocation for data and primary and
                          # secondary indexes.
    storage-engine memory # Configure the storage-engine to not use persistence.
}
  • 1
  • 2
  • 3
  • 4
  • 5
HDD及索引储存方案

这类储存方案比较特殊,适用于你的数据库只有单个bin,你希望有内存储存的性能同时不失去企业版提供的快速重启恢复数据的能力,用这个方案:

namespace <namespace-name> {
    memory-size <N>G                # Maximum memory allocation for data and
                                    # primary and secondary indexes.
    single-bin true                 # Required true by data-in-index.
    data-in-index true              # Enables in index integer store.
    storage-engine device {         # Configure the storage-engine to use
                                    # persistence.
    file /opt/aerospike/<filename>  # Location of data file on server.
    # file /opt/aerospike/<another> # (optimal) Location of data file on server.
    # device /dev/<device>          # Optional alternative to using files.

    filesize <SIZE>G               # Max size of each file in GiB. Maximum size is 2TiB
    data-in-memory true            # Required true by data-in-index.
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

数据有效期

namespace可以配置数据的有效时长,过时的数据自动清理。

  • default-ttl 数据保留的时长,单位秒

  • high-water-disk-pct 持久化数据达到总容量的百分比后开始清理数据

  • high-water-memory-pct 内存数据达到总容量的百分比后开始清理数据

  • stop-writes-pct 数据达到总容量的百分比后停止写入数据

namespace <namespace-name> {
    default-ttl <VALUE>             # How long (in seconds) to keep data after it is written
    high-water-disk-pct <PERCENT>   # How full may the disk become before the server begins eviction (expiring records early)
    high-water-memory-pct <PERCENT> # How full may the memory become before the server begins eviction (expiring records early)
    stop-writes-pct <PERCENT>       # How full may the memory become before we disallow new writes
    ...
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 设置某个set不被清洗
namespace <namespace-name> {
    ...
    set <set-name> {
        set-disable-eviction true     # Protect this set from evictions.

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 设置某个set最多容纳的记录数(record)
namespace <namespace-name> {
    ...
    set <set-name> {
        set-stop-writes-count 5000     # Limit number of records that can be written to this set to 5000.

    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

设置备份数量

namespace <namespace-name> {
    ...
    replication-factor 2
    ...
}
  • 1
  • 2
  • 3
  • 4
  • 5

多个namespace

当你需要多个数据库时,可以同时配置多个namespace,但是要注意,一个AS集群最多只能容纳32个namespace。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Aerospike和ClickHouse都是键值对内存数据库,但是它们的使用场景和特点有所不同。 Aerospike是一种高性能、可扩展的键值对内存数据库,适用于需要快速读写大量数据的场景,例如广告技术、实时分析和个性化推荐等。Aerospike支持多种数据类型,包括字符串、整数、浮点数、列表、映射和二进制数据等。Aerospike还支持多种读写操作,例如单个键值对读写、批量读写、范围查询和二次索引查询等。Aerospike的优点是高性能、可扩展、易于使用和部署,缺点是不支持复杂查询和事务。 ClickHouse是一种高性能、可扩展的列式存储数据库,适用于需要快速查询大量数据的场景,例如日志分析、数据仓库和实时报表等。ClickHouse的特点是支持高并发、高吞吐量的查询,支持复杂的SQL查询和聚合操作,支持多种数据格式和压缩算法,支持分布式部署和数据复制。ClickHouse的优点是高性能、可扩展、支持复杂查询和事务,缺点是不支持实时更新和删除操作。 以下是两个例子: 1.使用Aerospike存储和读取数据 ```python import aerospike # 连接Aerospike数据库 config = { 'hosts': [ ('127.0.0.1', 3000) ] } client = aerospike.client(config).connect() # 写入数据 key = ('test', 'demo', 'key1') bins = { 'name': 'Alice', 'age': 25, 'gender': 'female' } client.put(key, bins) # 读取数据 (key, metadata, record) = client.get(key) print(record) # 关闭连接 client.close() ``` 2.使用ClickHouse查询数据 ```sql -- 创建表 CREATE TABLE test ( id UInt32, name String, age UInt8, gender String ) ENGINE = MergeTree() ORDER BY id; -- 插入数据 INSERT INTO test VALUES (1, 'Alice', 25, 'female'), (2, 'Bob', 30, 'male'); -- 查询数据 SELECT * FROM test WHERE age > 25; ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值