SpringBopot&SpringCloud註冊中心Eureka部署linux環境掛載執行
阿新 • • 發佈:2018-12-19
Eureka部署linux環境掛載執行
- 首先是pom檔案 對內嵌tomcat的處理javax.servlet-api;
- maven管理依賴的引入spring-boot-maven-plugin;
- springcloud依賴的引入spring-cloud-dependencies;
<?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.公司名</groupId> <artifactId>公司名_eureka</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>公司名_eureka</name> <description>Demo project for Spring Boot</description> <!--繼承 boot 共有工程--> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.0.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <!--制定 jdk 和 編碼--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.M1</spring-cloud.version> </properties> <!--Eureka server 依賴--> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --> <!--支援tomcat 啟動--> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <!--Eureka lock--> <!--<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>--> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <!--ScriptCloud--> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project>
- 然後是啟動類的改動 SpringBootServletInitializer 支援外部啟動
package 公司名.eureka.eureka; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; @EnableEurekaServer @SpringBootApplication public class 公司名EurekaApplication extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(HnEurekaApplication.class, args); } }
- 然後是配置檔案properties 這裡主要是註冊中心ip地址的配置改動0.0.0.0 這裡不太懂,一直配指定ip , 這裡聽取了王董的建議
server.port = 7517 spring.application.name = HnEureka #Eurekalock #security.basic.enabled = true #security.user.name = user #security.user.password = 123456 #EurekaServer eureka.instance.hostname = eureka eureka.client.register-with-eureka = false eureka.client.fetch-registry = false eureka.client.serviceUrl.defaultZone = http://0.0.0.0:0/eureka/
- 然後傳到linux環境下,記得裝匹配版本的jdk , 這裡用的是1.8
- 然後執行linux 命令試執行專案, java -jar item.jar 如果看到了美麗的springboot啟動成功畫面,那麼恭喜下自己
- 然後讓專案後臺執行,啟用懸掛命令(item.jar=當前的jar全名) nohup java -jar target/item.jar > /dev/null 2>&1 &
- 如果這個時候看到的畫面卡頓了,不用擔心,關閉ssh連結,重新進入一下
- ps -ef |grep eureka 檢視下我們的程序
- 這個時候訪問一下我們的Eureka
- 呀!出來了,心情大家懂得啊
chenyb 隨筆記錄,只為方便自己學習
2018-11-05