cloud config、eureka+security(3个不同公网ip、不同局域网环境的服务器)

本文档详细介绍了如何在三个不同公网IP和局域网环境的服务器上配置cloud config、eureka及security。每个服务器上分别部署了一个带有security的eureka和一个config服务,config服务仅在本地局域网内运行。通过@EnableConfigServer和@EnableEurekaServer注解启动相关服务,并在Gitee上管理配置文件。Dockerfile和docker-compose.yml用于构建和部署服务,确保在CentOS7的Docker环境中正确运行。在不同网络环境中,需开放eureka的端口以实现互相注册。
摘要由CSDN通过智能技术生成

cloud config、eureka+security(3个不同公网ip、不同局域网环境的服务器)

每个服务器分别有一个eureka(整合security)和一个config,config只在本地局域网中,eureka向互联网暴露端口。

  1. config的启动类使用@EnableConfigServer注解,eureka的启动类用@EnableEurekaServer
//Config的Application启动类
@SpringBootApplication
@EnableConfigServer // 启动Cloud Config服务端服务,获取远程git/gitee的配置
public class HttpConfigN03344Application {
   

  public static void main(String[] args) {
   
      SpringApplication.run(HttpConfigN03344Application.class, args);
  }

}

//Eureka的Applicatoin启动类
@SpringBootApplication
@EnableEurekaServer // EnableEurekaSever 服务端的启动类,可以接收别人注册进来~
public class HttpEurekaN17001Application {
   

  public static void main(String[] args) {
   
      SpringApplication.run(HttpEurekaN17001Application.class, args);
  }

  @EnableWebSecurity //用到了security,如果不写这个,会发现服务之间没法相互注册,明明有开放端口
  static class WebSecurityConfig extends WebSecurityConfigurerAdapter {
   
      @Override
      protected void configure(HttpSecurity http) throws Exception {
   
          http.csrf().ignoringAntMatchers("/eureka/**");
          super.configure(http);
      }
  }
}
  1. IDEA中编写Config项目的application.yml以及Eureka的application.yml和bootstrap.yml
###### Config项目的配置文件 application.yml
server:
port: 3344 # 服务的端口,只用来docker网络网桥内访问,docker中不用另外配置-p 3344:3344来映射到宿主机,因为我们只要本地的eureka访问网桥bridge下的该Cloud Config服务的3344端口即可

spring:
application:
  name: http-config-n0-3344 #应用名
  # 连接远程仓库
cloud:
  config:
    server:
      git:
        uri: https://gitee.com/XXXXXX.git # https,不是git,https才能使用下面的账号密码形式,如果用ssh,那么需要用rsa密钥访问。本来我打算用ssh方式,但是尝试了之后失败了,可能我配置下面参数的rsa出错了,但是我按照网络上各种文章以及官方示例,都没整好,就不折腾了
        username: gitee账号
        password: gitee密码

# 通过 config-server可以连接到git,访问其中的资源以及配置~



###### Eureka项目的application.yml
spring:
application
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值