Docker安装Sentinel-dashboard

本文详细介绍了如何在Docker环境下部署sentinel-dashboard,并确保它与本地sentinel-client的通信。重点在于网络配置,包括自定义网络和IP设置,以确保两者在同一网段以实现正常通信。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

目录

  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
在这里插入图片描述



3. sentinel-client(Spring Boot)

项目结构
在这里插入图片描述
pom.xml

	<dependency>
	    <groupId>com.alibaba.cloud</groupId>
	    <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
	</dependency>
	
	<dependency>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-web</artifactId>
	</dependency>
	
	<dependency>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-actuator</artifactId>
	</dependency>

application.yml(注意,这里的ip需要在sentinel-net指定的网段下)

# 应用名称
spring:
  application:
    name: demo-13-sentinel-service-7005
  cloud:
    sentinel:
      transport:
        dashboard: 121.37.199.247: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";
    }
}

启动类

@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。
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值