ETCD 安装、简介、使用REST API

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 -version
etcd 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 -tnl
State      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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值