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 查看下我们的进程 
  • 这个时候访问一下我们的Eureka 
  • SpringCloud注册中心Eureka部署linux环境挂载运行与服务搭建_第1张图片
  • 呀!出来了,心情大家懂得啊
  • 如果没有实现 这里有我做的好的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
  • 完成启动效果图

SpringCloud注册中心Eureka部署linux环境挂载运行与服务搭建_第2张图片

 

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

2018-11-05

 

 

 

 

你可能感兴趣的:(Spring,Cloud,SpringBoot)