Spring Cloud--Honghu Cloud Distributed Microservice Cloud System-Eureka (6)

Abstract: Honghu Cloud distributed microservice cloud system-Eureka We do the following construction for the eureka project of Honghu cloud. The whole construction process is very simple. I will record the construction process of each step, hoping to help everyone. 1. Create a maven project named common-eureka, inherit commonservice, and the specific pom.xml configuration file is as follows:

Honghu  Cloud  Distributed Microservice Cloud System -Eureka 

We do the following construction for the eureka project of HongHu cloud. The whole construction process is very simple. I will record every step of the construction process, hoping to help everyone.

1. Create a maven project named common-eureka, inherit commonservice, and the specific pom.xml configuration file is as follows:

<?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">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.ml.honghu</groupId>
        <artifactId>commonservice</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>commonservice-eureka</artifactId>
    <packaging>jar</packaging>
    <name>commonservice-eureka</name>
    <description>commonservice project for Spring Boot</description>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>1</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
    <execution>
    <id>2</id>
    <goals>
    <goal>build-info</goal>
    </goals>
    </execution>
                </executions>
                <configuration>
                    <executable>true</executable>
                </configuration>
                
            </plugin>
        </plugins>
    </build>

 2. Refer to the relevant configuration of eureka at the entry of the startup class, the code is as follows:

package com.ml.honghu; 
import org.springframework.boot.SpringApplication; 
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 
@EnableEurekaServer
@SpringBootApplication public class ServiceApplication{      public static void main(String[] args) { 
        SpringApplication.run(ServiceApplication.class, args); 
    }

3. Configure the application.yml file

# server (eureka default port is: 8761 )
server:   port: 8761 # spring spring:   application: 
    name: commonservice-erueka
# eureka eureka:    client:  
    # Whether to register with eureka
    register-with-eureka: true 
    # Whether to get registration information from eureka
    fetch-registry: false     availability-zones:        honghu: honghuZone     service-url:  
honghuZone: http://honghu:123456@localhost:8761/eureka/       defaultZone: http://honghu:123456@localhost:8761/eureka/   instance: 
    prefer-ip-address: true     hostname: localhost     metadataMap:       zone: honghuZone       user: ${security.user.name} 
      password: {security.user.password}
  # Specify the environment
  environment: dev
  #Specify the data center
  datacenter: honghu
  # Turn off the self-protection mode server:  
    enable -self-preservation: false #Set  
  the interval for cleaning invalid nodes, the default is 60000 , which is 60s
    eviction-interval-timer-in-ms: 60000 
# Service authentication security: basic:  
    enabled: true   user:  
    name: honghu     password: 123456management:   security:
enabled: false 

4. Increase the log mechanism and packaging operation mechanism of the project (we will write in detail later for Linux

Packaging and deployment mechanism under Centos)

5. Since the deployment of the entire project has been completed, run As --> Spring Boot App manually. The running results are as follows: Console running results:

Access the console and log in:

Console running effect:

At the beginning, I will record the construction process and essence of the recently developed spring cloud microservice cloud architecture to help more friends who are interested in developing the spring cloud framework. Let’s discuss the construction process of the spring cloud architecture and how to use it. in corporate projects.

Friends who are willing to understand framework technology or source code directly ask for exchange and sharing technology 1791743380

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325578503&siteId=291194637