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
點擊查看更多內容
為 TA 點贊
評論
評論
共同學習,寫下你的評論
評論加載中...
作者其他優質文章
正在加載中
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