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

Distributed key High availability Storage Cluster Architecture (ETCD)

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

Share

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

ETCD is a highly available distributed key value database that can be used for service discovery. ETCD adopts raft consistency algorithm and is implemented based on Go language. With the increasing popularity of projects such as CoreOS and Kubernetes in the open source community, etcd components used in their projects are gradually concerned by developers as a highly available and highly consistent service discovery repository. In the era of cloud computing, how to quickly and transparently access services to the computing cluster, how to make shared configuration information quickly discovered by all machines in the cluster, and more importantly, how to build such a set of highly available, secure, easy to deploy and fast response service cluster has become an urgent problem to be solved. Etcd brings good news for solving this kind of problems. This article will start from the application scenario of etcd, in-depth interpretation of the implementation of etcd, for developers to more fully enjoy the convenience brought by etcd.

Characteristics

Simple: easy to install and configure, provide HTTP API

Security: support for SSL certificates

Reliable: using raft algorithm to realize the availability and consistency of distributed system data

Download the installation package:

[root@master ~] # wget https://github.com/coreos/etcd/releases/download/v3.3.2/etcd-v3.3.2-linux-amd64.tar.gz

Copy the installation package to each pin:

[root@master] # ansible k8s-m copy-a'src=/root/etcd-v3.3.2-linux-amd64.tar.gz dest=/root/'

Three machines in the deployment environment: IP-- hostname-cluster node name

192.168.27.211 client1 (etcd1)

192.168.27.212 client2 (etcd2)

192.168.27.213 client3 (etcd3)

Extract the version package

Tar-zxvf etcd-v3.3.2-linux-amd64.tar.gz or [root@master ~] # ansible k8s-m shell-a'tar-zxf etcd-v3.3.2-linux-amd64.tar.gz'

Rename and move the extracted file to the / etc/ directory

Mv etcd-v3.3.2-linux-amd64 / etc/etcd-v3.3.2 or

[root@master] # ansible k8s-m shell-a'mv etcd-v3.3.2-linux-amd64 / etc/etcd-v3.3.2'

Add etcd and etcdctl to the system variable PATH (can be omitted)

[root@master] # ansible k8s-m shell-a'echo export PATH=/etc/etcd-v3.3.2:$PATH > > ~ / .bashrc'

[root@master] # ansible k8s-m shell-a'source ~ / .bashrc'

[root@master] # ansible k8s-m shell-a'source / root/.bashrc'# is more popular

4. Enter / etc/etcd-v3.3.2 and create a configuration file etcd.conf with the following contents:

Name: etcd1

Data-dir: / etc/etcd-v3.3.2/data

Listen-client-urls: http://0.0.0.0:2379

Advertise-client-urls: http://192.168.27.211:2379

Listen-peer-urls: http://0.0.0.0:2380

Initial-advertise-peer-urls: http://192.168.27.211:2380

Initial-cluster: etcd1= http://192.168.27.211:2380,etcd2=http://192.168.27.212:2380,etcd3=http://192.168.27.213:2380

Initial-cluster-token: etcd-cluster-my

Initial-cluster-state: new

5. Set the etcd version number. The default is 2. The version we installed is 3.3.2, so it is set to 3 here.

Add a line to the file ~ / .bashrc and change it to 3

Export ETCDCTL_API=3

Set boot up, create a new file / usr/lib/systemd/system/etcd.service, and set it to facilitate the management of configuration content:

[root@client1 etcd-v3.3.2] # cat / usr/lib/systemd/system/etcd.service

[Unit]

Description=Etcd Server

After=network.target

After=network-online.target

Wants=network-online.target

[Service]

Type=notify

WorkingDirectory=/etc/etcd-v3.3.2

# User=etcd

ExecStart=/etc/etcd-v3.3.2/etcd-config-file / etc/etcd-v3.3.2/etcd.conf

Restart=on-failure

LimitNOFILE=65536

[Install]

WantedBy=multi-user.target

Start etcd, and when you start the first member, the member waits for the other member to be initialized and is in the watting state, and then start the second one immediately

Systemctl daemon-reload

Systemctl enable etcd

Systemctl start etcd

Systemctl restart etcd

Note: 192.168.27.212192.168.27.213 deployment is like the above step, you only need to change the dot name and ip in step 4 to your own ip.

Name: etcd2

Data-dir: / etc/etcd-v3.3.2/data

Listen-client-urls: http://0.0.0.0:2379

Advertise-client-urls: http://192.168.27.212:2379

Listen-peer-urls: http://0.0.0.0:2380

Initial-advertise-peer-urls: http://192.168.27.212:2380

Initial-cluster: etcd1= http://192.168.27.211:2380,etcd2=http://192.168.27.212:2380,etcd3=http://192.168.27.213:2380

