consul Concept :

consul It's used as a registry He and eureka It's the same Registries generally exist in the form of clusters
Guaranteed high availability consul It's like a nosql Stored key value pairs Can do storage
consul yes c/s Architecturally Its client is responsible for communicating with users There is no practical significance What really works is the back-end server The stored data is also stored on the server side

Environmental Science :

host ip
consul-1 192.168.10.20
consul-2 192.168.10.30
consul-3 192.168.10.40
client client 192.168.10.10

In the first place 、 Two sets consul host And the fourth client Installed on the host jdk and maven Environmental Science
install jdk

[root@localhost ~]# java -version
openjdk version "1.8.0_102"
OpenJDK Runtime Environment (build 1.8.0_102-b14)
OpenJDK 64-Bit Server VM (build 25.102-b14, mixed mode)
[root@localhost ~]# rm -rf /usr/bin/java # Delete... From the original host Java Program
[root@localhost ~]# java -version
-bash: /usr/bin/java: There is no file or directory
[root@localhost ~]# tar -zxf jdk-8u201-linux-x64.tar.gz
[root@localhost ~]# mv jdk1.8.0_201/ /usr/local/java

Add environment variables ( Usually we use the second method )

[root@localhost bin]# vim /etc/profile
# Add... At the end
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
[root@localhost bin]# source /etc/profile
[root@localhost bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/java/bin:/usr/local/java/jre/bin
[root@localhost bin]# java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

install maven

[root@localhost ~]# tar -zxf apache-maven-3.6.0-bin.tar.gz
[root@localhost ~]# mv apache-maven-3.6.0 /usr/local/maven
[root@localhost ~]# vim /etc/profile
export PATH=$PATH:/usr/local/maven/bin
[root@localhost ~]# source /etc/profile
[root@localhost ~]# mvn -v
Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
Maven home: /usr/local/maven
Java version: 1.8.0_201, vendor: Oracle Corporation, runtime: /usr/local/java/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-514.el7.x86_64", arch: "amd64", family: "unix"

install consul service ( All four stations should be installed )

[root@localhost ~]# unzip consul_1.4.0_linux_amd64.zip -d /usr/bin/
Archive: consul_1.4.0_linux_amd64.zip
inflating: /usr/bin/consul
[root@localhost ~]# mkdir -p /opt/consul/{data,config,logs}

Parameter interpretation :
data: The directory where the data is stored
config: The directory where configuration information is stored
logs: Storage log

consul No profile , So it's called clustering to configure it directly through the start command

consul-1

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# consul agent -server -node=consul1 -data-dir /opt/consul/data/ -config-dir /opt/consul/config/ -bind 192.168.10.20 -client 0.0.0.0 -enable-script-checks=true -datacenter=kgc -bootstrap-expect=2

Parameter interpretation :
consul command
agent Start an agent
-server Start as a server
-node=consul1 The name of the current node in the cluster
-data-dir /opt/consul/data/ Directory of data files
-config-dir /opt/consul/config/ Directory of configuration files
-bind 192.168.2.10 Monitoring ip
-client 0.0.0.0 The specified client On behalf of all clients
-enable-script-checks=true Turn on the heartbeat connection
-datacenter=kgc The name of the data center
-bootstrap-expect=2 At least two nodes form a cluster

consul-2

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# consul agent -server -ui -node=consul2 -data-dir /opt/consul/data/ -config-dir /opt/consul/config/ -bind 192.168.10.30 -client 0.0.0.0 -enable-script-checks=true -datacenter=kgc -join 192.168.10.20

Parameter interpretation :
-ui : Graphical interface
-join: To join the cluster

consul-3

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# consul agent -server -ui -node=consul3 -data-dir /opt/consul/data/ -config-dir /opt/consul/config/ -bind 192.168.10.40 -client 0.0.0.0 -enable-script-checks=true -datacenter=kgc -join 192.168.10.20

client client

[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]# consul agent -node=client -data-dir /opt/consul/data/ -config-dir /opt/consul/config/ -bind 192.168.10.10 -client 0.0.0.0 -enable-script-checks=true -datacenter=kgc -join 192.168.10.20

After execution, all hosts will block the terminal , Can be on the first consul Open another terminal on the host computer to check whether the cluster is built successfully

[root@localhost ~]# consul members
Node Address Status Type Build Protocol DC Segment
consul1 192.168.10.20:8301 alive server 1.4.0 2 kgc <all>
consul2 192.168.10.30:8301 alive server 1.4.0 2 kgc <all>
consul3 192.168.10.40:8301 alive server 1.4.0 2 kgc <all>
client 192.168.10.10:8301 alive client 1.4.0 2 kgc <default> [root@localhost ~]# curl http://192.168.10.20:8500/v1/status/leader
"192.168.10.20:8300"
[root@localhost ~]# curl http://192.168.10.20:8500/v1/status/peers
["192.168.10.20:8300","192.168.10.30:8300","192.168.10.40:8300"] [root@localhost ~]# consul info # View the cluster information
agent:
check_monitors = 0
check_ttls = 0
checks = 0
services = 0
build:
prerelease =
revision = 0bddfa23
version = 1.4.0
consul:
acl = disabled
bootstrap = false
known_datacenters = 1
leader = true
leader_addr = 192.168.10.20:8300
server = true
…………………… [root@localhost ~]# curl http://192.168.10.20:8500/v1/catalog/nodes?pretty # See all the nodes , And convert to json Format
[
{
"ID": "e280d23d-58b1-72b4-1c93-5a240f0ee1cd",
"Node": "client",
"Address": "192.168.10.10",
"Datacenter": "kgc",
"TaggedAddresses": {
"lan": "192.168.10.10",
"wan": "192.168.10.10"
},
"Meta": {
"consul-network-segment": ""
},
"CreateIndex": 23,
"ModifyIndex": 24
},
………………

Visit the second one consul-2 Of ip And port ( Because the first one didn't have a graphical interface , Only the second and third have , So here we can go and check it out )

consul The basic order of

nosql Store the data Add data

1、 Create or update data

[root@localhost ~]# consul kv put redis/config/one 1 # Add data to the cluster 
Success! Data written to: redis/config/one
[root@localhost ~]# consul kv get redis/config/one # see
1

2、 Get value

[root@localhost ~]# consul kv get -detailed redis/config/one
CreateIndex 379
Flags 0
Key redis/config/one
LockIndex 0
ModifyIndex 379
Session -
Value 1


3、 Check the details

[root@localhost ~]# consul kv get -detailed redis/config/one
CreateIndex 379
Flags 0
Key redis/config/one
LockIndex 0
ModifyIndex 379
Session -
Value 1

4、 Delete

[root@localhost ~]# consul kv delete redis/config/one # Delete 
Success! Deleted key: redis/config/one
[root@localhost ~]# consul kv get redis/config/one
Error! No key exists at: redis/config/one

5、 Recursive delete

[root@localhost ~]# consul kv put redis/config/one 1
Success! Data written to: redis/config/one
[root@localhost ~]# consul kv put redis/config/two 2
Success! Data written to: redis/config/two
[root@localhost ~]# consul kv delete -recurse redis
Success! Deleted keys with prefix: redis
[root@localhost ~]# consul kv get redis/two
Error! No key exists at: redis/two

6、 Lists the contents of the specified prefix

[root@localhost ~]# consul kv put redis/config/one 1
Success! Data written to: redis/config/one
[root@localhost ~]# consul kv put redis/config/two 2
Success! Data written to: redis/config/two
[root@localhost ~]# consul kv get -keys redis/config/
redis/config/one
redis/config/two

7、 List all the keys

[root@localhost ~]# consul kv get -keys
redis/

consul Function as a registry

consul-1、consul-2、client client
notes : Open another terminal to execute

root@localhost ~]# git clone https://github.com/luojunyong/spring-cloud-examples.git
Is cloning to 'spring-cloud-examples'...
remote: Enumerating objects: 700, done.
remote: Total 700 (delta 0), reused 0 (delta 0), pack-reused 700
In the receiving object : 100% (700/700), 66.07 KiB | 0 bytes/s, done.
Handle delta in : 100% (216/216), done.

consul-1  producer

[root@localhost ~]# cd /root/spring-cloud-examples/spring-cloud-consul/spring-cloud-consul-producer
[root@localhost spring-cloud-consul-producer]# vim src/main/resources/application.properties
3 spring.cloud.consul.host=192.168.10.40 # This is the third one consul-3 Of ip( That is, it is not installed maven The mainframe of the company )
[root@localhost spring-cloud-consul-producer]# source /etc/profile
[root@localhost spring-cloud-consul-producer]# mvn spring-boot:run

consul-2  producer

[root@localhost ~]# cd /root/spring-cloud-examples/spring-cloud-consul/spring-cloud-consul-producer-2/
[root@localhost spring-cloud-consul-producer-2]# vim src/main/resources/application.properties
3 spring.cloud.consul.host=192.168.10.40
[root@localhost spring-cloud-consul-producer-2]# source /etc/profile
[root@localhost spring-cloud-consul-producer-2]# mvn spring-boot:run

client  consumer

[root@localhost ~]# cd /root/spring-cloud-examples/spring-cloud-consul/spring-cloud-consul-consumer/
[root@localhost spring-cloud-consul-consumer]# vim src/main/resources/application.properties
spring.cloud.consul.host=192.168.10.40
[root@localhost spring-cloud-consul-consumer]# source /etc/profile
[root@localhost spring-cloud-consul-consumer]# mvn spring-boot:run

The fourth client Open another terminal to access

[root@localhost ~]# curl 192.168.10.10:8503/call
helle consul
[root@localhost ~]# curl 192.168.10.10:8503/call
helle consul two

Go to the graphical interface again to see the validation

consul What is it? ? More articles about

  1. Consul Service registration and service discovery

    Last one :Mac OS.Ubuntu Installation and use Consul 1. Service registration Yes Consul Before you register for the service , You need to deploy a service site first , We can use ASP.NET Core establish Web Applications ...

  2. Mac OS、Ubuntu Installation and use Consul

    Consul Concept ( excerpts ): Consul yes HashiCorp Open source tools launched by the company , Service discovery and configuration for distributed systems . With other distributed service registration and discovery solutions , such as Airbnb Of SmartStac ...

  3. Use C# and Consul Distributed system coordination

    With the coming of big data Era , Distributed is a major means to solve the problem of big data , With more and more distributed services , How to coordinate these services in a distributed system has become a very difficult problem . Today we'll see how to use C# , Using open source for distributed services ...

  4. Distributed service registration and discovery consul Brief introduction

    Consul yes HashiCorp Open source tools launched by the company , Service discovery and configuration for distributed systems . With other distributed service registration and discovery solutions ,Consul The plan of " "One-stop" work style ", Built in service registration and discovery box frame ...

  5. Chapter two consul Installation and startup of

    Installation environment : mac:64bit( see mac digit : Open the terminal -->"uname -a") consul_0.6.4_darwin_amd64.zip and consul_0.6.4_w ...

  6. application .Net+Consul maintain RabbitMq High availability

    The process of lazy people's learning is to study what the boss asks them to do , On the weekend when I came back from the National Day holiday, my boss assigned me a task through nailing , RabbitMQ Highly available solutions , I want to say the nails are too pitted : This is after the national day 9 On Sunday night, I got off work , I'm on Monday ...

  7. Consul An update for : Reconnection after server node failure

    For some time Consul, I want to write a strategy , But it's too bad and the expression ability is abnormal ... Found today HashiCorp Sure enough, I accepted the opinions of the public and changed something .. Scene is : If Consul There are three in the cluster Server Node when ...

  8. build consul colony

    1.   preparation a)      Start up three virtual machines s1:10.1.7.141 s2:10.1.7.139 s3:10.1.7.138 b)      On every machine /home New folder mkdir ...

  9. Centos 7 Docker、docker-compose、Registrator、Consul、Consul Template and Nginx Achieve highly scalable Web frame

    Install the required software Docker Docker-compose To configure docker-compose.yml The contents of the document are as follows : #load balancer will automatically update th ...

  10. Consul Windows install

    Download the file https://www.consul.io/downloads.html, After decompression, there is only one consul file consul Start a Agent consul agent -server - ...

