docker etcd 问题
踩过的坑,终将成为你的财富……
·
踩过的坑,终将成为你的财富……
1-Linux环境权限问题
举例:
某年,某月,某天,你突发奇想,想使用etcd作为微服务注册中心,此时可能你想用现成的框架,例如golang的go-micro/kratos/go-zero……等等,当然也可能有像我这样想徒手搓一套微服务框架的人,此时你满怀信心的搭建起了项目,一切的很顺利,此时来到安装etcd环节;
这时,你想到了方便快捷的docker,就想着用docker-compose快速搭建一个etcd三节点集群;
当你满怀信心的编写完docker-compose.yml
, 敲下sudo docker-compose up -d
, 然后成功运行,此时你满怀信心准备尝试使用etcd,当你使用etcd sdk操作时,爆出一个错误来:
{"level":"warn","ts":"2023-11-04T21:27:46.896566+0800","logger":"etcd-client","caller":"v3@v3.5.10/retry_interceptor.go:62","msg":"retrying of unary invoker failed","target":"etcd-endpoints://0xc00015ca80/127.0.0.1:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = latest balancer error: last connection error: connection error: desc = \"transport: Error while dialing: dial tcp 127.0.0.1:2379: connect: connection refused\""}
Error: context deadline exceeded
此时,你去sudo docker logs etcd_node1
查看日志发现没有什么问题:
然而,你不知道的是,其实略微细心往上翻会发现这句日志:
{"level":"warn","ts":"2023-11-04T21:42:05.350828+0800","caller":"etcdmain/etcd.go:146","msg":"failed to start etcd","error":"open /opt/bitnami/etcd/conf/peer-key.pem: permission denied"}
如果此时,你看到这句大概就明白缺什么东西了,缺少权限,缺少什么权限?
此时我直接一个sudo chmod -R 765 /opt/docker/etcd
, 然后重新运行项目,完美解决,然后,完结撒花;
这只是其中一个问题,但是,篇幅不允许再往下讲了(其实我也忘了还遇到什么问题了,最重要的应该就是这个),下面附赠etcd单节点tlsdocker-compose.yml
version: "3.7"
services:
etcd_node1:
image: "bitnami/etcd:latest"
container_name: "etcd_node1"
restart: "always"
ports:
- 10103:2379
- 10104:2380
environment:
- TZ=Asia/Shanghai
- ETCD_NAME=etcd_node1
- ETCD_ROOT_PASSWORD=hillstone
- ETCD_CLIENT_CERT_AUTH=true
- ETCD_PEER_CLIENT_CERT_AUTH=true
- ETCD_ADVERTISE_CLIENT_URLS=https://192.168.1.100:10103
- ETCD_INITIAL_ADVERTISE_PEER_URLS=https://192.168.1.100:10104
- ETCD_LISTEN_CLIENT_URLS=https://0.0.0.0:2379
- ETCD_LISTEN_PEER_URLS=https://0.0.0.0:2380
- ETCD_INITIAL_CLUSTER_TOKEN=etcd_cluster
- ETCD_INITIAL_CLUSTER=etcd_node1=https://192.168.1.100:10104
- ETCD_INITIAL_CLUSTER_STATE=new
- ETCD_DATA_DIR=/opt/bitnami/etcd/data
- ETCD_TRUSTED_CA_FILE=/opt/bitnami/etcd/conf/ca.pem
- ETCD_KEY_FILE=/opt/bitnami/etcd/conf/server-key.pem
- ETCD_CERT_FILE=/opt/bitnami/etcd/conf/server.pem
- ETCD_PEER_TRUSTED_CA_FILE=/opt/bitnami/etcd/conf/ca.pem
- ETCD_PEER_KEY_FILE=/opt/bitnami/etcd/conf/peer-key.pem
- ETCD_PEER_CERT_FILE=/opt/bitnami/etcd/conf/peer.pem
volumes:
# 将数据映射到宿主机
- ./data:/opt/bitnami/etcd/data
- ./cert/ca.pem:/opt/bitnami/etcd/conf/ca.pem
- ./cert/peer.pem:/opt/bitnami/etcd/conf/peer.pem
- ./cert/peer-key.pem:/opt/bitnami/etcd/conf/peer-key.pem
- ./cert/server.pem:/opt/bitnami/etcd/conf/server.pem
- ./cert/server-key.pem:/opt/bitnami/etcd/conf/server-key.pem
- ./cert/client-key.pem:/opt/bitnami/etcd/client-key.pem
- ./cert/client.pem:/opt/bitnami/etcd/client.pem
更多推荐
已为社区贡献1条内容
所有评论(0)