标签:idg 删除 ide 设置 现在 子目录 dex before 键值存储
etcd 是一个一致的分布式可靠的键值存储技术。可被用来做配置共享和服务发现。
etc
目录,发音为/??tsi?di?/
。curl -L https://github.com/coreos/etcd/releases/download/v3.3.1/etcd-v3.3.1-linux-amd64.tar.gz -o etcd-v3.3.1-linux-amd64.tar.gz
tar xzvf etcd-v3.3.1-linux-amd64.tar.gz
cd etcd-v3.3.1-linux-amd64
sudo cp etcd /usr/local/bin/
sudo cp etcdctl /usr/local/bin/
# 安装
brew install etcd
# 验证安装
etcd -version
etcdctl -version
参考 Running etcd under Docker - CoreOS 及 docker_practice/etcd/install :
# 使用 host IP
export ETCD_NODE1=127.0.0.1
# 安装 etcd
docker run --name etcd -p 2379:2379 -p 2380:2380 --volume=etcd-data:/etcd-data quay.io/coreos/etcd:latest /usr/local/bin/etcd --data-dir=/etcd-data --name node1 --initial-advertise-peer-urls http://${ETCD_NODE1}:2380 --listen-peer-urls http://0.0.0.0:2380 --advertise-client-urls http://${ETCD_NODE1}:2379 --listen-client-urls http://0.0.0.0:2379 --initial-cluster node1=http://${ETCD_NODE1}:2380
# 进入etcd 命令行交互
docker exec -it etcd /bin/sh
# 验证安装
etcd -version
etcdctl -version
# 验证是否启动
curl http://127.0.0.1:2379/version
参考 Docker Compose 的使用说明,编辑 docker-compose.yml
文件如下:
version: "3.6"
services:
node1:
image: quay.io/coreos/etcd
volumes:
- node1-data:/etcd-data
expose:
- 2379
- 2380
networks:
cluster_net:
ipv4_address: 172.16.238.100
environment:
- ETCDCTL_API=3
command:
- /usr/local/bin/etcd
- --data-dir=/etcd-data
- --name
- node1
- --initial-advertise-peer-urls
- http://172.16.238.100:2380
- --listen-peer-urls
- http://0.0.0.0:2380
- --advertise-client-urls
- http://172.16.238.100:2379
- --listen-client-urls
- http://0.0.0.0:2379
- --initial-cluster
- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
- --initial-cluster-state
- new
- --initial-cluster-token
- docker-etcd
node2:
image: quay.io/coreos/etcd
volumes:
- node2-data:/etcd-data
networks:
cluster_net:
ipv4_address: 172.16.238.101
environment:
- ETCDCTL_API=3
expose:
- 2379
- 2380
command:
- /usr/local/bin/etcd
- --data-dir=/etcd-data
- --name
- node2
- --initial-advertise-peer-urls
- http://172.16.238.101:2380
- --listen-peer-urls
- http://0.0.0.0:2380
- --advertise-client-urls
- http://172.16.238.101:2379
- --listen-client-urls
- http://0.0.0.0:2379
- --initial-cluster
- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
- --initial-cluster-state
- new
- --initial-cluster-token
- docker-etcd
node3:
image: quay.io/coreos/etcd
volumes:
- node3-data:/etcd-data
networks:
cluster_net:
ipv4_address: 172.16.238.102
environment:
- ETCDCTL_API=3
expose:
- 2379
- 2380
command:
- /usr/local/bin/etcd
- --data-dir=/etcd-data
- --name
- node3
- --initial-advertise-peer-urls
- http://172.16.238.102:2380
- --listen-peer-urls
- http://0.0.0.0:2380
- --advertise-client-urls
- http://172.16.238.102:2379
- --listen-client-urls
- http://0.0.0.0:2379
- --initial-cluster
- node1=http://172.16.238.100:2380,node2=http://172.16.238.101:2380,node3=http://172.16.238.102:2380
- --initial-cluster-state
- new
- --initial-cluster-token
- docker-etcd
volumes:
node1-data:
node2-data:
node3-data:
networks:
cluster_net:
driver: bridge
ipam:
driver: default
config:
-
subnet: 172.16.238.0/24
Tip:可以通过
ETCDCTL_API=3 etcdctl -h
查看 v3 版本的命令行帮助页
# 指定版本为 v3 且 key 前缀为空,也就是所有 key 了
ETCDCTL_API=3 etcdctl get --prefix=true ""
ETCDCTL_API=3 etcdctl put /testdir/testkey "你好 etcd"
Tip:可以通过
etcdctl -h
查看 v2 版本的命令行帮助页
设置某个键的值,支持选项:
--ttl '0' 该键值的超时时间(单位为秒),不配置(默认为 0)则永不超时
--swap-with-value value 若该键现在的值是 value,则进行设置操作
--swap-with-index '0' 若该键现在的索引值是指定索引,则进行设置操作
示例:
etcdctl set /testdir/testkey "Hello etcd"
获取指定键的值,支持选项:
--sort 对结果进行排序
--consistent 将请求发给主节点,保证获取内容的一致性
示例:
etcdctl get /testdir/testkey
更新某个键的值,支持选项:
--ttl '0' 该键值的超时时间(单位为秒),不配置(默认为 0)则永不超时
示例:
etcdctl update /testdir/testkey "你好 etcd"
删除某个键,支持选项:
--dir 删除空目录或键值对
--recursive, -r 删除当前键及其子键(当为目录时)
--with-value 当值匹配时删除
--with-index '0' 当索引匹配时删除
示例:
etcdctl rm /testdir/testkey --with-value "Hello etcd"
列出目录(默认为根目录 /
)下的键和子目录,默认不显示子目录中内容。支持选项:
--sort 将输出结果排序
--recursive 如果目录下有子目录,则递归输出其中的内容
-p 对于输出为目录,在最后添加 / 进行区分
示例:
etcdctl ls -r -p
使用 member
命令进行 etcd 实例与集群的操作:
list
列出 etcd 集群中的所有实例add
添加 etcd 实例到集群中remove
从集群中删除 etcd 实例update
更新集群中的 etcd 实例示例:
# v2
etcdctl member list
# v3
ETCDCTL_API=3 etcdctl member list
# 查看版本
curl http://127.0.0.1:2379/version
# get
curl http://127.0.0.1:2379/v2/keys/testdir/testkey
HOST=http://ecp-etcd-7fbedb40ccf7b594.elb.us-east-1.amazonaws.com:2379
declare -A KV=(["config/http_server_port"]=8080 ["config/db_type"]="dynamo" ["config/aws_region"]="us-east-1" ["config/kafka_brokers"]="172.19.0.9:9092")
# show version
curl $HOST/version
# put key value
for k in ${!KV[@]}
do
key=$(echo -n $k | base64)
value=$(echo -n ${KV[$k]} | base64)
## delete key before
curl -L $HOST/v3alpha/kv/deleterange -X POST -d "{\"key\": \"${key}\"}"
## put new key and value
curl -L $HOST/v3alpha/kv/put -X POST -d "{\"key\":\"${key}\", \"value\": \"${value}\"}"
done
# show all keys
curl -L $HOST/v3alpha/kv/range -X POST -d '{"key": "AA==", "range_end": "AA=="}'
#curl -X POST -d '{"key": "L2FwcA==", "range_end": "L2I="}' $HOST/v3alpha/kv/range
已知问题:
{\"error\":\"invalid character ‘\\\\n‘ in string literal\",\"code\":3}
。标签:idg 删除 ide 设置 现在 子目录 dex before 键值存储
原文地址:https://www.cnblogs.com/lshare/p/11334309.html