eureka编译 linux,SpringCloud注册中心Eureka部署linux环境挂载运行与服务搭建

Eureka部署linux环境挂载运行

首先是pom文件 对内嵌tomcat的处理javax.servlet-api;

maven管理依赖的引入spring-boot-maven-plugin;

springcloud依赖的引入spring-cloud-dependencies;

4.0.0

org.springframework.boot

spring-boot-starter-parent

2.2.2.RELEASE

com.ll

eureka

0.0.1-SNAPSHOT

eureka

Demo project for Spring Boot

1.8

Hoxton.SR6

org.springframework.cloud

spring-cloud-starter-netflix-eureka-server

org.springframework.boot

spring-boot-starter-test

test

org.junit.vintage

junit-vintage-engine

org.springframework.cloud

spring-cloud-dependencies

${spring-cloud.version}

pom

import

eureka

org.springframework.boot

spring-boot-maven-plugin

然后是启动类的改动 SpringBootServletInitializer 支持外部启动

package com.ll.eureka;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@EnableEurekaServer

@SpringBootApplication

public class EurekaApplication {

public static void main(String[] args) {

SpringApplication.run( EurekaApplication.class, args );

}

}

eureka.client.defaultZone: 这里目前一定要这么写,否则读取不到,http://ll-eureka:8080/eureka

eureka.instance.hostname:代替当前eureka IP

eureka服务中配置 eureka.client.defaultZone、eureka.instance.hostname,解决 Connect to localhost:8761 timed out异常

server:

port: 7517

######################################################################

# -- eureka -- #

######################################################################

eureka:

server:

enable-self-preservation: false

client:

register-with-eureka: false

fetch-registry: false

# service-url.defaultZone && instance.hostname 解决 Connect to localhost:8761 timed out

service-url:

defaultZone: http://ll-eureka:8080/eureka

instance:

# hostname 代替IP

hostname: ll-eureka

然后传到linux环境下,记得装匹配版本的jdk , 这里用的是1.8

然后运行linux 命令试运行项目,java -jar item.jar 如果看到了美丽的springboot启动成功画面,那么恭喜下自己

然后让项目后台运行,启用悬挂命令(item.jar=当前的jar全名) nohup java -jar item.jar &

如果这个时候看到的画面卡顿了,不用担心,关闭ssh链接,重新进入一下

ps -ef |grep eureka查看下我们的进程

a9192574d0b2801190324c7b01c3e5d7.png

这个时候访问一下我们的Eureka

48ee42d66753834bd99d7e2e505121bf.png

呀!出来了,心情大家懂得啊

如果没有实现 这里有我做的好的jar 直接启动就可以了https://download.csdn.net/download/scdncby/10765985

Eureka 客户端

客户端maven依赖

org.springframework.cloud

spring-cloud-starter-openfeign

2.2.2.RELEASE

启动类

package com.ll;

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.builder.SpringApplicationBuilder;

import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@EnableEurekaClient

@SpringBootApplication

public class JobApplication extends SpringBootServletInitializer{

public static void main(String[] args) {

SpringApplication.run( JobApplication.class, args);

}

@Override

protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

return application.sources( JobApplication.class );

}

}

yaml配置

defaultZone:http://127.0.0.1:8080/eureka/ ,127.0.0.1eureka注册中心ip地址,7517eureka注册中心ip端口号

记得用spring.application.name:标明在eureka中心的名称,否则被标记为:unknown不好区分

spring:

application:

name: ll-job

eureka:

client:

enabled: true

registry-fetch-interval-seconds: 10

service-url:

# default-zone 不可以(目前只能这么写)

defaultZone: http://127.0.0.1:7517/eureka/

instance:

prefer-ip-address: true

lease-renewal-interval-in-seconds: 5

lease-expiration-duration-in-seconds: 15

完成启动效果图

cee4aac18bc9ca2aeb82a0eb60f0ef79.png

chenyb 随笔记录,只为方便自己学习

2018-11-05

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值