- 浏览: 269923 次
- 性别:
- 来自: 天津
文章分类
- 全部博客 (183)
- oracle (4)
- informix (1)
- web开发 (6)
- java (49)
- hibernate (1)
- hadoop (1)
- spring (23)
- 非技术 (8)
- ibatis2 (5)
- Linux (6)
- tomcat (14)
- nginx (7)
- dubbo (3)
- myibatis (7)
- webservice 开发 (2)
- mysql (2)
- svn (2)
- redis (7)
- 分布式技术 (17)
- zookeeper (2)
- kafka (2)
- velocity (1)
- maven (7)
- js (1)
- freemarker (1)
- Thymeleaf (3)
- 代码审计 (1)
- ibatis3 (1)
- rabbitmq (1)
最新评论
1.新建一个springboot的项目。
2.添加pom.xml 内容:
<?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.boce.dfs</groupId>
<artifactId>comm-eku</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>comm-eku</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.添加配置文件 application.yml
# server (eureka 默认端口为:8761)
server:
port: 9999
# spring
spring:
application:
name: comm-eku
# eureka
eureka:
client:
# 是否注册到eureka
register-with-eureka: true
# 是否从eureka获取注册信息
fetch-registry: false
availability-zones:
honghu: honghuZone
#Eureka Server注册服务的地址
service-url:
honghuZone: http://honghu:123456@localhost:8761/eureka/
defaultZone: http://honghu:123456@localhost:8761/eureka/
instance:
prefer-ip-address: true
hostname: localhost
metadataMap:
zone: honghuZone
user: ${security.user.name}
password: {security.user.password}
# 指定环境
environment: dev
#指定数据中心
datacenter: honghu
# 关闭自我保护模式
server:
enable-self-preservation: false
#设置清理无效节点的时间间隔,默认60000,即是60s
eviction-interval-timer-in-ms: 60000
# 服务认证
security:
basic:
enabled: true
user:
name: honghu
password: 123456
management:
security:
enabled: false
4.给主类添加注解:
package com.boce.dfs;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
@ComponentScan(value = "com.boce")
@EnableEurekaServer
@SpringBootApplication
public class CommEkuApplication {
@RequestMapping("/hello")
private String greeting() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(CommEkuApplication.class, args);
}
}
package com.boce;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
/**
* Created by gjp on 2017/11/7.
*/
@Component
@Configuration
public class ConfigBase {
@LoadBalanced
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
package com.boce.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
/**
* Created by gjp on 2017/11/7.
*/
@Controller
public class DemoController {
@Resource
private RestTemplate restTemplate;
@ResponseBody
@RequestMapping("/demo/test")
public String test(){
System.out.println("test.................");
return "test";
}
}
日志信息:
2017-11-07 17:07:26.183 INFO 18960 --- [ Thread-17] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false
2017-11-07 17:07:26.183 INFO 18960 --- [ Thread-17] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context
2017-11-07 17:07:26.232 INFO 18960 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9999 (http)
2017-11-07 17:07:26.233 INFO 18960 --- [ restartedMain] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 9999
2017-11-07 17:07:26.239 INFO 18960 --- [ restartedMain] com.boce.dfs.CommEkuApplication : Started CommEkuApplication in 9.861 seconds (JVM running for 10.571)
2017-11-07 17:07:26.811 INFO 18960 --- [nio-9999-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-11-07 17:07:26.811 INFO 18960 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-11-07 17:07:26.836 INFO 18960 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 25 ms
2017-11-07 17:07:26.956 INFO 18960 --- [nio-9999-exec-1] c.n.e.registry.AbstractInstanceRegistry : Registered instance COMM-EKU/gjp-pc:comm-eku:9999 with status UP (replication=false)
2017-11-07 17:07:26.978 INFO 18960 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COMM-EKU/gjp-pc:comm-eku:9999 - registration status: 204
2017-11-07 17:07:27.620 INFO 18960 --- [nio-9999-exec-2] c.n.e.registry.AbstractInstanceRegistry : Registered instance COMM-EKU/gjp-pc:comm-eku:9999 with status UP (replication=true)
2017-11-07 17:09:26.188 INFO 18960 --- [ Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node
2017-11-07 17:09:26.188 INFO 18960 --- [ Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1
2017-11-07 17:09:26.188 INFO 18960 --- [ Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
2017-11-07 17:09:26.198 INFO 18960 --- [ Thread-17] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
2.添加pom.xml 内容:
<?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.boce.dfs</groupId>
<artifactId>comm-eku</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>comm-eku</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
<version>1.3.4.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
3.添加配置文件 application.yml
# server (eureka 默认端口为:8761)
server:
port: 9999
# spring
spring:
application:
name: comm-eku
# eureka
eureka:
client:
# 是否注册到eureka
register-with-eureka: true
# 是否从eureka获取注册信息
fetch-registry: false
availability-zones:
honghu: honghuZone
#Eureka Server注册服务的地址
service-url:
honghuZone: http://honghu:123456@localhost:8761/eureka/
defaultZone: http://honghu:123456@localhost:8761/eureka/
instance:
prefer-ip-address: true
hostname: localhost
metadataMap:
zone: honghuZone
user: ${security.user.name}
password: {security.user.password}
# 指定环境
environment: dev
#指定数据中心
datacenter: honghu
# 关闭自我保护模式
server:
enable-self-preservation: false
#设置清理无效节点的时间间隔,默认60000,即是60s
eviction-interval-timer-in-ms: 60000
# 服务认证
security:
basic:
enabled: true
user:
name: honghu
password: 123456
management:
security:
enabled: false
4.给主类添加注解:
package com.boce.dfs;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.web.bind.annotation.RequestMapping;
@ComponentScan(value = "com.boce")
@EnableEurekaServer
@SpringBootApplication
public class CommEkuApplication {
@RequestMapping("/hello")
private String greeting() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(CommEkuApplication.class, args);
}
}
package com.boce;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
/**
* Created by gjp on 2017/11/7.
*/
@Component
@Configuration
public class ConfigBase {
@LoadBalanced
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
package com.boce.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
/**
* Created by gjp on 2017/11/7.
*/
@Controller
public class DemoController {
@Resource
private RestTemplate restTemplate;
@ResponseBody
@RequestMapping("/demo/test")
public String test(){
System.out.println("test.................");
return "test";
}
}
日志信息:
2017-11-07 17:07:26.183 INFO 18960 --- [ Thread-17] o.s.c.n.e.server.EurekaServerBootstrap : isAws returned false
2017-11-07 17:07:26.183 INFO 18960 --- [ Thread-17] o.s.c.n.e.server.EurekaServerBootstrap : Initialized server context
2017-11-07 17:07:26.232 INFO 18960 --- [ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 9999 (http)
2017-11-07 17:07:26.233 INFO 18960 --- [ restartedMain] .s.c.n.e.s.EurekaAutoServiceRegistration : Updating port to 9999
2017-11-07 17:07:26.239 INFO 18960 --- [ restartedMain] com.boce.dfs.CommEkuApplication : Started CommEkuApplication in 9.861 seconds (JVM running for 10.571)
2017-11-07 17:07:26.811 INFO 18960 --- [nio-9999-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2017-11-07 17:07:26.811 INFO 18960 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2017-11-07 17:07:26.836 INFO 18960 --- [nio-9999-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 25 ms
2017-11-07 17:07:26.956 INFO 18960 --- [nio-9999-exec-1] c.n.e.registry.AbstractInstanceRegistry : Registered instance COMM-EKU/gjp-pc:comm-eku:9999 with status UP (replication=false)
2017-11-07 17:07:26.978 INFO 18960 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_COMM-EKU/gjp-pc:comm-eku:9999 - registration status: 204
2017-11-07 17:07:27.620 INFO 18960 --- [nio-9999-exec-2] c.n.e.registry.AbstractInstanceRegistry : Registered instance COMM-EKU/gjp-pc:comm-eku:9999 with status UP (replication=true)
2017-11-07 17:09:26.188 INFO 18960 --- [ Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Got 1 instances from neighboring DS node
2017-11-07 17:09:26.188 INFO 18960 --- [ Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Renew threshold is: 1
2017-11-07 17:09:26.188 INFO 18960 --- [ Thread-17] c.n.e.r.PeerAwareInstanceRegistryImpl : Changing status to UP
2017-11-07 17:09:26.198 INFO 18960 --- [ Thread-17] e.s.EurekaServerInitializerConfiguration : Started Eureka Server
发表评论
-
solr 5.0 集群搭建
2018-01-13 14:55 599一,搭建zookeeper集群 1.下载zookeeper解压 ... -
elasticsearch环境搭建和api编程
2017-12-28 16:40 8861.下载 Elasticsearch ,下载地址:https: ... -
solr 5.0搭建 和使用 ik分词
2017-12-19 15:14 4871.将下载来的solr-5.0.0.zip解压。 创建D:\ ... -
修改dubbox支持sping4
2017-09-12 09:03 4771.通过修改依赖jar包和修改部分代码,使dubbox可以在s ... -
solr 4.9 学习
2017-09-05 11:04 4761.下载solr 4.9.0 下载地址 ... -
jenkins自动构建发布程序
2017-08-31 10:28 16151.首先到 https://jenkins.io/ 下载win ... -
FastDFS分布式文件系统使用
2017-08-30 10:28 637安装参照: http://blog.csdn.net/hard ... -
RocketMQ 3.2.6 web监控程序
2017-08-04 14:09 6121.针对 rocketmq3.2.6监控代码在附件中 2. ... -
RocketMQ 3.2.6安装以及测试
2017-08-02 16:34 1692下载 alibaba-rocketmq-3.2.6.tar.g ... -
roketmq3.2.6
2017-04-20 15:30 431roketmq3.2.6 设置 #设置rocketmq的地址 ... -
uncode-schedule 学习
2017-04-11 16:34 574在多台机器都存在定时任务时,通过zookeeper 实现定 ... -
分布式锁 zookeeper
2017-04-06 11:27 402package zk.lock; import ja ... -
分布式锁实现两种方式
2017-03-16 17:13 554package org.gjp; import ja ... -
disconf使用
2017-03-07 10:33 696disconf 已经搭建成功(http://gjp014. ... -
disconf安装过程
2017-03-06 15:49 7031.首先下载 https://github.com/kn ... -
curator 实现分布式锁
2017-02-08 16:20 550package org.gjp; import j ...
相关推荐
通过本地Eureka服务的搭建,开发者可以在开发和测试环境中方便地进行微服务间的通信和调用,提高开发效率并降低调试难度。记住,Eureka的使用需要配合Spring Cloud等相关框架,确保服务的注册和发现功能能正确工作。
**Spring Cloud Eureka 服务搭建** 在分布式系统中,服务发现是至关重要的组成部分,它使得服务消费者能够自动找到服务提供者并进行通信。Spring Cloud Eureka 是 Netflix 提供的一个服务发现组件,它允许微服务...
通过搭建Eureka Server,服务提供者可以将自己的元数据信息注册到Eureka,而服务消费者则可以通过Eureka查找并调用其他服务。整个过程可以通过jar包部署,便于在各种环境中快速启动和运行,同时通过浏览器可以直接...
本文将深入探讨如何使用Spring Cloud搭建微服务,特别是配置Eureka服务发现以及集成Ribbon实现负载均衡。 首先,我们来看标题中的“搭建微服务(聚合工程)”。在Spring Cloud中,聚合工程通常指的是一个包含了多...
eureka集群搭建入门
Eureka集群搭建是一个重要的步骤,尤其在微服务架构中,为了确保服务注册与发现的高可用性,通常需要建立Eureka服务器的集群。Eureka是一个由Netflix开发的服务发现组件,它允许微服务实例向Eureka注册,并通过...
本文将深入探讨Eureka的基本概念、服务注册与发现的原理,以及如何搭建Eureka集群,以提升系统的稳定性和可扩展性。 首先,简单微服务框架是指将单一应用程序拆分为一组小的服务,每个服务都运行在其自己的进程中,...
总结起来,Eureka集群的搭建主要涉及Eureka Server的配置和多实例部署,而Ribbon则是在服务消费者端实现服务实例的选择和负载均衡。这两个组件协同工作,为Spring Cloud微服务架构提供了稳定、高效的服务发现和通信...
eureka集群搭建源码,servlet 应用 Jersey 框架实现自身的 RESTful HTTP接口 服务的注册通过 HTTP 协议实现 通过 JDK 自带的 Timer 实现定时任务:心跳、定时清理过期服务、节点同步 使用Google的guava包实现内存...
在Spring Cloud生态系统中,Eureka是核心的服务发现组件,它提供了服务注册与发现的功能,使得微服务架构中的各个服务能够互相通信。本教程将详细讲解如何在本地环境中模拟搭建Eureka集群,以便于理解其工作原理和...
spring cloud之Eureka Server搭建,最简洁的环境搭建,帮助新手快速搭建起Eureka Server! 安装流程参考 http://lib.csdn.net/article/linux/39639
搭建Eureka集群的主要目的是提高服务发现的可用性。当一个Eureka Server出现故障时,其他节点仍然能够正常工作,保证系统的连续运行。以下是一步步搭建Eureka集群的步骤: 1. **配置多台Eureka Server** 首先,你...
Spring Cloud Eureka集群搭建
Eureka服务端介质,搭建本地的微服务注册与发现中心,spring开发必备,启动命令java -jar eurekaserver01-0.0.1-SNAPSHOT.jar > eurekaserver01.log
Spring Cloud多模块搭建Eureka服务器端口过程详解是指通过Spring Cloud框架搭建一个Eureka服务器,实现服务注册和发现的功能。下面是搭建Eureka服务器端口的详细过程。 首先,需要创建一个父项目,使用Maven作为...
6. **负载均衡**:当Eureka集群搭建完成后,我们可以使用 Ribbon 或者 Netflix Zuul 进行客户端负载均衡,将请求分发到不同的服务实例。 7. **健康检查**:Eureka Server会定期进行心跳检查,如果一段时间内未收到...
Spring Cloud Eureka是Spring Cloud Netflix子项目的核心组件之一,主要用于微服务架构中的服务治理。Eureka是服务注册与发现机制的实现,它允许微服务在注册中心注册自己的地址及端口信息,然后在需要调用其他服务...
SpringCloud搭建微服务架构 SpringBoot 版本1.5.6.RELEASE Dalston.SR3 与时俱进,一起学习进步。 经过几天学习实践整理,已经完成SpringCloud 注册中心 、SpringCloud Config配置中心 搭建。
在`application.yml`文件中,开启Eureka服务,并指定服务实例的名称: ```yaml server: port: 8761 eureka: instance: hostname: localhost client: register-with-eureka: false fetch-registry: false ```...