SpringCloud(Hoxton.SR3)基础篇:第三章、Eureka集群 高可用的认证服务实现与搭建
2021-02-15 04:20
标签:security 代码 ble frame mamicode cal repo lease color 一、Eureka Server高可用搭建(服务注册中心) 1.1MAVEN相关依赖 1.2 application.yml 相关配置 eureka服务一配置 eureka服务二配置 eureka服务三配置 1.2.2 配置hosts文件,识别peer1,peer2,peer3地址 windows系统hosts文件路径:C:\Windows\System32\drivers\etc 修改步骤:以管理员的身份运行CMD,输入notepad打开记事本。用记事本往hosts文件内添加内容 hosts文件加入peer1,peer2,peer3内容 1.3 启动类代码 1.4 解决页面中Instances currently registered with Eureka下面并没得注入的别的服务 禁用Spring Security的CSRF保护,添加一个配置类禁用csrf 1.5 eureka页面出现unavailable-replicas(不可用分片)问题 最后成功启动三个eureka服务,结果如图 参考文献:https://blog.csdn.net/longguo321/article/details/80493618 https://blog.csdn.net/liupeifeng3514/java/article/details/85273961 SpringCloud(Hoxton.SR3)基础篇:第三章、Eureka集群 高可用的认证服务实现与搭建 标签:security 代码 ble frame mamicode cal repo lease color 原文地址:https://www.cnblogs.com/wps54213/p/12716846.html parent>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-parentartifactId>
version>2.2.6.RELEASEversion>
relativePath />
parent>
properties>
project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
project.reporting.outputEncoding>UTF-8project.reporting.outputEncoding>
java.version>1.8java.version>
spring-cloud.version>Hoxton.SR3spring-cloud.version>
properties>
dependencyManagement>
dependencies>
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-dependenciesartifactId>
version>${spring-cloud.version}version>
type>pomtype>
scope>importscope>
dependency>
dependencies>
dependencyManagement>
dependencies>
dependency>
groupId>org.springframework.cloudgroupId>
artifactId>spring-cloud-starter-netflix-eureka-serverartifactId>
dependency>
dependency>
groupId>org.springframework.bootgroupId>
artifactId>spring-boot-starter-securityartifactId>
dependency>
dependencies>
server:
port: 8761
#安全认证配置
spring:
application:
name: EUREKA-HA
security:
basic:
enabled: true
user:
name: user
password: password123
eureka:
#Eureka实例名,集群中根据这里相互识别
instance:
hostname: peer1
client:
serviceUrl:
#注册中心地址
defaultZone: http://user:password123@peer2:8762/eureka/,http://user:password123@peer3:8763/eureka/
server:
port: 8762
#安全认证配置
spring:
application:
name: EUREKA-HA
security:
basic:
enabled: true
user:
name: user
password: password123
eureka:
#Eureka实例名,集群中根据这里相互识别
instance:
hostname: peer2
client:
serviceUrl:
defaultZone: http://user:password123@peer1:8761/eureka/,http://user:password123@peer3:8763/eureka/
server:
port: 8763
#安全认证配置
spring:
application:
name: EUREKA-HA
security:
basic:
enabled: true
user:
name: user
password: password123
eureka:
#Eureka实例名,集群中根据这里相互识别
instance:
hostname: peer3
client:
serviceUrl:
defaultZone: http://user:password123@peer1:8761/eureka/,http://user:password123@peer2:8762/eureka/
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 peer1
127.0.0.1 peer2
127.0.0.1 peer3
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication
//该注解表明应用为eureka服务,有可以联合多个服务作为集群,对外提供服务注册以及发现功能
@EnableEurekaServer
public class EurekaHaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaHaApplication.class, args);
}
}
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* eureka开启服务无法连接注册中心
* spring Cloud 2.0 以上 security默认启用了csrf检验,要在eurekaServer端配置security的csrf检验为false
* @author computer
*
*/
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter{
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
super.configure(http);
}
}
上一篇:Spring Boot实践(二):logback日志配置
下一篇:数组去重
文章标题:SpringCloud(Hoxton.SR3)基础篇:第三章、Eureka集群 高可用的认证服务实现与搭建
文章链接:http://soscw.com/index.php/essay/55493.html