Initial-cluster-token: etcd-cluster-my

Initial-cluster-state: new

Name: etcd3

Data-dir: / etc/etcd-v3.3.2/data

Listen-client-urls: http://0.0.0.0:2379

Advertise-client-urls: http://192.168.27.213:2379

Listen-peer-urls: http://0.0.0.0:2380

Initial-advertise-peer-urls: http://192.168.27.213:2380

Initial-cluster: etcd1= http://192.168.27.211:2380,etcd2=http://192.168.27.212:2380,etcd3=http://192.168.27.213:2380

Initial-cluster-token: etcd-cluster-my

Initial-cluster-state: new

6. Check the members and status of the cluster after starting successfully:

[root@client3 etcd-v3.3.2] # etcdctl member list

Etcdctl endpoint health-endpoints=192.168.27.211:2379192.168.27.212:2379192.168.27.213:2379

[root@client3 etcd-v3.3.2] # etcdctl endpoint status-- endpoints=192.168.27.211:2379192.168.27.212:2379192.168.27.213:2379

[root@client3 etcd-v3.3.2] # etcdctl endpoint status-- endpoints=192.168.27.211:2379

Access the test through non-ETCD cluster members:

[root@master etcd-v3.3.2] # etcdctl endpoint status-- endpoints=192.168.27.211:2379

192.168.27.211:2379, f4e909b85dbd820b, 3.3.2, 25 kB, false, 69, 71

[root@master etcd-v3.3.2] # etcdctl endpoint status-- endpoints=192.168.27.211:2379

192.168.27.211:2379, f4e909b85dbd820b, 3.3.2, 25 kB, false, 69, 71

[root@master etcd-v3.3.2] # etcdctl endpoint status-- endpoints=192.168.27.211:2379192.168.27.212:2379192.168.27.213:2379

192.168.27.211:2379, f4e909b85dbd820b, 3.3.2, 25 kB, false, 69, 71

192.168.27.212:2379, 265ebeb3298fa51f, 3.3.2, 25 kB, false, 69, 71

192.168.27.213:2379, 510ff85ed64c7436, 3.3.2, 25 kB, true, 69, 71

[root@master etcd-v3.3.2] # etcdctl put name jerry-- endpoints=192.168.27.211:2379192.168.27.212:2379192.168.27.213:2379

OK

[root@master etcd-v3.3.2] # etcdctl put topic "this is an etcd client test"-- endpoints=192.168.27.211:2379192.168.27.212:2379192.168.27.213:2379

OK

[root@master etcd-v3.3.2] # etcdctl get topic-- endpoints=192.168.27.211:2379192.168.27.212:2379192.168.27.213:2379

Topic

This is an etcd client test

[root@master etcd-v3.3.2] # etcdctl get topic-- endpoints=192.168.27.211:2379

Topic

This is an etcd client test

Etcd uses:

Read-write key value:

[root@client1 etcd-v3.3.2] # etcdctl put key1 value1

OK

[root@client1 etcd-v3.3.2] # etcdctl get key1

Key1

Value1

Prefix read (read out all key-value pairs whose prefix is key)

Key value deletion:

[root@client1 etcd-v3.3.2] # etcdctl del key

0

[root@client1 etcd-v3.3.2] # etcdctl get key

[root@client1 etcd-v3.3.2] # etcdctl get key1

Key1

Value1

[root@client1 etcd-v3.3.2] # etcdctl del key1

one

[root@client1 etcd-v3.3.2] # etcdctl get key1

Observe that there is no KEY1 key and value.

Delete all by prefix

Observe no key values and data

Recreate three key values:

Access key value test on other ETCD cluster members:

Monitor a key, each time the key value changes

[root@client1 etcd-v3.3.2] # etcdctl watch key-- prefix

PUT

Key1

Value

PUT

Key2

Jerry

Set expiration time TTL

[root@client2 etcd-v3.3.2] # etcdctl lease grant 30

Lease 251f6cf538287411 granted with TTL (30s)

[root@client2 etcd-v3.3.2] # etcdctl put key5 value5-- lease=251f6cf538287411

Error: etcdserver: requested lease not found

[root@client2 etcd-v3.3.2] # etcdctl lease grant 30

Lease 251f6cf538287414 granted with TTL (30s)

[root@client2 etcd-v3.3.2] # etcdctl put key5 value5-- lease=251f6cf538287414

OK

[root@client2 etcd-v3.3.2] # etcdctl lease keep-alive 251f6cf538287414

Lease 251f6cf538287414 expired or revoked.

[root@client2 etcd-v3.3.2] # etcdctl get key5

[root@client2 etcd-v3.3.2] # etcdctl get key5

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