当前位置:网站首页>Etcd tutorial - Chapter 5 etcd etcdctl usage
Etcd tutorial - Chapter 5 etcd etcdctl usage
2022-06-27 07:49:00 【Ximu Qi】
Etcd course — The fifth chapter Etcd And etcdctl Use
Preface
Etcd In microservices and Kubernates Not only can it be used as a service in a cluster register And Find out , It can also be used as key-value Middleware for storage .
One 、etcdctl Introduce
etcdctl Is a command line client , It can provide some concise commands , For users to follow directly etcd Service contact , Without having to be based on HTTP API The way . It is convenient to test the service or modify the database content manually .
We can just start by etdctl To familiarize yourself with the relevant operations . These operations are similar to HTTP API It's basically the corresponding .etcdctl In two different etcd The behavior under version is also completely different .
export ETCDCTL_API=2
export ETCDCTL_API=3
This paper mainly uses API 3 Mainly .
Etcd The binary distribution package already contains etcdctl Tools ,etcdctl The supported commands are generally divided into database operation and non database operation .
Two 、 Non database operations
2.1 see Etcd Version of command
[[email protected] ~]# etcd --version
etcd Version: 3.5.4
Git SHA: 08407ff76
Go Version: go1.16.15
Go OS/Arch: linux/amd64
2.2 see etcdctl Common commands
[[email protected] ~]# etcdctl h
NAME:
etcdctl - A simple command line client for etcd3.
USAGE:
etcdctl [flags]
VERSION:
3.5.4
API VERSION:
3.5
COMMANDS:
alarm disarm Disarms all alarms
alarm list Lists all alarms
auth disable Disables authentication
auth enable Enables authentication
auth status Returns authentication status
check datascale Check the memory usage of holding data for different workloads on a given server endpoint.
check perf Check the performance of the etcd cluster
compaction Compacts the event history in etcd
defrag Defragments the storage of the etcd members with given endpoints
del Removes the specified key or range of keys [key, range_end)
elect Observes and participates in leader election
endpoint hashkv Prints the KV history hash for each endpoint in --endpoints
endpoint health Checks the healthiness of endpoints specified in `--endpoints` flag
endpoint status Prints out the status of endpoints specified in `--endpoints` flag
get Gets the key or a range of keys
help Help about any command
lease grant Creates leases
lease keep-alive Keeps leases alive (renew)
lease list List all active leases
lease revoke Revokes leases
lease timetolive Get lease information
lock Acquires a named lock
make-mirror Makes a mirror at the destination etcd cluster
member add Adds a member into the cluster
member list Lists all members in the cluster
member promote Promotes a non-voting member in the cluster
member remove Removes a member from the cluster
member update Updates a member in the cluster
move-leader Transfers leadership to another etcd cluster member.
put Puts the given key into the store
role add Adds a new role
role delete Deletes a role
role get Gets detailed information of a role
role grant-permission Grants a key to a role
role list Lists all roles
role revoke-permission Revokes a key from a role
snapshot restore Restores an etcd member snapshot to an etcd directory
snapshot save Stores an etcd node backend snapshot to a given file
snapshot status [deprecated] Gets backend snapshot status of a given file
txn Txn processes all the requests in one transaction
user add Adds a new user
user delete Deletes a user
user get Gets detailed information of a user
user grant-role Grants a role to a user
user list Lists all users
user passwd Changes password of user
user revoke-role Revokes a role from a user
version Prints the version of etcdctl
watch Watches events stream on keys or prefixes
OPTIONS:
--cacert="" verify certificates of TLS-enabled secure servers using this CA bundle
--cert="" identify secure client using this TLS certificate file
--command-timeout=5s timeout for short running command (excluding dial timeout)
--debug[=false] enable client-side debug logging
--dial-timeout=2s dial timeout for client connections
-d, --discovery-srv="" domain name to query for SRV records describing cluster endpoints
--discovery-srv-name="" service name to query when using DNS discovery
--endpoints=[127.0.0.1:2379] gRPC endpoints
-h, --help[=false] help for etcdctl
--hex[=false] print byte strings as hex encoded strings
--insecure-discovery[=true] accept insecure SRV records describing cluster endpoints
--insecure-skip-tls-verify[=false] skip server certificate verification (CAUTION: this option should be enabled only for testing purposes)
--insecure-transport[=true] disable transport security for client connections
--keepalive-time=2s keepalive time for client connections
--keepalive-timeout=6s keepalive timeout for client connections
--key="" identify secure client using this TLS key file
--password="" password for authentication (if this option is used, --user option shouldn't include password)
--user="" username[:password] for authentication (prompt if password is not supplied)
-w, --write-out="simple" set the output format (fields, json, protobuf, simple, table)
You can see ,etcdctl A lot of orders , Common command options 【OPTIONS】:
--debug Output CURL command , Display the request initiated when executing the command
--no-sync Do not synchronize cluster information before making a request
--output, -o 'simple' Format of output content (simple For the original information ,json For the json Format decoding , Easier to read )
--peers, -C Specify the peer information in the cluster , Separated by commas ( The default is : "127.0.0.1:4001")
--cert-file HTTPS For the next client SSL Certificate file
--key-file HTTPS For the next client SSL The key file
--ca-file Server use HTTPS when , Use CA Document validation
--help, -h Display help command information
--version, -v Print version information
3、 ... and 、 Database operation
Database operations revolve around the of key values and directories CRUD ( I.e. add, delete, change and check , accord with REST A set of styles API operation ) Complete lifecycle management .
Etcd The hierarchical spatial structure is adopted in the organization of keys ( Similar to the concept of directory in file system ), The key specified by the user can be a separate name , Such as :testkey, At this time, it is actually placed in the root directory / below , You can also specify a directory structure for , Such as /cluster1/node2/testkey, The corresponding directory structure will be created .
3.1 Write operations
[[email protected] ~]# etcdctl put /testdir/testkey "Hello world"
OK
[[email protected] ~]# etcdctl put /testdir/testkey2 "Hello world2"
OK
[[email protected] ~]# etcdctl put /testdir/testkey3 "Hello world3"
OK
Three pairs of key values were written successfully ,/testdir/testkey、/testdir/testkey2 and /testdir/testkey3.
3.2 Read operations
[[email protected] ~]# etcdctl get /testdir/testkey
/testdir/testkey
Hello world
get Hexadecimal reads the specified value :
[[email protected] ~]# etcdctl get /testdir/testkey --hex
\x2f\x74\x65\x73\x74\x64\x69\x72\x2f\x74\x65\x73\x74\x6b\x65\x79
\x48\x65\x6c\x6c\x6f\x20\x77\x6f\x72\x6c\x64
get Values in the specified range :
[[email protected] ~]# etcdctl get /testdir/testkey /testdir/testkey3
/testdir/testkey
Hello world
/testdir/testkey2
Hello world2
You can see , Obtained greater than or equal to /testdir/testkey, And less than /testdir/testkey3 The key/value pair .testkey3 Out of range , Because the range is Semi open interval [testkey, testkey3), It doesn't contain testkey3.
Gets all key value pairs for the specified prefix , adopt –prefix You can specify a prefix :
[[email protected] ~]# etcdctl get --prefix /testdir/testkey
/testdir/testkey
Hello world
/testdir/testkey2
Hello world2
/testdir/testkey3
Hello world3
In this way, you can get all the information in /testdir/testkey The first key value pair . When the current result is too many , You can also use –limit=2 Limit the number of acquisitions :
etcdctl get --prefix --limit=2 /testdir/testkey
Read values from previous versions of the key :
The application may want to read the substituted value of the key 【 That is, the old value 】. for example , The application may want to rollback to the old configuration through the previous version of the access key . perhaps , An application may want to obtain a unified view covering multiple keys through multiple requests , These requests can be made by accessing the key history . because etcd Each modification of the key value store on the cluster will increase etcd Global revision of the cluster , The application can provide the old etcd Modify the version to read the replaced key . The following key value pairs exist :
foo = bar # revision = 2
foo1 = bar2 # revision = 3
foo = bar_new # revision = 4
foo1 = bar2_new # revision = 5
preparation :
[[email protected] ~]# etcdctl put foo bar
OK
[[email protected] ~]# etcdctl put foo1 bar2
OK
[[email protected] ~]# etcdctl put foo bar_new
OK
[[email protected] ~]# etcdctl put foo1 bar2_new
OK
Access previous versions key An example of :
[[email protected] ~]# etcdctl get --prefix foo # Visit the latest version of key
foo
bar_new
foo1
bar2_new
[[email protected] ~]# etcdctl get --prefix --rev=4 foo # Access No. 4 Versions key
foo
bar_new
foo1
bar2
[[email protected] ~]# etcdctl get --prefix --rev=3 foo # Access No. 3 Versions key
foo
bar
foo1
bar2
[[email protected] ~]# etcdctl get --prefix --rev=2 foo # Access No. 3 Versions key
foo
bar
[[email protected] ~]# etcdctl get --prefix --rev=1 foo # Access No. 1 Versions key
Read a key greater than or equal to the specified key byte Value key
The application may want to read a key greater than or equal to the specified key Of byte Value key . hypothesis etcd The cluster already has the following keys :
a = 123
b = 456
z = 789
Read keys greater than or equal to b Of byte Value key command :
[[email protected] ~]# etcdctl get --from-key b
b
456
c
789
Delete key . Applications can be from etcd Delete a key or a specific range of keys in the cluster .
hypothesis etcd The cluster already has the following keys :
a = 123
b = 456
c = 789
foo = bar_new
foo1 = bar2_new
hello = world
Delete key foo The order of :
[[email protected] ~]# etcdctl del foo
1 # Number of delete keys
Remove from foo to foo1 Range key command :
etcdctl del foo foo1
Delete key a And return the command of the deleted key value pair :
[[email protected] ~]# etcdctl del --prev-kv a
1 # Number of delete keys
a # Deleted key
123 # The value of the deleted key
Delete prefix foo The command of the key :
[[email protected] ~]# etcdctl del --prefix foo
1 # Number of delete keys
Delete keys greater than or equal to b Of byte Value key command :
[[email protected] ~]# etcdctl del --from-key b
3 # Number of delete keys
3.3 watch History changes
边栏推荐
- C how to call line and rows when updating the database
- JS to determine whether the result is qualified, the range is 0-100, otherwise re-enter
- JS use the switch statement to output the corresponding English day of the week according to 1-7
- Common operation and Principle Exploration of stream
- 二叉树结构以及堆结构基础
- 八大误区,逐个击破(终篇):云难以扩展、定制性差,还会让管理员失去控制权?
- js判断用户输入的数是否为质数(多种方法)
- c的时间函数算效率
- ACM course term summary
- Installation and functions of uview
猜你喜欢

VNC Viewer方式的远程连接树莓派

洛谷刷题心得记录
![Speech signal processing - concept (II): amplitude spectrum (STFT spectrum), Mel spectrum [the deep learning of speech mainly uses amplitude spectrum and Mel spectrum] [extracted with librosa or torch](/img/b3/6c8d9fc66e2a4dbdc0dd40179266d3.png)
Speech signal processing - concept (II): amplitude spectrum (STFT spectrum), Mel spectrum [the deep learning of speech mainly uses amplitude spectrum and Mel spectrum] [extracted with librosa or torch

js用switch语句根据1-7输出对应英文星期几

【批处理DOS-CMD命令-汇总和小结】-输出/显示命令——echo

淘宝虚拟产品开店教程之作图篇

L'enquête en aveugle a montré que les femmes étaient meilleures que les hommes.

js用switch输出成绩是否合格

win10-如何管理开机启动项?

索引+sql练习优化
随机推荐
JS output shape
What is a flotation machine?
八大误区,逐个击破(终篇):云难以扩展、定制性差,还会让管理员失去控制权?
How to view program running time (timer) in JS
2、项目使用的QT组件
【c ++ primer 笔记】第4章 表达式
Recognize the ordering of O (nlogn)
(note) Anaconda navigator flashback solution
JS to determine whether the result is qualified, the range is 0-100, otherwise re-enter
R language calculates Spearman correlation coefficient in parallel to speed up the construction of co occurrence network
How torch. gather works
语音信号处理-概念(四):傅里叶变换、短时傅里叶变换、小波变换
PayPal账户遭大规模冻结!跨境卖家如何自救?
【批处理DOS-CMD命令-汇总和小结】-将文件夹映射成虚拟磁盘——subst
After working in a large factory for ten years with an annual salary of 400000 yuan, I was suddenly laid off. If the company wanted to abandon you, it wouldn't leave any kindness
win10-如何管理开机启动项?
How can the flower e-commerce 2.0 era go after the breakthrough from 0 to 1?
期货反向跟单—交易员的培训问题
js中判断奇偶的函数,求圆面积的函数
磁选机是什么?