继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

ETCD 安装、简介、使用REST API

慕虎7371278
关注TA
已关注
手记 1307
粉丝 202
获赞 878

ETCD

分布式键值存储系统,可用于服务注册发现

下载etcd安装包

访问git下载安装包,地址https://github.com/coreos/etcd/releases
使用wget命令加上资源url下载文件

解压

tar -zxvf etcd-v3.3.2-linux-amd64.tar.gz # z参数对应.gz压缩格式

查看etcd信息

[root@localhost etcd]# ./etcd -versionetcd Version: 3.3.2
Git SHA: c9d46ab37
Go Version: go1.9.4
Go OS/Arch: linux/amd64

启动etcd(后台进程启动)

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

./etcd 可以直接前台运行etcd

添加key

[root@localhost etcd]# ./etcdctl put mykey "this is awesome"No help topic for 'put' # etcdctl 需要设置环境变量 ETCDCTL_API=3,使用第三版的api,默认的api是2[root@localhost etcd]# ETCDCTL_API=3 ./etcdctl put mykey "this is awesome"OK

设置环境变量

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 # 刚添加的内容

etcd的README.md文件中有etcd的介绍和命令
使用 ETCDCTL_API=2 ./etcdctl 可以查看 api2的命令
使用 ETCDCTL_API=3 ./etcdctl 可以查看 api3的命令

REST API

  • 查看版本信息

[root@localhost etcd]# curl http://127.0.0.1:2379/version {"etcdserver":"3.3.2","etcdcluster":"3.3.0"}

默认2379和2380端口只在127.0.0.1机器上监听,即本机

[root@localhost etcd]# ss -tnlState      Recv-Q Send-Q                       Local Address:Port                                      Peer Address:Port              
LISTEN     0      128                              127.0.0.1:2379                                                 *:*                  
LISTEN     0      128                              127.0.0.1:2380                                                 *:*                  
LISTEN     0      128                                      *:22                                                   *:*                  
LISTEN     0      100                              127.0.0.1:25                                                   *:*                  
LISTEN     0      128                                     :::80                                                  :::*                  
LISTEN     0      128                                     :::22                                                  :::*                  
LISTEN     0      100                                    ::1:25                                                  :::*

若想通过机器IP访问则需要启动时指定IP

./etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380# 后台启动nohup ./etcd --listen-client-urls http://0.0.0.0:2379 --advertise-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 > /tmp/etcd.log 2>&1 &

0.0.0.0:2379 表示任何ip都可以访问

[root@localhost etcd]# curl http://192.168.72.31:2379/version # 通过机器IP访问 {"etcdserver":"3.3.2","etcdcluster":"3.3.0"}



作者:maxbin
链接:https://www.jianshu.com/p/2966b6ef5d10


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP

相关阅读

设计模式