提交 6b24c2e7 编写于 作者: M ManongJu

集成Nacos

上级 66c00765
target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
nbproject/private/
build/
nbbuild/
dist/
nbdist/
.nb-gradle/
\ No newline at end of file
java -jar .\target\Micro-Service-Skeleton-Register-0.0.1-SNAPSHOT.jar --spring.profiles.active=node-1
\ No newline at end of file
java -jar .\target\Micro-Service-Skeleton-Register-0.0.1-SNAPSHOT.jar --spring.profiles.active=node-2
\ No newline at end of file
@echo on
mvn clean -e -U package -Dmaven.test.skip=true
\ No newline at end of file
<?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.microservice.skeleton</groupId>
<artifactId>Micro-Service-Skeleton-Parent</artifactId>
<version>2.0.0</version>
</parent>
<artifactId>Micro-Service-Skeleton-Register</artifactId>
<version>2.0.0</version>
<packaging>jar</packaging>
<name>mss-eureka</name>
<description>Demo project for Spring Boot</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</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>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
FROM frolvlad/alpine-oraclejdk8:slim
VOLUME /tmp
ADD Micro-Service-Skeleton-Register.jar Micro-Service-Skeleton-Register.jar
RUN sh -c 'touch /Micro-Service-Skeleton-Register.jar'
ENTRYPOINT ["sh", "-c" , "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /Micro-Service-Skeleton-Register.jar" ]
\ No newline at end of file
package com.microservice.skeleton.register;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
@EnableEurekaServer
public class RegisterApplication {
public static void main(String[] args) {
SpringApplication.run(RegisterApplication.class, args);
}
}
package com.microservice.skeleton.register.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceCanceledEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
/**
* Created by Mr.Yangxiufeng on 2017/12/9.
* Time:13:45
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
@Slf4j
public class InstanceCancelListener implements ApplicationListener<EurekaInstanceCanceledEvent> {
@Override
public void onApplicationEvent(@NonNull EurekaInstanceCanceledEvent event) {
log.info("服务:{}挂了",event.getAppName());
}
}
package com.microservice.skeleton.register.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRegisteredEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.lang.NonNull;
/**
* Created by Mr.Yangxiufeng on 2017/12/9.
* Time:13:37
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
@Slf4j
public class InstanceRegisterListener implements ApplicationListener<EurekaInstanceRegisteredEvent>{
@Override
public void onApplicationEvent(@NonNull EurekaInstanceRegisteredEvent eurekaInstanceRegisteredEvent) {
log.info("服务:{},注册成功了",eurekaInstanceRegisteredEvent.getInstanceInfo().getAppName());
}
}
package com.microservice.skeleton.register.listener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.netflix.eureka.server.event.EurekaInstanceRenewedEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
/**
* Created by Mr.Yangxiufeng on 2017/12/9.
* Time:13:48
* ProjectName:Mirco-Service-Skeleton
*/
@Configuration
@Slf4j
public class InstanceRenewListener implements ApplicationListener<EurekaInstanceRenewedEvent> {
@Override
public void onApplicationEvent(EurekaInstanceRenewedEvent event) {
log.info("心跳检测服务:{}" ,event.getInstanceInfo().getAppName());
}
}
server:
port: 9010
spring:
application:
##name必须一样,不然高可用会导致unavailable-replicas
name: mss-eureka
eureka:
instance:
hostname: mss-eureka1
client:
##这里要覆盖application的设置,不然会读取application文件导致unavailable-replicas
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://mss-eureka2:9011/eureka/
\ No newline at end of file
server:
port: 9011
spring:
application:
name: mss-eureka
eureka:
instance:
hostname: mss-eureka2
client:
##这里要覆盖application的设置,不然会读取application文件导致unavailable-replicas
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://mss-eureka1:9010/eureka/
\ No newline at end of file
server:
port: 9010
spring:
application:
name: mss-eureka
jackson:
date-format: yyyy-MM-dd HH:mm:ss
joda-date-time-format: yyyy-MM-dd HH:mm:ss
locale: zh_CN
time-zone: GMT+8
eureka:
instance:
hostname: mss-eureka
client:
register-with-eureka: false
fetch-registry: false
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
server:
#### 清理间隔(单位毫秒,默认是60*1000),开发环境设置如下可快速移除不可用的服务
eviction-interval-timer-in-ms: 5000
enable-self-preservation: false
\ No newline at end of file
<configuration>
<property name="PATTERN" value="%d{yyyy-MM-dd HH:mm:ss} %-5level [%thread%X{sourceThread}]%logger{24} - %msg%n"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{MM/dd/yyyy HH:mm:ss} %-5level [%thread%X{sourceThread}]%logger{24} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/export/logs/Micro-Service-Skeleton/register-center/log.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/export/logs/Micro-Service-Skeleton/register-center/log.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{MM/dd/yyyy HH:mm:ss} %-5level ${version} [%thread]%logger{16} - %msg%n
</pattern>
</encoder>
</appender>
<appender name="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<File>/export/logs/Micro-Service-Skeleton/register-center/error.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/export/logs/Micro-Service-Skeleton/register-center/error-%d{yyyyMMdd}.log.%i
</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>500MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>2</maxHistory>
</rollingPolicy>
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%msg%n
</Pattern>
</layout>
</appender>
<appender name="SQL" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/export/logs/Micro-Service-Skeleton/register-center/sql.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>/export/logs/Micro-Service-Skeleton/register-center/sql.%d{yyyy-MM-dd}.log.gz</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>%d{MM/dd/yyyy HH:mm:ss} %-5level ${version} [%thread]%logger{16} - %msg%n
</pattern>
</encoder>
</appender>
<logger name="org.springframework.jdbc.core.JdbcTemplate" level="debug">
<appender-ref ref="SQL"/>
</logger>
<logger name="org.springframework.web.servlet.mvc" level="info"/>
<root level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
<appender-ref ref="ERROR_FILE"/>
<appender-ref ref="SQL"/>
</root>
</configuration>
package com.microservice.skeleton.register;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
public class RegisterApplicationTests {
@Test
public void contextLoads() {
}
}
......@@ -18,7 +18,11 @@
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
......
spring:
application:
name: mss-gateway
server:
port: 9030
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
client:
service-url:
defaultZone: http://mss-eureka1:9010/eureka/,http://mss-eureka2:9011/eureka/
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
loadbalancer:
retry:
enabled: true
zuul:
host:
connect-timeout-millis: 10000
......
server:
port: 9030
spring:
application:
name: mss-gateway
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
......@@ -16,16 +16,15 @@
<description>Demo project for Spring Boot</description>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
......@@ -36,25 +35,12 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-turbine</artifactId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.cloud</groupId>-->
<!--<artifactId>spring-cloud-sleuth-zipkin-stream</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>io.zipkin.java</groupId>-->
<!--<artifactId>zipkin-server</artifactId>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>io.zipkin.java</groupId>-->
<!--<artifactId>zipkin-autoconfigure-ui</artifactId>-->
<!--<scope>runtime</scope>-->
<!--</dependency>-->
</dependencies>
<build>
<plugins>
......
......@@ -3,15 +3,9 @@ package com.microservice.skeleton.monitor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.turbine.EnableTurbine;
import zipkin.server.EnableZipkinServer;
@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrixDashboard
@EnableTurbine
@EnableZipkinServer
public class MonitorApplication {
public static void main(String[] args) {
......
server:
port: 9050
spring:
application:
name: micro-service-monitor
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 10
client:
service-url:
defaultZone: http://mss-eureka1:9010/eureka/,http://mss-eureka2:9011/eureka/
endpoints:
health:
sensitive: false
enabled: true
management:
security:
enabled: false
turbine:
app-config-list: micro-a-service
cluster-name-expression: "'default'"
\ No newline at end of file
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
\ No newline at end of file
spring:
application:
name: micro-service-monitor
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
......@@ -27,7 +27,11 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
......
server:
port: 9060
spring:
application:
name: uaa
jpa:
show-sql: true
datasource:
......@@ -16,17 +13,11 @@ spring:
host: 127.0.0.1
port: 6379
password: 123456
eureka:
instance:
prefer-ip-address: true
instance-id: ${spring.cloud.client.ip-address}:${server.port}
##续约更新时间间隔设置5秒,m默认30s
lease-renewal-interval-in-seconds: 5
##续约到期时间10秒,默认是90秒
lease-expiration-duration-in-seconds: 10
client:
service-url:
defaultZone: http://mss-eureka1:9010/eureka/
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
logging:
config: classpath:logback.xml
level:
......
spring:
application:
name: uaa
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
......@@ -26,7 +26,11 @@
<!--注册中心-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.microservice.skeleton.common</groupId>
......
server:
port: 9021
spring:
application:
name: mss-upms
datasource:
url: jdbc:mysql://localhost:3306/zuul-auth?useUnicode=true&characterEncoding=utf-8
username: root
password: 123456
druid:
driver-class-name: com.mysql.jdbc.Driver
eureka:
instance:
prefer-ip-address: true #使用IP注册
instance-id: ${spring.cloud.client.ip-address}:${server.port}
##续约更新时间间隔设置5秒,m默认30s
lease-renewal-interval-in-seconds: 5
##续约到期时间10秒,默认是90秒
lease-expiration-duration-in-seconds: 10
client:
service-url:
defaultZone: http://mss-eureka1:9010/eureka/,http://mss-eureka2:9011/eureka/
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
mybatis:
mapper-locations: classpath:mapper/*.xml
\ No newline at end of file
spring:
application:
name: mss-upms
cloud:
nacos:
config:
server-addr: 127.0.0.1:8848
......@@ -34,7 +34,6 @@
</parent>
<modules>
<module>mss-common</module>
<module>mss-eureka</module>
<module>mss-oauth</module>
<module>mss-gateway</module>
<module>mss-monitor</module>
......@@ -83,6 +82,13 @@
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger2.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
<version>0.2.1.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册