CentOS Install ETCD Test

Source: Internet
Author: User
Tags etcd
This is a creation in Article, where the information may have evolved or changed.

1, about ETCD

ETCD is a service discovery tool similar to zookeeper.
Reference Introduction:
http://dockone.io/article/667
Https://coreos.com/blog/performance-of-etcd.html
ETCD Performance Comparison:

2, build the environment

Under Linux: Install the latest 3.1.1

https://github.com/coreos/etcd/releases/download/v3.1.1/etcd-v3.1.1-linux-amd64.tar.gz

Unzip. Start directly.
./ETCD version
./etcd
I am using VirtualBox installed because it is a virtual machine. So a NAT network is used. Remote Access does a port forwarding.

Starting a etcd at the same time requires binding to the IP 10.0.2.15, which is bound to the 127.0.0.1 IP after the default boot.

.--name test-etcd--advertise-client-urls http://10.0.2.15:2379 --listen-client-urls http://10.0.2.15:2379

Do not know why to use two times the command, there is no direct call addr parameters.
ETCD currently uses 2379 port to provide HTTP API service, 2380 port and peer communication.

3, using a Java Client connection

Https://github.com/coreos/jetcd
Download Lib library. Rely on Google's grpc,protobuf.
Maven downloads are slow and can use Ali's image.

Java code:

Importcom. CoreOS. Jetcd. Etcdclient;Importcom. CoreOS. Jetcd. Etcdclientbuilder;Importcom. CoreOS. Jetcd. ETCDKV;Importcom. CoreOS. Jetcd. API. KeyValue;Importcom. CoreOS. Jetcd. API. Rangeresponse;Importcom. CoreOS. Jetcd. Exception. Authfailedexception;Importcom. CoreOS. Jetcd. Exception. Connectexception;Importcom. Google. Common. Util. Concurrent. Listenablefuture;Importcom. Google. Protobuf. ByteString;Import Java. IO. Unsupportedencodingexception;Import Java. Util. List;Import Java. Util. Concurrent. Executionexception;/** */public class Testjetcd {public static void main (string[] args) throws Executionexception, Interruptedexception, Unsupp Ortedencodingexception, Authfailedexception, connectexception {etcdclient client = Etcdclientbuilder. Newbuilder(). Endpoints("http://localhost:2379"). Build();ETCDKV kvclient = Client. Getkvclient();System. out. println(kvclient);ByteString key = ByteString. CopyFrom("Test_key","UTF-8");ByteString value = ByteString. CopyFrom("Test_value","UTF-8");System. out. println(kvclient. Get(key). Get());Put the Key-value kvclient. Put(Key, value). Get();list<keyvalue> list = Kvclient. Get(key). Get(). Getkvslist();Cycle through all the data. for (KeyValue keyvalue:list) {//Convert to utf-8Project. String Tmpkey = KeyValue. GetKey(). Tostringutf8 ();System. out. println("key:"+ Tmpkey);String Tmpval = KeyValue. GetValue(). Tostringutf8 ();System. out. println("Value:"+ tmpval);System. out. println("version:"+ KeyValue. GetVersion());}//Delete the key//kvclient. Delete(key). Get();}}

4, error

ExceptioninchThread"Main"Java. Util. Concurrent. Executionexception: IO. Grpc. Statusruntimeexception: Unavailable atcom. Google. Common. Util. Concurrent. Abstractfuture. Getdonevalue(abstractfuture. Java:476) atcom. Google. Common. Util. Concurrent. Abstractfuture. Get(abstractfuture. Java:455)

Sometimes the error is like this. You have to check that the ETCD service is started.
See if the port on the VirtualBox is not through.
Or you can access it directly using HTTP.
Http://127.0.0.1:2379/version

is an HTTP call.
Other command references:
Http://cizixs.com/2016/08/02/intro-to-etcd
This guy is pretty full.

5, summary

The text of this text connection is: Http://blog.csdn.net/freewebsys/article/details/56276386 not allowed to reprint without the Bo master.
Bo main address is: Http://blog.csdn.net/freewebsys

The performance of the ETCD is still very powerful.
The Java client uses GRPC for communication.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.