Metadata 服务
功能概述
AppCenter 的 Metadata Service 是在 Etcd 的基础之上进行二次开发,主要增加了 self 属性,即每个节点只能从该服务获取到自身相关的信息,如本机 IP、Server ID 等。此项目已在 github 上开源。
元数据结构
结构示例
每个应用集群在 Metadata Service 中存储的元信息结构如下。
-
/self
-
/hosts/[role name]/[instance_id]*
-
/ip [IP address]
-
/eip [public IP address]
-
/mac [MAC address]
-
/sid [server ID]
-
/gid [group ID]
-
/gsid [global server ID]
-
/node_id [node ID]
-
/instance_id [instance ID]
-
/cpu [cpu]
-
/gpu [gpu]
-
/memory [memory in MiB]
-
/volume_size [volume size in GiB]
-
/instance_class [instance class]
-
/gpu_class [gpu class]
-
/volume_class [volume class]
-
/physical_machine [ID of the physical machine that hosts the instance]
-
/role [role name]
-
/pub_key [pub key string]
-
/token [token string]
-
/reserved_ips
-
/[reserved IP name such as vip]*
-
/value [reserved ip address]
-
-
-
-
/host
-
/ip [IP address]
-
/eip [public IP address]
-
/mac [MAC address]
-
/sid [server ID]
-
/gid [group ID]
-
/gsid [global server ID]
-
/node_id [node ID]
-
/instance_id [instance ID]
-
/cpu [cpu]
-
/gpu [gpu]
-
/memory [memory in MiB]
-
/volume_size [volume size in GiB]
-
/instance_class [instance class]
-
/gpu_class [gpu class]
-
/volume_class [volume class]
-
/physical_machine [ID of the physical machine that hosts the instance]
-
/role [role name]
-
/pub_key [pub key string]
-
/token [token string]
-
/reserved_ips
-
/[reserved IP name such as vip]*
-
/value [reserved ip address]
-
-
-
-
/cluster
-
/app_id [application ID]
-
/cluster_id [cluster ID]
-
/user_id [application ID]
-
/global_uuid [global UUID]
-
/cluster_tag [cluster tag ID]
-
/vxnet [VxNet ID]
-
/zone [Zone ID]
-
/endpoints
-
/[service name]*
-
/port [port or a reference to env parameter]
-
/protocol [protocol]
-
-
/reserved_ips
-
/[reserved IP name such as vip]*
-
/value [reserved ip address]
-
-
-
-
/api_server
-
/host [host of api server]
-
/port [port of api server]
-
/protocol [protocol of api server]
-
-
/resource_limits
-
/valid_volume_classes [comma-separated valid volume classes]
-
/valid_instance_classes [comma-separated valid instance classes]
-
-
/upgrade-audit
-
/from_app_version [App version]
-
/to_app_version [App version]
-
-
-
/env/[parameter key]* [parameter value]
-
/adding-hosts/[role name]/[instance_id]*
-
/ip [IP address]
-
/eip [public IP address]
-
/mac [MAC address]
-
/sid [server ID]
-
/gid [group ID]
-
/gsid [global server ID]
-
/node_id [node ID]
-
/instance_id [instance ID]
-
/cpu [cpu]
-
/gpu [gpu]
-
/memory [memory in MiB]
-
/volume_size [volume size in GiB]
-
/instance_class [instance class]
-
/gpu_class [gpu class]
-
/volume_class [volume class]
-
/physical_machine [ID of the physical machine that hosts the instance]
-
/role [role name]
-
/pub_key [pub key string]
-
/token [token string]
-
/reserved_ips
-
/[reserved IP name such as vip]*
-
/value [reserved ip address]
-
-
-
-
/deleting-hosts/[role name]/[instance_id]*
-
/ip [IP address]
-
/eip [public IP address]
-
/mac [MAC address]
-
/sid [server ID]
-
/gid [group ID]
-
/gsid [global server ID]
-
/node_id [node ID]
-
/instance_id [instance ID]
-
/cpu [cpu]
-
/gpu [gpu]
-
/memory [memory in MiB]
-
/volume_size [volume size in GiB]
-
/instance_class [instance class]
-
/gpu_class [gpu class]
-
/volume_class [volume class]
-
/physical_machine [ID of the physical machine that hosts the instance]
-
/role [role name]
-
/pub_key [pub key string]
-
/token [token string]
-
/reserved_ips
-
/[reserved IP name such as vip]*
-
/value [reserved ip address]
-
-
-
-
/links/[service name]* [cluster_id]
-
/cmd
-
/id [cmd ID]
-
/cmd [cmd string]
-
/timeout [timeout(second)]
-
-
/vertical-scaling-roles [role names]
-
格式说明
-
/[cluster ID]与self平级目录,每个 Cluster ID 目录下内容结构与self相同,self通过软链接指向自己的 Cluster ID。 -
黑体字为固定 Key,括号内为变量,斜体字为可选项,黑色斜体字表示此项为可选项,但如果有此项则为固定 Key,右上角带
*表示该项有 Sibling (兄弟)节点。
返回信息
元数据结构中根节点 self 表示发送请求的那个节点,Metadata Server 接到请求后返回该节点的相关信息,具体信息如下。
| 参数 | 描述 |
|---|---|
hosts |
|
ip |
节点私有 IP 地址 |
eip |
节点绑定的公网 IP 地址,默认为空 |
mac |
节点 MAC 地址 |
sid |
节点 Server ID,云平台调度系统自动为每个节点分配的从 1 开始的整数。 |
gid |
|
gsid |
节点 Global Server ID,云平台调度系统自动为每个节点分配的全球唯一的 9 位随机整数 ID。 |
node_id |
节点 Node ID,云平台调度系统自动为每个节点分配的节点 ID,是一个以 |
instance_id |
|
cpu |
节点 CPU 核数。 |
memory |
节点内存大小,单位 MiB。 |
volume_size |
节点数据盘大小,单位 GiB。 |
gpu |
节点 GPU 显卡数。 |
instance_class |
节点类型,其中 |
gpu_class |
节点 GPU 显卡类型,其中 |
volume_class |
数据盘类型,其中 |
physical_machine |
节点所在物理机标识符。 |
role |
节点角色名称。 |
pub_key |
节点 Passphraseless SSH 公钥。 |
token |
节点通过开发者自定义脚本在该云服务器里运行结果,详情参见云应用开发模板规范 - 完整版。 |
reserved_ips |
节点预留 IP 地址. 这个目录下开发者可以定义多个 Reserved IP,比如 |
使用示例
例如,用户可通过 /self/hosts/i-abcd2xyz/ip 获取发起请求的节点所在集群中云服务器 ID 为 i-abcd2xyz 的 IP 地址;或通过 /self/hosts/master/i-abcd2xyz/ip 获取发起请求的节点所在集群中云服务器 ID 为 i-abcd2xyz 的 IP 地址,而此节点是一个 Master 节点。
| 说明 |
|---|
|
字段说明
元数据中,各字段说明可参考以下内容。
host
例如,用户可通过 /self/host/ip 获取自身节点的 IP 地址。
| 参数 | 描述 |
|---|---|
ip |
本节点私有 IP 地址 |
eip |
节点绑定的公网 IP 地址,默认为空。 |
mac |
本节点 MAC 地址 |
sid |
本节点 Server ID |
gid |
本节点 Group ID |
gsid |
本节点 Global Server ID |
node_id |
本节点 Node ID |
instance_id |
本节点云服务器 ID |
cpu |
本节点 CPU 核数 |
memory |
本节点内存大小 |
volume_size |
本节点数据盘大小。 |
gpu |
本节点节点 GPU 显卡数 |
instance_class |
本节点类型。 |
gpu_class |
本节点 GPU 显卡类型。 |
volume_class |
本节点数据盘类型。 |
physical_machine |
本节点所在物理机标识符 |
role |
本节点角色名称 |
pub_key |
本节点 Passphraseless SSH 公钥 |
token |
本节点通过开发者自定义脚本在本云服务器里运行结果 |
reserved_ips |
节点预留 IP 地址. 这个目录下开发者可以定义多个 Reserved IP,比如 |
cluster
Cluster 保存跟集群相关的元信息。
| 参数 | 描述 |
|---|---|
app_id |
集群所属的应用 ID |
cluster_id |
集群 ID,用户在创建应用的时候云平台调度系统自动生成的一个以 |
user_id |
用户 ID,创建该集群的用户,如 |
global_uuid |
集群全球唯一 ID,用户在进入部署应用页面时自动生成的全球唯一标识,这个 ID 可用于需要生成 Licence 的应用使用。 |
cluster_tag |
集群以及通过 API 创建的资源所绑定的 Tag ID。 |
vxnet |
集群所在网络 ID |
zone |
集群所在区域 ID |
endpoints |
|
api_server |
集群内部可通过内网访问的 API Server 信息,包括 |
resource_limits |
当前 Zone 下所支持的资源类型。
|
upgrade-audit |
升级操作时,临时保存升级版本信息。
|
env
env 保存用户可修改的应用参数,key 为参数名,value 为具体参数值。
例如,Redis 节点可通过 /env/maxclients 获取用户配置的 maxclients 数值来更新 redis.conf。对于参数类型是 accesskey 的参数,在其原来目录下,云平台调度系统会添加 /access_key_id 和 /secret_access_key 两个子目录,分别存储 API 密钥 ID 和私钥。
adding-hosts
adding-hosts 临时保存新加入的节点信息,当 Scale Out (添加节点)操作完成之后这个子目录下的信息会随之消失。云服务器信息参见 hosts。
deleting-hosts
deleting-hosts 临时保存即将删除的节点信息,当 Scale In (删除节点)操作完成之后这个子目录下的信息会随之消失。云服务器信息参见 hosts。
links
外部服务依赖定义,有些应用依赖于另外一个服务才能正常工作,如 Kafka 依赖于 ZooKeeper,因此此处需指定被依赖集群的 ID,Service Name 可在云应用开发模板规范 - 完整版中任意定义。
cmd
cmd 表示本节点需要执行的命令。开发者不需要用到这类信息,这是云平台调度系统转发并执行应用命令,如启动应用命令等。
| 说明 |
|---|
开发者只需要在模板中定义命令即可,详情参见云应用开发模板规范 - 完整版。 |
| 参数 | 描述 |
|---|---|
vertical-scaling-roles |
表示当前正在进行纵向扩容的角色节点名称。
|
测试
在创建好一个集群后,登录到任意一个节点,在文件 /etc/confd/confd.toml 里找到 nodes 这一行,这一行定义的是 Metadata Server 的 IP 地址,任取一个 IP,执行命令行 curl http://[IP]/self 或者 curl http://metadata/self 即可看到所有信息。
| 说明 |
|---|
|