目的
了解 etcd 连接
了解 etcd 增删改查方法
概念
etcd 以 key-value 方式进行值的存储, 用于配置共享和服务发现
结构
etcd 可以创建, 删除目录, 用于区分保存不同的信息
key-volume 可以直接存取到 etcd 集群中
同理, key-value 可以保存到不同目录中
key 被保存到 btree 中, 方便进行搜索与获取
api-version
当前 etcdctl 支持 ETCDCTL-API=2 ETCDCTL_API=3 两种不同的操作类型
不同的 api 类型使用的命令参数不一样
通过环境变量切换方法定义当前 api 类型
version2
[root@terry ~]# etcdctl --help
NAME:
etcdctl - A simple command line client for etcd.
USAGE:
etcdctl [global options] command [command options] [arguments...]
VERSION:
3.2.7
COMMANDS:
backup backup an etcd directory
cluster-health check the health of the etcd cluster
mk make a new key with a given value
mkdir make a new directory
rm remove a key or a directory
rmdir removes the key if it is an empty directory or a key-value pair
get retrieve the value of a key
ls retrieve a directory
set set the value of a key
setdir create a new directory or update an existing directory TTL
update update an existing key with a given value
updatedir update an existing directory
watch watch a key for changes
exec-watch watch a key for changes and exec an executable
member member add, remove and list subcommands
user user add, grant and revoke subcommands
role role add, grant and revoke subcommands
auth overall auth controls
help, h Shows a list of commands or help for one command
version3
[root@terry ~]# export ETCDCTL_API=3
[root@terry ~]# etcdctl --help
NAME:
etcdctl - A simple command line client for etcd3.
USAGE:
etcdctl
VERSION:
3.2.7
API VERSION:
3.2
COMMANDS:
get Gets the key or a range of keys
put Puts the given key into the store
del Removes the specified key or range of keys [key, range_end)
txn Txn processes all the requests in one transaction
compaction Compacts the event history in etcd
alarm disarm Disarms all alarms
alarm list Lists all alarms
defrag Defragments the storage of the etcd members with given endpoints
endpoint health Checks the healthiness of endpoints specified in `--endpoints` flag
endpoint status Prints out the status of endpoints specified in `--endpoints` flag
watch Watches events stream on keys or prefixes
version Prints the version of etcdctl
lease grant Creates leases
lease revoke Revokes leases
lease timetolive Get lease information
lease keep-alive Keeps leases alive (renew)
member add Adds a member into the cluster
member remove Removes a member from the cluster
member update Updates a member in the cluster
member list Lists all members in the cluster
snapshot save Stores an etcd node backend snapshot to a given file
snapshot restore Restores an etcd member snapshot to an etcd directory
snapshot status Gets backend snapshot status of a given file
make-mirror Makes a mirror at the destination etcd cluster
migrate Migrates keys in a v2 store to a mvcc store
lock Acquires a named lock
elect Observes and participates in leader election
auth enable Enables authentication
auth disable Disables authentication
user add Adds a new user
user delete Deletes a user
user get Gets detailed information of a user
user list Lists all users
user passwd Changes password of user
user grant-role Grants a role to a user
user revoke-role Revokes a role from a user
role add Adds a new role
role delete Deletes a role
role get Gets detailed information of a role
role list Lists all roles
role grant-permission Grants a key to a role
role revoke-permission Revokes a key from a role
check perf Check the performance of the etcd cluster
help Help about any command
增删改查
注意,
当前文档使用 centos 7 rpm 软件( etcd-3.2.7-1.el7.x86_64 及 etcd-3.0.15-1.el7.x86_64 )
在增删改查上, 官档主要介绍 api-version=3 版本的使用方法
连接 etcd
利用 etcdctl 命令进行连接
本地连接, 默认使用 http://127.0.0.1:2379 作为默认 endpoint
假如需要执行远程连接, 可以通过定义 endpoint 实现
ex: etcd --endpoint http://10.199.205.229:2379