Objective
This document records how to build a service registry Eureka, then package it into a Docker image and deploy the Eureka cluster with Docker swarm
1. Environment
Environment |
Version and Description |
Reference Address |
Docker |
V1.13.1,docker is an open Source engine that automates the deployment of developed applications to containers |
Http://www.cnblogs.com/520playbo y/p/7910357.html |
doker-compose |
V1.11,docker One of the official orchestration (Orchestration) projects, responsible for the rapid deployment of distributed in the cluster should |
|
docker swarm |
v1.13.1,docker Engine 1.12 or later built-in swarm (no additional installation) |
http://www.cnblogs.com/520playboy/p/7873903.html |
Docker Registry |
Registry:latest for storage Private warehouse for Docker images |
http://www.cnblogs.com/520playboy/p/7889647.html |
Spring boot |
1 .5.1.RELEASE, is out of the box, provides a series of large projects common non-functional characteristics of the rapid development tool |
Spring Boot official website |
Spring Cloud |
Cam Den sr5,spring Cloud provides developers with a development toolset for operations in distributed systems such as configuration management, service discovery, circuit breakers, intelligent routing, micro-proxies, control buses, one-time tokens, global locks, decision campaigns, distributed sessions, and cluster status |
Spring Cloud official website |
Development tools |
Jdk1.8/intellij idea2016/maven3.3 |
2. Create a parent Empty project Microservice-spring-cloud
3. pom.xml file for parent project
<?xml version="1.0"encoding="UTF-8"? ><project xmlns="http://maven.apache.org/POM/4.0.0"Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <groupId>org.springframework.boot</groupId> <artifactid>spring-boot -starter-parent</artifactid> <version>1.4.2. Release</version> </parent> <modelVersion>4.0.0</modelVersion> <groupId>com.jacky</groupId> <artifactid>microservice-spring-cloud</ Artifactid> <packaging>pom</packaging> <version>1.0-snapshot</version> <modules> <module>microservice-discovery-eureka-ha</module> </ Modules> <properties> <project.build.sourceencoding>utf-8</project.build.sourceEncoding> <project.reporting.outputencoding>utf-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <docker.image.prefix>jacky</docker.image.prefix><!--Configuring the properties of a mirrored warehouse-< ;d ocker.repostory>192.168.6.132: the</docker.repostory><!--Configure the corresponding address and port of the mirrored warehouse--</properties> <dependencyManagement> <de Pendencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>camden.sr3</vers ion> <type>pom</type> <scope>import</scope> </depen dency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <ARTIFACTID>SP Ring-boot-maven-plugin</artifactid> </plugin> </plugins> <!--add build with Maven plugin Plug-ins for Cker mirroring-<pluginManagement> <plugins> <plugin> <groupid>com.sPotify</groupid> <artifactId>docker-maven-plugin</artifactId> < Version>0.4. -</version> </plugin> </plugins> </pluginManagement> </build ></project>
4. Create sub-project Microservice-discovery-eureka-ha
5. pom.xml file of Microservice-discovery-eureka-ha project
<?xml version="1.0"encoding="UTF-8"? ><project xmlns="http://maven.apache.org/POM/4.0.0"Xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> <artifactId>microservice-spring-cloud</artifactId> <groupid>com.jac Ky</groupid> <version>1.0-snapshot</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>microservice-discovery-eureka-ha</artifactId> <packaging>jar </packaging> <properties> <project.build.sourceencoding>utf-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <ARTIFACTID>SPRING-CLOUD-STARTER-EUREKA-SERVER&L t;/artifactid> </dependency> <dependency> <GROUPID>ORG.SPRINGFRAMEWORK.BOOT&L T;/groupid> <artifactId>spring-boot-starter-security</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>com. Spotify</groupid> <artifactId>docker-maven-plugin</artifactId> <executi Ons> <!--setting up mirroring when executing maven install-<execution> <id>build-image</id> <phase>install</phase> <g Oals> <goal>build</goal> </goals> </execution> </executions> <configuration> <!--hosts with Docker installed, and API Remot is turned on E-Interface Settings--<dockerhost>http://192.168.6.130:5678</dockerhost><pushImage>true</pushImage><!--Setting up an upload image to a private warehouse requires Docker settings specify the private warehouse address--<!--mirror name--< Imagename>${docker.repostory}/${docker.image.prefix}/${project.artifactid}:${project.version}</imagename > <!--the base version of the image--<baseimage>java:openjdk-8-jdk-alpine</baseimage> <!--mirroring start parameters--<entrypoint>["Java","-jar","/${project.build.finalname}.jar"]</entrypoint> <resources> <resource> <targetPath>/</targetPath> <directory>${project.build.directory}</direc Tory> <include>${project.build.finalName}.jar</include> & lt;/resource> </resources> </configuration> </plugin> </plugins> </build></project>
5. application.yml file of Microservice-discovery-eureka-ha project
Spring:application:name:EUREKA-HAsecurity:basic:enabled:trueUser:name:jacky password:admin---Server:port:8761Spring:profiles:peer1eureka:instance:hostname:peer1 #Eureka实例的主机名 prefer-ip-address:trueinstance-ID: ${spring.application.name}:${spring.cloud.client.ipaddress}:${spring.application.instance_id:${ Server.port}} client:serviceUrl:defaultZone:http://Jacky:[email protected]:8762/eureka/,Http://jacky: [Email protected]:8763/eureka/#Eureka节点相互注册Register-with-eureka:true---Server:port:8762Spring:profiles:peer2eureka:instance:hostname:peer2 #Eureka实例的主机名 prefer-ip-address:trueinstance-ID: ${spring.application.name}:${spring.cloud.client.ipaddress}:${spring.application.instance_id:${ Server.port}} client:serviceUrl:defaultZone:http://Jacky:[email protected]:8761/eureka/,Http://jacky: [Email protected]:8763/eureka/Register-with-eureka:true---Server:port:8763Spring:profiles:peer3eureka:instance:hostname:peer3 #Eureka实例的主机名 prefer-ip-address:trueinstance-ID: ${spring.application.name}:${spring.cloud.client.ipaddress}:${spring.application.instance_id:${ Server.port}} client:serviceUrl:defaultZone:http://Jacky:[email protected]:8761/eureka/,Http://jacky: [Email protected]:8762/eureka/Register-with-eureka:true
6. Create a Eurekahaapplication.java file
Package Com.jacky.cloud;import Org.springframework.boot.springapplication;import Org.springframework.boot.autoconfigure.springbootapplication;import Org.springframework.cloud.netflix.eureka.server.EnableEurekaServer, @SpringBootApplication @enableeurekaserver Publicclass eurekahaapplication { publicstaticvoid Main (string[] args) { springapplication.run (eurekahaapplication. class , args);} }
7. Create the Docker-compose.yml file in the parent directory
Version"3"services:peer1: # By default, other services can connect to the service using the service name. Therefore, for EUREKASERVICE1 nodes, it requires a connection to http://eurekaservice2/3:951x/eureka/, so the name of the service that needs to be configured is EurekaService1. Image192.168.6.132: the/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT Deploy:replicas:1number of replicas of services that #定义 replicated mode update_config:parallelism:1#每次更新复本数量 delay:2s #每次更新间隔 restart_policy:condition:on-failure #定义服务的重启条件 Networks:-eureka-NET ports:-"8761:8761"Environment:-Spring.profiles.active=peer1 Peer2: # Highly available Eureka Register Node 2 Image:192.168.6.132: the/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT Deploy:replicas:1number of replicas of services that #定义 replicated mode update_config:parallelism:1#每次更新复本数量 delay:2s #每次更新间隔 restart_policy:condition:on-failure #定义服务的重启条件 Networks:-eureka-NET ports:-"8762:8762"Environment:-Spring.profiles.active=peer2 Peer3: # Highly available Eureka Register node 3 Image:192.168.6.132: the/jacky/microservice-discovery-eureka-ha:1.0-SNAPSHOT Deploy:replicas:1number of replicas of services that #定义 replicated mode update_config:parallelism:1#每次更新复本数量 delay:2s #每次更新间隔 restart_policy:condition:on-failure #定义服务的重启条件 Networks:-eureka-NET ports:-"8763:8763"Environment:-Spring.profiles.active=Peer3networks:eureka-Net: #网络名称 driver:overlay
8. Packing
Double-click Install
9. View the image on the 192.168.6.130 machine
Indicates successful upload
10. Upload the Docker-compose.yml file to the owning swarm environment, execute the command as follows
[email protected] docker-compose]# Docker stack deploy-c docker-compose.yml eurekacreating Service eureka_peer2creating Service eureka_peer3creating service Eureka_peer1[[email Protected] Docker-compose]# Docker Stack PS eurekaid NAME IMAGE NODE desired state Current state ERROR portsnjhk2gkh7b6r Eureka_peer1.1 192.168.6.132: the/jacky/microservice-discovery-eureka-ha:1.0-snapshot node3.jacky.com Running Running -seconds ago y5xwabq42zx4 Eureka_peer3.1 192.168.6.132: the/jacky/microservice-discovery-eureka-ha:1.0-snapshot node3.jacky.com Running Running -seconds ago 468xoiu6lv6l eureka_peer2.1 192.168.6.132: the/jacky/microservice-discovery-eureka-ha:1.0-snapshot node2.jacky.com Running Running $Seconds ago
Description Eureka Cluster Deployment succeeded
Description: The Swarm cluster 192.168.6.130;192.168.6.131;192.168.6.132;8761,8762,8763 port can be accessed
Springcloud and Docker-eureka of micro-services (I.)