⚡ 集成nacos
This commit is contained in:
parent
18c5ed1001
commit
9e6273810c
|
|
@ -1,12 +1,2 @@
|
|||
server:
|
||||
port: 8100
|
||||
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
label: master
|
||||
profile: ${blade.env}
|
||||
fail-fast: true
|
||||
discovery:
|
||||
enabled: true
|
||||
service-id: blade-config-server
|
||||
|
|
|
|||
|
|
@ -20,6 +20,12 @@
|
|||
<artifactId>blade-core-launch</artifactId>
|
||||
<version>${blade.tool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.dreamlu</groupId>
|
||||
<artifactId>mica-auto</artifactId>
|
||||
<version>${mica.auto.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -8,19 +8,14 @@ package org.springblade.common.constant;
|
|||
public interface CommonConstant {
|
||||
|
||||
/**
|
||||
* consul dev 地址
|
||||
* nacos dev 地址
|
||||
*/
|
||||
String CONSUL_DEV_HOST = "http://localhost";
|
||||
String NACOS_DEV_ADDR = "127.0.0.1:8848";
|
||||
|
||||
/**
|
||||
* consul prod 地址
|
||||
* nacos prod 地址
|
||||
*/
|
||||
String CONSUL_PROD_HOST = "http://192.168.186.129";
|
||||
|
||||
/**
|
||||
* consul端口
|
||||
*/
|
||||
String CONSUL_PORT = "8500";
|
||||
String NACOS_PROD_ADDR = "192.168.186.129:8848";
|
||||
|
||||
/**
|
||||
* 顶级父节点id
|
||||
|
|
@ -37,4 +32,5 @@ public interface CommonConstant {
|
|||
* 默认密码
|
||||
*/
|
||||
String DEFAULT_PASSWORD = "123456";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,8 +32,8 @@ public class LauncherServiceImpl implements LauncherService {
|
|||
@Override
|
||||
public void launcher(SpringApplicationBuilder builder, String appName, String profile) {
|
||||
Properties props = System.getProperties();
|
||||
props.setProperty("spring.cloud.consul.host", profile.equals(AppConstant.DEV_CDOE) ? CommonConstant.CONSUL_DEV_HOST : CommonConstant.CONSUL_PROD_HOST);
|
||||
props.setProperty("spring.cloud.consul.port", CommonConstant.CONSUL_PORT);
|
||||
props.setProperty("spring.cloud.nacos.discovery.server-addr", profile.equals(AppConstant.DEV_CDOE) ? CommonConstant.NACOS_DEV_ADDR : CommonConstant.NACOS_PROD_ADDR);
|
||||
props.setProperty("spring.cloud.nacos.config.server-addr", profile.equals(AppConstant.DEV_CDOE) ? CommonConstant.NACOS_DEV_ADDR : CommonConstant.NACOS_PROD_ADDR);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,15 +66,15 @@
|
|||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!--Config-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
<!--Discovery-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-consul-discovery</artifactId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
|
||||
<version>${nacos.version}</version>
|
||||
</dependency>
|
||||
<!--Swagger-->
|
||||
<dependency>
|
||||
|
|
|
|||
|
|
@ -15,15 +15,11 @@
|
|||
*/
|
||||
package org.springblade.gateway.controller;
|
||||
|
||||
import com.ecwid.consul.v1.ConsulClient;
|
||||
import com.ecwid.consul.v1.health.model.Check;
|
||||
import com.ecwid.consul.v1.health.model.HealthService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.client.ServiceInstance;
|
||||
import org.springframework.cloud.client.discovery.DiscoveryClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
|
@ -44,8 +40,6 @@ public class DiscoveryClientController {
|
|||
|
||||
private final DiscoveryClient discoveryClient;
|
||||
|
||||
private final ConsulClient consulClient;
|
||||
|
||||
/**
|
||||
* 获取服务实例
|
||||
*/
|
||||
|
|
@ -60,46 +54,4 @@ public class DiscoveryClientController {
|
|||
return instances;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定无效服务
|
||||
*
|
||||
* @param serviceName 服务名
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/deRegister/{serviceName}")
|
||||
public String deRegister(@PathVariable String serviceName) {
|
||||
serviceDeregister(serviceName);
|
||||
return "服务删除成功";
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除所有无效服务
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/deRegisterAll")
|
||||
public String deRegisterAll() {
|
||||
consulClient.getAgentChecks().getValue().forEach((k, v) -> serviceDeregister(v.getServiceName()));
|
||||
return "服务删除成功";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据serviceName删除无效服务
|
||||
*
|
||||
* @param serviceName
|
||||
*/
|
||||
public void serviceDeregister(String serviceName) {
|
||||
List<HealthService> response = consulClient.getHealthServices(serviceName, false, null).getValue();
|
||||
for (HealthService service : response) {
|
||||
// 创建一个用来剔除无效实例的ConsulClient,连接到无效实例注册的agent
|
||||
ConsulClient clearClient = new ConsulClient(service.getNode().getAddress());
|
||||
service.getChecks().forEach(check -> {
|
||||
if (check.getStatus() != Check.CheckStatus.PASSING) {
|
||||
log.info("deregister : {}", check.getServiceId());
|
||||
clearClient.agentServiceDeregister(check.getServiceId());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,13 +10,6 @@ blade:
|
|||
|
||||
spring:
|
||||
cloud:
|
||||
config:
|
||||
label: master
|
||||
profile: ${blade.env}
|
||||
fail-fast: true
|
||||
discovery:
|
||||
enabled: true
|
||||
service-id: blade-config-server
|
||||
gateway:
|
||||
routes:
|
||||
# 认证中心
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@
|
|||
package org.springblade.admin;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
import org.springblade.core.launch.BladeApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
import org.springframework.cloud.client.SpringCloudApplication;
|
||||
|
||||
/**
|
||||
* admin启动器
|
||||
|
|
@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
* @author Chill
|
||||
*/
|
||||
@EnableAdminServer
|
||||
@SpringBootApplication
|
||||
@SpringCloudApplication
|
||||
public class BladeAdminApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
|
|
|||
|
|
@ -11,20 +11,7 @@ server:
|
|||
direct-buffers: true
|
||||
|
||||
spring:
|
||||
cloud:
|
||||
zookeeper:
|
||||
discovery:
|
||||
register: false
|
||||
boot:
|
||||
admin:
|
||||
discovery:
|
||||
ignored-services: consul
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: "*"
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
FROM anapsix/alpine-java:8_server-jre_unlimited
|
||||
|
||||
MAINTAINER smallchill@163.com
|
||||
|
||||
RUN mkdir -p /blade/config
|
||||
|
||||
WORKDIR /blade/config
|
||||
|
||||
EXPOSE 7005
|
||||
|
||||
ADD ./target/blade-config-server.jar ./app.jar
|
||||
|
||||
ENTRYPOINT ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "app.jar"]
|
||||
|
||||
CMD ["--spring.profiles.active=test"]
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
# bladex-config
|
||||
|
||||
##bladex配置文件仓库部署步骤
|
||||
|
||||
1.建好git仓库,并建好文件夹,如:respo
|
||||
|
||||
2.将/config下的文件放到respo文件夹下,并push到git
|
||||
|
||||
3.到/resources/bootstrap.yml文件,修改spring.cloud.config.git节点下对应的配置
|
||||
|
||||
4.启动工程,开启config-server服务
|
||||
|
||||
##访问请求
|
||||
|
||||
在浏览器里输入:http://localhost:7005/application/dev/master
|
||||
或 http://localhost:7005/application-dev.yml
|
||||
或 http://localhost:7005/application-dev.properties
|
||||
|
||||
证明配置服务中心可以从远程程序获取配置信息,http请求地址和资源文件映射如下:
|
||||
· /{application}/{profile}/{label}
|
||||
· /{application}-{profile}.yml
|
||||
· /{label}/{application}-{profile}.yml
|
||||
· /{application}-{profile}.properties
|
||||
· /{label}/{application}-{profile}.properties
|
||||
|
|
@ -1,66 +0,0 @@
|
|||
<?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>blade-ops</artifactId>
|
||||
<groupId>org.springblade</groupId>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>blade-config-server</artifactId>
|
||||
<name>${project.artifactId}</name>
|
||||
<version>${blade.project.version}</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<!--Blade-->
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-common</artifactId>
|
||||
<version>${blade.project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-launch</artifactId>
|
||||
<version>${blade.tool.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springblade</groupId>
|
||||
<artifactId>blade-core-cloud</artifactId>
|
||||
<version>${blade.tool.version}</version>
|
||||
</dependency>
|
||||
<!--Config-Server-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-config-server</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>com.spotify</groupId>
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
<version>${docker.plugin.version}</version>
|
||||
<configuration>
|
||||
<imageName>${docker.registry.url}/blade/${project.artifactId}:${project.version}</imageName>
|
||||
<dockerDirectory>${project.basedir}</dockerDirectory>
|
||||
<dockerHost>${docker.registry.host}</dockerHost>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>/</targetPath>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<include>${project.build.finalName}.jar</include>
|
||||
</resource>
|
||||
</resources>
|
||||
<registryUrl>${docker.registry.url}</registryUrl>
|
||||
<serverId>${docker.registry.url}</serverId>
|
||||
<pushImage>true</pushImage>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) 2018-2028, Chill Zhuang 庄骞 (smallchill@163.com).
|
||||
* <p>
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* <p>
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* <p>
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springblade.config;
|
||||
|
||||
import org.springblade.core.launch.constant.AppConstant;
|
||||
import org.springblade.core.launch.BladeApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.config.server.EnableConfigServer;
|
||||
|
||||
/**
|
||||
* 服务中心启动器
|
||||
*
|
||||
* @author Chill
|
||||
*/
|
||||
@EnableConfigServer
|
||||
@SpringBootApplication
|
||||
public class BladeConfigApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
BladeApplication.run(AppConstant.APPLICATION_CONFIG_NAME, BladeConfigApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
${AnsiColor.BRIGHT_CYAN} _____ _ ${AnsiColor.BLUE} ______ _ _
|
||||
${AnsiColor.BRIGHT_CYAN}/ ___| (_) ${AnsiColor.BLUE} | ___ \| | | |
|
||||
${AnsiColor.BRIGHT_CYAN}\ `--. _ __ _ __ _ _ __ __ _ ${AnsiColor.BLUE} | |_/ /| | __ _ __| | ___
|
||||
${AnsiColor.BRIGHT_CYAN} `--. \| '_ \ | '__|| || '_ \ / _` | ${AnsiColor.BLUE} | ___ \| | / _` | / _` | / _ \
|
||||
${AnsiColor.BRIGHT_CYAN}/\__/ /| |_) || | | || | | || (_| | ${AnsiColor.BLUE} | |_/ /| || (_| || (_| || __/
|
||||
${AnsiColor.BRIGHT_CYAN}\____/ | .__/ |_| |_||_| |_| \__, | ${AnsiColor.BLUE} \____/ |_| \__,_| \__,_| \___|
|
||||
${AnsiColor.BRIGHT_CYAN} | | __/ |
|
||||
${AnsiColor.BRIGHT_CYAN} |_| |___/
|
||||
|
||||
${AnsiColor.BLUE}:: SpringBlade :: ${spring.application.name}:${AnsiColor.RED}${blade.env}${AnsiColor.BLUE} :: Running SpringBoot ${spring-boot.version} :: ${AnsiColor.BRIGHT_BLACK}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
server:
|
||||
port: 7005
|
||||
undertow:
|
||||
# 设置IO线程数, 它主要执行非阻塞的任务,它们会负责多个连接, 默认设置每个CPU核心一个线程
|
||||
io-threads: 4
|
||||
# 阻塞任务线程池, 当执行类似servlet请求阻塞操作, undertow会从这个线程池中取得线程,它的值设置取决于系统的负载
|
||||
worker-threads: 20
|
||||
# 以下的配置会影响buffer,这些buffer会用于服务器连接的IO操作,有点类似netty的池化内存管理
|
||||
buffer-size: 1024
|
||||
# 是否分配的直接内存
|
||||
direct-buffers: true
|
||||
|
||||
spring:
|
||||
# 配置中心
|
||||
cloud:
|
||||
#config:
|
||||
# server:
|
||||
# native:
|
||||
# search-locations: classpath:/config/
|
||||
config:
|
||||
server:
|
||||
git:
|
||||
uri: https://gitee.com/smallc/bladex-config
|
||||
search-paths: respo
|
||||
default-label: master
|
||||
#username: username
|
||||
#password: password
|
||||
loadbalancer:
|
||||
retry:
|
||||
enabled: true
|
||||
devtools:
|
||||
restart:
|
||||
log-condition-evaluation-delta: false
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: "*"
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
blade:
|
||||
modules:
|
||||
id: 1
|
||||
name: dashboard-dev
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
blade:
|
||||
modules:
|
||||
id: 1
|
||||
name: dashboard-prod
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
blade:
|
||||
modules:
|
||||
id: 3
|
||||
name: dashboard-test
|
||||
|
|
@ -14,7 +14,6 @@
|
|||
<modules>
|
||||
<module>blade-admin</module>
|
||||
<module>blade-develop</module>
|
||||
<module>blade-config-server</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -48,6 +48,12 @@
|
|||
<artifactId>swagger-models</artifactId>
|
||||
<version>${swagger.models.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.dreamlu</groupId>
|
||||
<artifactId>mica-auto</artifactId>
|
||||
<version>${mica.auto.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
# 启动步骤
|
||||
## 安装consul
|
||||
下载地址:https://www.consul.io/downloads.html
|
||||
|
||||
安装启动然后访问consul web端:http://localhost:8500
|
||||
## 安装(mac)
|
||||
```bash
|
||||
brew install consul
|
||||
```
|
||||
|
||||
## 启动
|
||||
### 命令方式:
|
||||
|
||||
```bash
|
||||
consul agent -server -bootstrap -bind 127.0.0.1 -client 0.0.0.0 -data-dir ./data -ui -datacenter=blade
|
||||
```
|
||||
|
||||
### brew服务
|
||||
> 修改consul启动参数:
|
||||
```bash
|
||||
vim /usr/local/opt/consul/homebrew.mxcl.consul.plist
|
||||
```
|
||||
|
||||
> 修改ProgramArguments部分:
|
||||
```html
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/usr/local/opt/consul/bin/consul</string>
|
||||
<string>agent</string>
|
||||
<string>-server</string>
|
||||
<string>-bootstrap</string>
|
||||
<string>-advertise</string>
|
||||
<string>127.0.0.1</string>
|
||||
<string>-data-dir</string>
|
||||
<string>./data</string>
|
||||
<string>-ui</string>
|
||||
</array>
|
||||
```
|
||||
|
||||
> 启动:
|
||||
```bash
|
||||
brew services start consul
|
||||
```
|
||||
|
||||
|
||||
Binary file not shown.
9
pom.xml
9
pom.xml
|
|
@ -19,7 +19,8 @@
|
|||
<mybatis.plus.version>3.0.7.1</mybatis.plus.version>
|
||||
<curator.framework.version>4.0.1</curator.framework.version>
|
||||
<protostuff.version>1.6.0</protostuff.version>
|
||||
<mica.auto.version>1.0.0</mica.auto.version>
|
||||
<mica.auto.version>1.0.1</mica.auto.version>
|
||||
<nacos.version>0.2.1.RELEASE</nacos.version>
|
||||
<spring.boot.admin.version>2.0.2</spring.boot.admin.version>
|
||||
|
||||
<spring.boot.version>2.0.7.RELEASE</spring.boot.version>
|
||||
|
|
@ -78,12 +79,6 @@
|
|||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.dreamlu</groupId>
|
||||
<artifactId>mica-auto</artifactId>
|
||||
<version>${mica.auto.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user