ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

etcd——源码编译、学习

2022-08-17 13:34:16  阅读:180  来源: 互联网

标签:http urls -- 192.168 编译 源码 etcd 1.32


借一张图

 

1、下载

https://github.com/etcd-io/etcd

git clone https://github.com/nats-io/nats-server.git

 

2、编译

进入etcd目录,

 

mac/linux下,   make clean  &&   make build

在etcd/bin目录下,生成 etcd  etcdctl   etcdutl 三个可执行文件

 

在win10下,不用make的前提下,

go build -o bin\etcd.exe server\main.go

go build -o bin\etcdctl.exe etcdctl\main.go

 

出现\etcd\client\v3 目录下诸多文件报错,这些文件都用的目录引用,

把真实目录 \etcd\tests\integration\clientv3\examples下对应的文件直接替换 D:\git\go\etcd\etcd\client\v3 目录下的,

重新编译即可。

 

3、单节点启动

命令行下: 

etcd -data-dir ~/data.etcd -advertise-client-urls  http://0.0.0.0:2379 -listen-client-urls http://0.0.0.0:2379

在 goland ide 下,加启动参数

--data-dir bin\in-ide.etcd --advertise-client-urls http://0.0.0.0:2379 --listen-client-urls http://0.0.0.0:2379  

 

4、测试

etcdctl member list
etcdctl --endpoints=10.60.80.11:2379 member list

etcdctl --endpoints=10.60.80.11:2379 put foo hihi
etcdctl --endpoints=10.60.80.11:2379 get foo

 

5、win10下集群部署与测试

1、win 10 环境
下载  https://github.com/etcd-io/etcd/releases
解压 etcd-v3.4.20-windows-amd64.zip

2、启动命令见
https://blog.51cto.com/u_10125763/3700481

3、依次启动 start1.bat   start2.bat  start3.bat

4、查看集群状态
etcdctl --endpoints=[192.168.1.32:2379,192.168.1.32:3379,192.168.1.32:4379]   member list

etcdctl --endpoints=[192.168.1.32:2379,192.168.1.32:3379,192.168.1.32:4379]   endpoint health --cluster=true

etcdctl --endpoints=10.60.80.11:2379 member list

5、查看服务发现
etcdctl --endpoints=[192.168.1.32:2379,192.168.1.32:3379,192.168.1.32:4379]   get /game/sanguo-test/server_state/gateway/1660642593870881200
/game/sanguo-test/server_state/gateway/1660642593870881200

start1.bat

.\etcd.exe --name etcd01 ^
--data-dir .\data\etcd01 ^
--advertise-client-urls http://192.168.1.32:2379 ^
--listen-client-urls http://192.168.1.32:2379 ^
--listen-peer-urls http://192.168.1.32:2380 ^
--initial-advertise-peer-urls http://192.168.1.32:2380 ^
--initial-cluster-token etcd-cluster-1 ^
--initial-cluster etcd01=http://192.168.1.32:2380,etcd02=http://192.168.1.32:2381,etcd03=http://192.168.1.32:2382 ^
--initial-cluster-state new

pause

start2.bat

.\etcd.exe --name etcd02 ^
--data-dir .\data\etcd02 ^
--advertise-client-urls http://192.168.1.32:3379 ^
--listen-client-urls http://192.168.1.32:3379 ^
--listen-peer-urls http://192.168.1.32:2381 ^
--initial-advertise-peer-urls http://192.168.1.32:2381 ^
--initial-cluster-token etcd-cluster-1 ^
--initial-cluster etcd01=http://192.168.1.32:2380,etcd02=http://192.168.1.32:2381,etcd03=http://192.168.1.32:2382 ^
--initial-cluster-state new

pause

start3.bat

.\etcd.exe --name etcd03 ^
--data-dir .\data\etcd03 ^
--advertise-client-urls http://192.168.1.32:4379 ^
--listen-client-urls http://192.168.1.32:4379 ^
--listen-peer-urls http://192.168.1.32:2382 ^
--initial-advertise-peer-urls http://192.168.1.32:2382 ^
--initial-cluster-token etcd-cluster-1 ^
--initial-cluster etcd01=http://192.168.1.32:2380,etcd02=http://192.168.1.32:2381,etcd03=http://192.168.1.32:2382 ^
--initial-cluster-state new

pause

 

6、mac/linux下集群部署

创建执行文件

touch etcd-static.sh

在每个etcd节点上,指定集群成员。

# 指定集群token
# 如果你所在的网络环境配置了多个etcd集群,为了避免意外发生,最好使用-initial-cluster-token参数为每个集群单独配置一个token认证。
# 这样就可以确保每个集群和集群的成员都拥有独特的ID。 TOKEN=token-01 CLUSTER_STATE=new NAME_1=machine-1 NAME_2=machine-2 NAME_3=machine-3 HOST_1=192.168.199.140 HOST_2=192.168.199.141 HOST_3=192.168.199.142 CLUSTER=${NAME_1}=http://${HOST_1}:2380,${NAME_2}=http://${HOST_2}:2380,${NAME_3}=http://${HOST_3}:2380

每个节点添加一下各节点对应启动命令行

THIS_NAME=${NAME_1}
THIS_IP=${HOST_1}
/opt/etcd-v3.2.32-linux-amd64/etcd --data-dir=data.etcd --name ${THIS_NAME} \
    --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
    --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
    --initial-cluster ${CLUSTER} \
    --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
    
THIS_NAME=${NAME_2}
THIS_IP=${HOST_2}
/opt/etcd-v3.2.32-linux-amd64/etcd --data-dir=data.etcd --name ${THIS_NAME} \
    --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
    --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
    --initial-cluster ${CLUSTER} \
    --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}
    
THIS_NAME=${NAME_3}
THIS_IP=${HOST_3}
/opt/etcd-v3.2.32-linux-amd64/etcd --data-dir=data.etcd --name ${THIS_NAME} \
    --initial-advertise-peer-urls http://${THIS_IP}:2380 --listen-peer-urls http://${THIS_IP}:2380 \
    --advertise-client-urls http://${THIS_IP}:2379 --listen-client-urls http://${THIS_IP}:2379 \
    --initial-cluster ${CLUSTER} \
    --initial-cluster-state ${CLUSTER_STATE} --initial-cluster-token ${TOKEN}

 

启动服务:sh etcd-static.sh

 

标签:http,urls,--,192.168,编译,源码,etcd,1.32
来源: https://www.cnblogs.com/xingchong/p/16594799.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有