首页 > 其他分享 >搭建eureka集群环境以及客户端配置

搭建eureka集群环境以及客户端配置

时间:2024-12-03 23:33:08浏览次数:5  
标签:spring springframework eureka 集群 user org security 客户端

先来效果图

eureka集群节点一

 eureka集群节点二

 节点一显示的注册服务

 节点二显示的注册服务

 eureka服务端配置如下所示

 现在将eureka服务端放到了测试环境 192.168.31.50  192.168.31.60

服务信息

 最后给出全部的eureka代码

pom文件

<?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">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.eureka</groupId>
    <artifactId>pingan-cloud</artifactId>
    <version>1.0-SNAPSHOT</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.14</version>
        <relativePath/>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>2021.0.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.springframework.security</groupId>-->
<!--            <artifactId>spring-security-web</artifactId>-->
<!--            <version>5.4.11</version>-->
<!--        </dependency>-->
        <dependency>
            <groupId>com.thoughtworks.xstream</groupId>
            <artifactId>xstream</artifactId>
            <version>1.4.20</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jettison</groupId>
            <artifactId>jettison</artifactId>
            <version>1.5.4</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
        </plugins>
        <finalName>eureka</finalName>
    </build>

</project>

  application.properties

#端口号
server.port=8764
eureka.client.service-url.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@192.168.31.60:8763/eureka
eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false
#关闭自动保护机制
eureka.server.enable-self-preservation=false
#eureka清理无效节点的时间间隔,单位毫秒
eureka.server.eviction-interval-timer-in-ms=60000

spring.application.name=eureka_8764

#日志打印级别
#logging.level.com.eureka=info
#logging.level.web=info
#spring.devtools.add-properties=false


logging.level.com.eureka=debug
logging.level.org.springframework.web.client.RestTemplate=info
logging.level.org.springframework.web.HttpLogging=info
logging.level.web=debug
spring.devtools.add-properties=false

spring.security.user.name=qiuxie
spring.security.user.password=E13301455191qiuxie

spring.security.basic.enable=true

  代码部分

package com.eureka.config;

import org.springframework.context.annotation.Configuration;
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;
import org.springframework.security.config.http.SessionCreationPolicy;

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER);
        http.csrf().disable();
        //注意:为了可以使用 http://${user}:${password}@${host}:${port}/eureka/ 这种方式登录,所以必须是httpBasic,
        // 如果是form方式,不能使用url格式登录
        http.authorizeRequests().anyRequest().authenticated().and().httpBasic();
    }
}

  

package com.eureka;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
/**
 * @author yourheart
 * @Description
 * @create 2022-04-20 21:17
 */
@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class,args);
    }
}

  项目结构展示

 

 客户端配置为

eureka.client.serviceUrl.defaultZone=http://${spring.security.user.name}:${spring.security.user.password}@192.168.31.60:8763/eureka/,http://${spring.security.user.name}:${spring.security.user.password}@192.168.31.50:8764/eureka/

spring.security.user.name=aa
spring.security.user.password=123456

  

标签:spring,springframework,eureka,集群,user,org,security,客户端
From: https://www.cnblogs.com/q202105271618/p/18585150

相关文章

  • Redis设计与实现第17章 -- 集群 总结2(执行命令 重新分片)
    17.3在集群中执行命令接收命令的节点会计算出命令要处理的数据库键属于哪个槽,并检查这个槽是否指派给了自己:如果是的话,直接执行这个命令否则,节点向客户端返回一个MOVED错误,指引客户端转向redirect至正确的节点,并再次发送之前想要执行的命令17.3.1计算键属于哪个槽......
  • RabbitMQ 双机 镜像集群模式
    目录准备工作组建集群rabbitmq01rabbitmq02设置HA策略注意补充命令行检验登录管理界面检验准备工作#/etc/hosts172.16.0.11rabbitmq01172.16.0.12rabbitmq02组建集群rabbitmq01rabbitmq-server-detachedrabbitmqctlstatus#复制cookiecp~/.erlang.cookierabbitmq......
  • 三网H5游戏【全民暗黑H5】最新整理Win一键服务端+GM授权后台+简易安卓客户端+详细搭建
    搭建环境windows2012R2中文版推荐最低服务器配置2核心4G内存安卓客户端已测试客户端大小6M版本码H-000154......
  • Kafka单机集群安装
    下载地址https://kafka.apache.org/downloads解压到指定目录tar-zxf/mnt/d/software/kafka_2.12-3.9.0.tgz-C/mnt/d/appsmv/mnt/d/apps/kafka_2.12-3.9.0/mnt/d/apps/kafka自动添加相关配置信息及启动脚本假定当前机器的IP地址:172.29.2.194KAFKA_HOME=/mnt/d/apps/k......
  • ZooKeeper单机集群的安装
    下载地址https://dlcdn.apache.org/zookeeper/zookeeper-3.8.4/解压到指定目录tar-zxf/mnt/d/software/apache-zookeeper-3.8.4-bin.tar.gz-C/mnt/d/appsmv/mnt/d/apps/apache-zookeeper-3.8.4-bin/mnt/d/apps/zookeeper配置脚本#假设Zookeeper解压到以下目录ZK_H......
  • SseEmitter 服务器向客户端推送消息
    importorg.springframework.http.MediaType;importorg.springframework.web.bind.annotation.GetMapping;importorg.springframework.web.bind.annotation.RestController;importorg.springframework.web.servlet.mvc.method.annotation.SseEmitter;importjava.io.IOExc......
  • elasticsearch集群部署及加密通讯
    原文地址:elasticsearch集群部署及加密通讯–无敌牛欢迎参观我的个人博客:无敌牛–技术/著作/典籍/分享等第零步,准备给各台设备配置虚拟主机名,这样集群不依赖IP,即使IP变动,改动也更方便。参考往期文章:https://www.madbull.site/?p=1094第三步3.2一节。第一步,颁发证书......
  • 初探elasticsearch集群
    集群概览:{"cluster_name":"3e4500835f604a89b762f0e854d3747f","status":"green","timed_out":false,"number_of_nodes":3,"number_of_data_nodes":2,"active_......
  • Move 合约部署踩坑笔记:如何解决 Sui 客户端发布错误Committing lock file
    Move共学活动:快速上手Move开发为了帮助更多开发者快速了解和掌握Move编程语言,Move共学活动由HOH社区、HackQuest、OpenBuild、KeyMap联合发起。该活动旨在为新手小白提供一个良好的学习平台,带领大家一步步熟悉Move语言,并了解如何将其应用到Web3开发中。通过......
  • 如何搭建JMeter分布式集群环境来进行性能测试
    在性能测试中,当面对海量用户请求的压力测试时,单机模式的JMeter往往力不从心。如何通过分布式集群环境,充分发挥JMeter的性能测试能力?这正是许多测试工程师在面临高并发、海量数据时最关注的问题。那么,如何轻松搭建JMeter分布式集群环境,实现性能测试的最大化呢?你是否也曾为测试......