Random recommendation

  1. look out SQL SERVER 2014 New characteristics &mdash;&mdash; Cardinality evaluation causes some performance problems

    I wrote a blog a while ago "SQL SERVER 2014 Next IF EXITS Share the case that caused the change of execution plan " Database from SQL SERVER 2005 Upgrade to SQL SERVER ...

  2. HDU4871 Shortest-path tree( Shortest path tree + The point divide of the tree )

    The problem is to find the root of a graph with edge weight 1 The shortest path tree of , To satisfy the minimum lexicographic order of the path sequence from root to each point : Then find the shortest path tree that contains k The length and number of the longest path of nodes . First, the shortest path tree with the smallest dictionary order is constructed .. ok , I'm so stupid ...

  3. SSM frame Web Procedure flow (Spring SpringMVC Mybatis)

    SSM Framework of the Web The program mainly uses three techniques : Spring: Annotation and automatic assembly are used , Namely Spring The two quintessence of IOC( Reverse control ) and AOP( Section oriented programming ). SpringMVC: Yes MVC Model , Replace logic with ...

  4. Bootloader brief introduction

    Let's introduce Bootloader, Run on a dedicated embedded development board GNU/Linux Systems have become more and more popular . An embedded Linux From the perspective of software, the system can be divided into four levels : 1. Boot loader . Including curing in firmware ( ...

  5. Kubernetes Log collection

    About kubernetes There are several kinds of logs , in the light of kubernetes In itself, there are three : 1. Resource runtime event event . For example k8s Create... In the cluster pod after , Can pass kubectl describe pod ...

  6. EasyUI Datagrid Mouse over to display cell contents

    The first way : .js Defined function <script type="text/javascript"> // Formatting cell prompts function formatCellTool ...

  7. zoj3961( Interval problem )

    Click on the open zoj1961Let's Chat Time Limit: 1 Second      Memory Limit:65536 KB ACM (ACMers' Chatting Messenge ...

  8. BitnamiRedmine Configure email system notes

    It was installed the other day Redmine There's a problem with the mail system , I need a new one , The method is recorded as follows : Modify the configuration file : cd ~/redmine/apps/redmine/htdocs/config vi configuration ...

  9. M2 Contribution distribution scheme

    1. At the beginning, everyone was 0. 2. Assign tasks every week , Score by task . 3. Every week everyone has 12.5 branch . 4. Finish the task of this week next week 6 branch . 5. Not all tasks of this week have been completed 6 branch . 6.12 month 29 Daily statistics score , The extra points are calculated according to the number of tasks completed ...

  10. java virtual machine launcher Error:Could not create the Java Virtual Machine. Error:A Fatal exception has occurred,Program will exit.

    Error:Could not create the Java Virtual Machine. Error:A Fatal exception has occurred,Program will e ...