Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Deployment and use of basic etcd of Docker self-Discovery Registration Service

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

In this issue, the editor will bring you about the deployment and use of the basic etcd of Docker self-discovery registration service. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

1. Background

The self-discovery service foundation requires a highly available key storage system, which is easy to think of KV in-memory databases such as redis and memcached, but I finally chose etcd because it was born to be clustered and was born to be used as node data synchronization for conf.

1) etcd is a basic component of coreos and is also used to save configuration information. Here we mainly discuss the deployment and use of etcd for non-coreos systems.

2) at present, the latest version of etcd is v2.3.6, and the beta version is v3.x. We conduct drills based on v2 version.

two。 Be careful

All my docker images are built on alpine 3.x. If you need other versions, please modify them yourself.

3. Prepare 1) etcd official address

Https://github.com/coreos/etcd

2) download address of the latest version of Linux

Https://github.com/coreos/etcd/releases/download/v2.3.6/etcd-v2.3.6-linux-amd64.tar.gz

3) construct etcd docker image FROM alpine:3.3MAINTAINER Etcd Maintainers "kekuer@gmail.com" RUN ETCD_VER=2.3.6 & &\ echo "http://127.0.0.1:8098/main" > / etc/apk/repositories & &\ apk-- update add curl & &\ mkdir src & &\ cd src & &\ curl-O http://127.0.0.1:8080/etcd-v${ETCD_VER based on alpine }-linux-amd64.tar.gz & &\ tar xzvf etcd-v$ {ETCD_VER}-linux-amd64.tar.gz & &\ cd etcd-v$ {ETCD_VER}-linux-amd64 & &\ cp etcd etcdctl / usr/bin/ & &\ apk-- update del curl & &\ rm-rf / var/cache/apk/* / src ENTRYPOINT ["/ usr/bin/etcd"]

Note:

Modify the repository address according to your own alpine image address to build your own alpine local image. Please refer to my other article: Alpine Linux Repository Local Image making.

I made a file pool here and put it on a server. If you have a corresponding file pool server, change the etcd download address to: https://github.com/coreos/etcd/releases/download/v${ETCD_VER}/etcd-v${ETCD_VER}-linux-amd64.tar.gz

4. Concept 1) static configuration and self-discovery

A) static configuration: start the etcd service through the initial-cluster startup parameter, which is used to predict the cluster address

-initial-cluster infra0= http://172.0.1.10:2380,http://172.0.1.11:2380,infra2=http://172.0.1.12:2380\-initial-cluster-state new

Or use environment variables

ETCD_INITIAL_CLUSTER= "infra0= http://172.0.1.10:2380,infra1=http://172.0.1.11:2380,infra2=http://172.0.1.12:2380"ETCD_INITIAL_CLUSTER_STATE=new

B) self-discovery mode: automatically configure cluster service by specifying discovery discovery service token address

You can use the official address: of course, it is best for https://discovery.etcd.io/new?size=3, to build an etcd-discovery service on its own in China, use the previously constructed etcd image, run a docker container, and release the discovery port. I use port 80 here, and the internal port of container is 2379.

Docker run-- name etcd-discovery-d-- restart=always-- log-opt max-size=100m-p 80docker run 2379-v / docker/mount/etcd-discovery/:/etcd funwun.io/etcd:1.4\-data-dir / etcd\-snapshot-count=100\-listen-client-urls http://0.0.0.0:2379\-advertise-client-urls http://0.0.0.0:2379

Note:

Recover etcd data is a tedious task, so try to mount data to host, if it is EC2, it is best to re-mount an EBS as a mount disk for all docker (my habit, you can also put forward your own comments and suggestions)

The reason for the reduction of snapshot-count is that my machines are lightweight host with 1 GB of memory, so I want to ensure the usage of memory.

2) etcd node

Because etcd uses the Raft algorithm, it requires a majority of nodes to vote when making a decision, so it is generally deployed as odd nodes: 3, 5, 7

3) four main concepts of etcd

A) listen-peer-urls

Used for data exchange between nodes, so you need to listen on IP addresses that other nodes can access

The default port is: 2380-7001 (7001 is not recommended, has been basically abandoned, and is mainly used for compatibility with old services)

B) listen-client-urls

The user client accesses etcd data and generally listens locally. If centralized management is needed, it can listen on the IP address that can be accessed by the management server.

The default port is: 2379-4001 (4001 is not recommended, has been basically abandoned, and is mainly used for compatibility with old services)

C) initial-advertise-peer-urls

This parameter represents the address where the node listens for synchronization signals from other nodes.

The default port is: 2380-7001 (7001 is not recommended, has been basically abandoned, and is mainly used for compatibility with old services)

D) advertise-client-urls

After joining the proxy node, the broadcast address is used, so you need to listen on an IP address that the proxy node can access.

The default port is: 2379-4001 (4001 is not recommended, has been basically abandoned, and is mainly used for compatibility with old services)

5. Use 1) create a discovery service configuration information TOKEN=test-1curl-X PUT http://127.0.0.1/v2/keys/discovery/${TOKEN}/_config/size-d value=3

Here, we use test-1 as token, and you can UUID one as token

Note:

Please pay attention to this name in the production environment. I do not recommend using UUID to do token, because the semantics are unknown, it is better to have a name that you can remember, so it is convenient to identify it later.

2) start the etcd service on the three node servers

A) obtain the local IP (for example, I use EC2, so the following shell is sufficient. If the network configuration is more complex, obtain the corresponding external IP according to your own conditions)

IP=$ (hostname-- all-ip-addresses | awk'{print $1}') & & echo $IP

B) start the etcd node on 3 servers

Docker run-- name etcd-d-- log-opt max-size=100m-p 2379 http://0.0.0.0:2379 2379-p 2380 http://0.0.0.0:2379 2380-v / docker/mount/etcd:/etcd funwun.io/etcd:1.4\-name ${IP}\-data-dir / etcd\-snapshot-count=1000\-listen-client-urls http://0.0.0.0:2379\-advertise-client-urls http://${IP}:2379\-listen-peer-urls http:// 0.0.0.0 initial-advertise-peer-urls 2380\-discovery http://${IP}:2380\-discovery http://172.0.0.1/v2/keys/discovery/test-1

C) if the cluster is initialized to 3 nodes, the service must gather 3 nodes before the service can work properly, and the excess part will be started as a proxy node, so on the fourth server, we should start the node as proxy

Docker run-- name etcd-d-- log-opt max-size=100m-- net=host-v / docker/mount/etcd:/etcd funwun.io/etcd:1.4\-name ${IP}\-data-dir / etcd\-snapshot-count=1000\-- proxy on\-listen-client-urls http://0.0.0.0:2379\-discovery http://172.31.16.100/v2/keys/discovery/test-1

Note:

Name must be unique, and etcd uses this to determine nodes. If you use-- initial-cluster, we will also use this name as the node name of the cluster (generally use node IP as the name, you can also use hostname)

Change the discovery address to your discovery service address

The above is the deployment and use of etcd, the basic Docker self-discovery registration service shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report