Aerospike数据库配置

来源:互联网 发布:微信抢号软件 编辑:程序博客网 时间:2024/05/18 03:46

Aerospike数据库配置

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

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

结构如下:

service {}               # Tuning parameters and process ownernetwork {                # 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 clusteringxdr {                    # (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}

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#  }}
  • 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}

存储方式

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.    }}

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.    }}

纯内存数据储存方案

如果你的数据不需要持久化,只需要配置储存引擎: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.}

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.    }}

数据有效期

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    ...}
  • 设置某个set不被清洗
namespace <namespace-name> {    ...    set <set-name> {        set-disable-eviction true     # Protect this set from evictions.    }}
  • 设置某个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.    }}

设置备份数量

namespace <namespace-name> {    ...    replication-factor 2    ...}

多个namespace

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

0 0
原创粉丝点击