springcloud學習之eureka的server和client搭建
標簽: springcloud
1.eurekaServer的搭建:
pom.xml中必要的依賴:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
application.yml配置:
spring:
profiles:
active: dev2
---
spring:
application:
###當前服務名
name: eureka-peer
profiles: dev
server:
##端口號
port: 10000
---
spring:
profiles: dev1
application:
name: eureka-peer2
server:
port: 10001
---
spring:
profiles: dev2
application:
name: eureka-peer3
server:
port: 10002
---
eureka:
instance:
hostname: dev1
client:
##檢索服務
fetch-registry: false
##是否將自己注冊到eureka
register-with-eureka: false
##客戶端默認去這個地址找注冊中心
service-url:
defaultZone: http://localhost:10000/eureka/,http://localhost:10001/eureka/,http://localhost:10002/eureka/
server:
### 當eureka啟動時,不能從集群節點中獲取到instance注冊信息,應該等多久
wait-time-in-ms-when-sync-empty: 0
enable-self-preservation: true
###eureka多長時間更新一次數據
peer-eureka-nodes-update-interval-ms: 100000
啟動類的注解配置:
package com.eurekaServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@EnableEurekaServer
@SpringBootApplication
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
- eurekaClient的配置:
pom.xml必要依賴:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
application.proprties配置:
eureka.port1=10000
eureka.port2=10001
eureka.port3=10002
server.port=8763
eureka.instance.hostname=localhost
spring.application.name=eureka-client
eureka.client.healthcheck.enabled=true
#在此指定服務注冊中心地址
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:${eureka.port1}/eureka/,http://${eureka.instance.hostname}:${eureka.port2}/eureka/,http://${eureka.instance.hostname}:${eureka.port3}/eureka/
management.endpoints.web.exposure.include= "*"
management.endpoints.web.cors.allowed-origins="*"
management.endpoints.web.cors.allowed-methods= "*"
啟動類的配置:
package come.eurekaclient;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
@SpringBootApplication
@EnableEurekaClient
public class EurekaclientApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaclientApplication.class, args);
}
}
demo代碼地址:https://github.com/luohong12/springcloud-eurakaclient.git
https://github.com/luohong12/springcloud-eurekaServer.git
3.springboot在linux環境上的發布:
springboot官方是建議以jar包的形式發布
發布eurekaServer:
cd /usr/local/src/
git clone -b master https://github.com/luohong12/springcloud-eurekaServer.git
cd springcloud-eurekaServer/
mvn clean install
mkdir /usr/local/project
cp target/Eureka-Server-0.0.1-SNAPSHOT.jar /usr/local/project/
cd /usr/local/project/
mkdir logs
java -jar Eureka-Server-0.0.1-SNAPSHOT.jar -> logs/EurekaServer.out &
tail -f logs/EurekaServer.out
訪問檢驗是否發布成功:
eurekaClient發布方式是一樣的,這里就不寫,直接看結果:
智能推薦
freemarker + ItextRender 根據模板生成PDF文件
1. 制作模板 2. 獲取模板,并將所獲取的數據加載生成html文件 2. 生成PDF文件 其中由兩個地方需要注意,都是關于獲取文件路徑的問題,由于項目部署的時候是打包成jar包形式,所以在開發過程中時直接安照傳統的獲取方法沒有一點文件,但是當打包后部署,總是出錯。于是參考網上文章,先將文件讀出來到項目的臨時目錄下,然后再按正常方式加載該臨時文件; 還有一個問題至今沒有解決,就是關于生成PDF文件...
電腦空間不夠了?教你一個小秒招快速清理 Docker 占用的磁盤空間!
Docker 很占用空間,每當我們運行容器、拉取鏡像、部署應用、構建自己的鏡像時,我們的磁盤空間會被大量占用。 如果你也被這個問題所困擾,咱們就一起看一下 Docker 是如何使用磁盤空間的,以及如何回收。 docker 占用的空間可以通過下面的命令查看: TYPE 列出了docker 使用磁盤的 4 種類型: Images:所有鏡像占用的空間,包括拉取下來的鏡像,和本地構建的。 Con...
requests實現全自動PPT模板
http://www.1ppt.com/moban/ 可以免費的下載PPT模板,當然如果要人工一個個下,還是挺麻煩的,我們可以利用requests輕松下載 訪問這個主頁,我們可以看到下面的樣式 點每一個PPT模板的圖片,我們可以進入到詳細的信息頁面,翻到下面,我們可以看到對應的下載地址 點擊這個下載的按鈕,我們便可以下載對應的PPT壓縮包 那我們就開始做吧 首先,查看網頁的源代碼,我們可以看到每一...
猜你喜歡
Linux C系統編程-線程互斥鎖(四)
互斥鎖 互斥鎖也是屬于線程之間處理同步互斥方式,有上鎖/解鎖兩種狀態。 互斥鎖函數接口 1)初始化互斥鎖 pthread_mutex_init() man 3 pthread_mutex_init (找不到的情況下首先 sudo apt-get install glibc-doc sudo apt-get install manpages-posix-dev) 動態初始化 int pthread_...
統計學習方法 - 樸素貝葉斯
引入問題:一機器在良好狀態生產合格產品幾率是 90%,在故障狀態生產合格產品幾率是 30%,機器良好的概率是 75%。若一日第一件產品是合格品,那么此日機器良好的概率是多少。 貝葉斯模型 生成模型與判別模型 判別模型,即要判斷這個東西到底是哪一類,也就是要求y,那就用給定的x去預測。 生成模型,是要生成一個模型,那就是誰根據什么生成了模型,誰就是類別y,根據的內容就是x 以上述例子,判斷一個生產出...
styled-components —— React 中的 CSS 最佳實踐
https://zhuanlan.zhihu.com/p/29344146 Styled-components 是目前 React 樣式方案中最受關注的一種,它既具備了 css-in-js 的模塊化與參數化優點,又完全使用CSS的書寫習慣,不會引起額外的學習成本。本文是 styled-components 作者之一 Max Stoiber 所寫,首先總結了前端組件化樣式中的最佳實踐原則,然后在此基...
19.vue中封裝echarts組件
19.vue中封裝echarts組件 1.效果圖 2.echarts組件 3.使用組件 按照組件格式整理好數據格式 傳入組件 home.vue 4.接口返回數據格式...