在分布式系统中,etcd
是一个高可用的键值存储,用于存储和共享配置信息、服务发现、协调等。向 etcd
写入数据可以通过多种方式进行,常见的方式是使用 etcd
提供的 HTTP API 或者通过客户端库来进行操作。
目录
一、使用EtcdCtl工具来写入数据
1.1、设置环境变量(可选)
export ETCDCTL_API=3
export ETCDCTL_ENDPOINTS=http://localhost:2379
1.2、使用etcdctl put写入数据
etcdctl put <key> <value>
etcdctl put /config/db/host "192.168.1.100"
1.3、通过etcdctl put -h来查看相关帮助信息
etcdctl put -h
NAME:
put - Puts the given key into the store
USAGE:
etcdctl put [options] <key> <value> (<value> can also be given from stdin) [flags]
DESCRIPTION:
Puts the given key into the store.
When <value> begins with '-', <value> is interpreted as a flag.
Insert '--' for workaround:
$ put <key> -- <value>
$ put -- <key> <value>
If <value> isn't given as a command line argument and '--ignore-value' is not specified,
this command tries to read the value from standard input.
If <lease> isn't given as a command line argument and '--ignore-lease' is not specified,
this command tries to read the value from standard input.
For example,
$ cat file | put <key>
will store the content of the file to <key>.
以下是 etcdctl put -h
命令帮助信息的中文翻译::
---
### 名称:
`put` - 将给定的键值对写入存储中
### 用法:
```bash
etcdctl put [选项] <key> <value> (<value> 也可以通过标准输入给出) [标志]
```
### 描述:
将给定的键值对写入存储中。
- 当 `<value>` 以 `-` 开