首页 > 其他 > 详细

golang etcd安装

时间:2020-05-19 17:45:30      阅读:59      评论:0      收藏:0      [点我收藏+]

1.Linux安装

curl -L https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz -o etcd-v3.3.2-linux-amd64.tar.gz
tar zxf etcd-v3.3.2-linux-amd64.tar.gz

2.查看版本

./etcd -version

3.后台启动

nohup ./etcd >/tmp/etcd.log 2>&1 &       // 日志文件输出到/tmp/etcd.log目录 

3.1 设置环境变量

root@localhost etcd]# echo ‘export ETCDCTL_API=3‘ >> /etc/profile ## 环境变量添加 ETCDCTL_API=3
[root@localhost etcd]# source /etc/profile # 是profile中修改的文件生效
[root@localhost etcd]# ./etcdctl get mykey # 可以直接使用./etcdctl get key 命令了
mykey
this is awesome # 刚添加的内容 

4.添加key

./etcdctl put mykey "this is awesome"

5.其他操作

./etcdctl –version?? –api版本
./etcdctl ls -p /?? –列出目录下所有目录或节点,-p参数会自动用/标识出节点还是目录
./etcdctl set /p1/p2/v1 hello? –创建一个节点,并给他一个value
./etcdctl get /p1/p2/v1?? –获取一个节点的value

# 删除某个 key
?  ./etcdctl mk /foo bar
bar
?  ./etcdctl rm /foo
PrevNode.Value: bar
?  ./etcdctl get /foo
Error:  100: Key not found (/foo) [1062]

# 只有当 key 的值匹配的时候,才进行删除
?  ./etcdctl mk /foo bar
bar
?  ./etcdctl rm --with-value wrong /foo
Error:  101: Compare failed ([wrong != bar]) [1063]
?  ./etcdctl rm --with-value bar /foo

# 创建一个目录
?  ./etcdctl mkdir /dir

# 删除空目录
?  ./etcdctl mkdir /dir/subdir/
?  ./etcdctl rmdir /dir/subdir/

# 删除非空目录
?  ./etcdctl rmdir /dir
Error:  108: Directory not empty (/dir) [1071]
?  ./etcdctl rm --recursive /dir

# 列出目录的内容
?  ./etcdctl ls /
/queue
/anotherdir
/message

# 递归列出目录的内容
?  ./etcdctl ls --recursive /
/anotherdir
/message
/queue
/queue/00000000000000001053
/queue/00000000000000001054

# 监听某个 key,当 key 改变的时候会打印出变化
?  ./etcdctl watch /message
changed

# 监听某个目录,当目录中任何 node 改变的时候,都会打印出来
?  ./etcdctl watch --recursive /
[set] /message
changed

# 一直监听,除非 `CTL + C` 导致退出监听
?  ./etcdctl watch --forever /message
new value
chaned again
Wola

# 监听目录,并在发生变化的时候执行一个命令
?  ./etcdctl exec-watch --recursive / -- sh -c "echo change detected."
change detected.

简单:易于部署,易使用。基于 HTTP+JSON 的 API 让你用 curl 就可以轻松使用。
安全:可选 SSL 客户认证机制。
快速:每个实例每秒支持一千次写操作。
可信:使用一致性 Raft 算法充分实现了分布式。

相关链接

https://www.jianshu.com/p/2966b6ef5d10
https://juejin.im/post/5dabc50ef265da5b591b761a

golang etcd安装

原文:https://www.cnblogs.com/tomtellyou/p/12917991.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!