1. 处理的情况
2. sentinel-dashboard
3. sentinel-client
1. 处理的情况
① 当sentinel-dashboard、sentinel-client都位于localhost,dashboard能显示client中的资源;
② 当用docker安装sentinel-dashboard(桥接到docker0),而sentinel-client位于localhost,dashboard不能显示client中的资源;
sentinel-dashboard能与sentinel-client进行网络通信,dashboard才能显示client中的资源。
所以,在使用docker安装sentinel-dashboard的情况下,把dashboard与client放到同一网段下,即可实现两者的通信。
2. sentinel-dashboard
# 拉取镜像
docker pull bladex/sentinel-dashboard:1.8.0
# 开放端口
firewall-cmd --add-port=8858/tcp --zone=public --permanent
firewall-cmd --add-port=8719/tcp --zone=public --permanent
# 测试
firewall-cmd --add-port=9000/tcp --zone=public --permanent
# 重新加载
firewall-cmd --reload
# 创建自定义网络(用于将sentinel-dashboard与sentinel-client置于同一网段下)
docker network create --driver bridge --subnet 172.19.0.0/16 --gateway 172.19.0.1 sentinel-net
# 创建并运行sentinel-dashboard容器
docker run \
--name sentinel \
--net sentinel-net \
--ip 172.19.10.1 \
-p 8858:8858 \
-p 8719:8719 \
-d bladex/sentinel-dashboard:1.8.0
访问 http://ip:8858
项目结构
pom.xml
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-sentinelartifactId>
dependency>
<dependency>
<groupId>com.alibaba.cloudgroupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discoveryartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-webartifactId>
dependency>
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-actuatorartifactId>
dependency>
application.yml(注意,这里的ip需要在sentinel-net指定的网段下)
# 应用名称
spring:
application:
name: demo-13-sentinel-service-7005
cloud:
nacos:
discovery:
server-addr: 120.37.100.249:8848
sentinel:
transport:
dashboard: 120.37.100.249:8858
# Sentinel api
port: 8719
client-ip: 172.19.10.2
management:
endpoints:
web:
exposure:
include: '*'
# 应用服务 WEB 访问端口
server:
port: 8080
FlowLimitController
@RestController
public class FlowLimitController {
@GetMapping("/resource/a")
public String testA() {
return "test A";
}
@GetMapping("/resource/b")
public String testB() {
return "test B";
}
}
启动类
@EnableDiscoveryClient
@SpringBootApplication
public class Demo13SentinelService7005Application {
public static void main(String[] args) {
SpringApplication.run(Demo13SentinelService7005Application.class, args);
}
}
Dockerfile
FROM openjdk:8u201-jdk-alpine3.9
COPY *.jar /app.jar
CMD ["--server.port=8080"]
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "/app.jar"]
将springboot项目编译、打包。并将jar包和Dockerfile上传至服务器的同一目录下!
构建镜像、创建并启动sentinel-client容器
# 进入jar和Dockerfile的目录
# 构建镜像
docker build -t sentinel-service:v1 .
# 创建并运行容器(注意这里的ip要与application.yml中的对应)
docker run \
--name sentinel-service \
--net sentinel-net \
--ip 172.19.10.2 \
-p 9000:8080 \
-d sentinel-service:v1
先访问
http://ip:9000/resource/a
http://ip:9000/resource/b
再刷新sentinel-dashboard。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)