這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)碛嘘P(guān)微服務(wù)spring-cloud 配置中心config-server本地化部署是怎樣的,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。
保山網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,保山網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為保山1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\成都外貿(mào)網(wǎng)站制作要多少錢,請找那個(gè)售后服務(wù)好的保山做網(wǎng)站的公司定做!
一、服務(wù)端:需要增加配置中心服務(wù)器config-server工程;
1、pom.xml增加相關(guān)配置信息
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
2、啟動(dòng)類中增加
@EnableConfigServer @SpringBootApplication public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } }
3.yml配置文件
server:
port: 8707
spring:
application:
name: config-server
profiles:
active: native
cloud:
config:
server:
native:
search-locations:
- file:/home/wshop/service/config
#- classpath:/config
# git:
# uri: ssh://git@127.0.0.1:61317/home/git/repo/java/cloud-config
# searchPaths: dev
# lable: master
# strict-host-key-checking: false
# ignore-local-ssh-settings: true
# private-key: |
# -----BEGIN RSA PRIVATE KEY-----
# MIIEpQIBAAKCAQEAx8S2qMyPTZxyw6+OB7PSLRM5WH+e1FPaKiqYwLzj1v0f9yGP
# 2cf41Si8m1y7o/tyaqoNiHbVkWlBvS5Pn6JCD3hlNQxCump2ZG2XqGg46EdDt52E
# PWB2u4flSqzp4hMN+/5ChY1FTCg7IXY6uOxJ3U864MuZ6ChumxfgyYCmLb7mkX+D
# S8vmDqNx5AGn9UscrhhdTuMMyw6HolUMdCQmpSyNyWQWk9caVKOvQlTGKG2nCAah
# apGHShjghpCsASGo+qk7/af/ZrRoJEj2eeu8MCLBcdyd5MOZhf/xr3wCXIZItxCJ
# P2qyPDg8s6umv6oW7nsKsy0qUcovZTqp1XkAawIDAQABAoIBABsuO8Ap3RGtSLwx
# ZbzMjbtOU04kRyMSqat1EkWfLczxsei5K05xc/zkxwzIiEteignTS3YW3SYk0SoB
# ZBoPRLfAJN0b5vRgSe2OL8VdMOkB0UfpabXEK0OG0P7hGg2FlDCGPtzXBOfAzZLW
# +FRy6fXvss4lRbKd1bbKf+5Kz9GHWy8gKWnpm9CXhnGvqCrxMkkBWuDOwpRK8VSx
# NIUj6wZwtpSOqWJPLzB3ZCrLKhFxmaHA8cYZdiFp/5P/N5Hq+9zy+uFReCfhcr33
# d7KgLnD1hnQdkuY7O2Jg9PTJUlxb41+W0WY4ZYW5igvtk8zirperuLbeHBbpQvsx
# 6CBx8akCgYEA9WZP9MF/joMHdtt0Mn663ycL9PEA233psnLghxeKNXR/n22MtK9Y
# CAnHO9mNiBp7nUUDKRtGwsUytUQt0BcuhikxisY+WoeKv1lmLperz6Qv7n4TTN3D
# 7edX6lQVLV8Q0k26Cf6kKEf9Noy0Utz8AWEMzK9XwMzIVa5+RB14t9cCgYEA0GXM
# z3MZvEe7IQnQGNvWzRFZ3lQEmpOUzzluOj+fBNh9A8v4+U5GAw7QQop5L5//rD7n
# 7DUhl5BoZOhUzdBTQr6q4rs05EBphPrwZgpGGDWXmmBzMD88fM5j1bKOC2c3ZqLs
# TVOdWTsj+iNqvxnfvMYB6U5PdM06wVObM0Q+WY0CgYEAqOlxo7EE0d1S5/cKNi+R
# stbDfNooI8Rx7a7WA26WMHOzuf5uyaeulNiYZf34dR86X6ak0xv98szUTE8XP5R1
# kP5LowgWKQFskV3CEiQLKCHodU7omUI1p91M99IBvQzu87A6ffm7cW8=
# -----END RSA PRIVATE KEY-----
eureka:
client:
serviceUrl:
defaultZone: http://127.0.0.1:8700/eureka/
registry-fetch-interval-seconds: 10
healthcheck:
enabled: true
instance:
lease-expiration-duration-in-seconds: 10
lease-renewal-interval-in-seconds: 10
4.在linux目錄“/home/wshop/service/config”下增加共享配置文件“base-dev.yml”:
文件內(nèi)容比如:
# 配置hystrix
feign:
hystrix:
enabled: true
ribbon:
ReadTimeout: 400000
ConnectTimeout: 400000
# 配置hystrix
hystrix:
metrics:
enabled: true
threadpool:
default:
coreSize: 101 #線程池核心線程數(shù)
command:
default:
execution:
isolation:
thread:
timeoutInMilliseconds: 400000 #超時(shí)時(shí)間,如果超時(shí),則實(shí)現(xiàn)服務(wù)降級處理
circuitBreaker:
requestVolumeThreshold: 100 #當(dāng)在配置時(shí)間窗口內(nèi)達(dá)到此數(shù)量后,進(jìn)行短路。默認(rèn)20個(gè)
sleepWindowInMilliseconds: 5000 #短路多久以后開始嘗試是否恢復(fù),默認(rèn)5s
errorThresholdPercentage: 50% #出錯(cuò)百分比閾值,當(dāng)達(dá)到此閾值后,開始短路。默認(rèn)50%
management:
endpoint:
health:
show-details: always
web:
exposure:
include: hystrix.stream
4.run腳本啟動(dòng),并訪問測試
run腳本范例:
#!/bin/bash ######################################################################### # File Name: run.sh # Function: # Author: Mason # Version: V1.0 # Created Time: 28/1/2019 11:41:48 ######################################################################### # chkconfig: - 98 33 # description: Starts and stops the java project daemon \ # used to provide some java jar packet services. source /etc/profile # base env parameters setting BASEDIR=$(dirname $(readlink -f $0)) APPNAME=config-server VERSION=1.0.0 JAVAOPT="-Xms256m -Xmx512m -XX:PermSize=128M -XX:MaxPermSize=256M" # define some functions get_pid(){ PID=$(ps -ef|grep ${APPNAME} |grep "java" |grep -v grep |awk '{print $2}') } start(){ if [ -z ${PID} ];then nohup java ${JAVAOPT} -Dlogging.config=${BASEDIR}/logback-spring.xml -D$APPNAME -jar ${BASEDIR}/${APPNAME}-${VERSION}.jar --spring.config.location=${BASEDIR}/application.yml &>/dev/null & inter=1 time=10 i=0 while ((i < time));do get_pid #if [ $(netstat -lntup|grep -c $PID) -le 1 ];then if((i>(time-2)));then if [ ${PID} ];then echo "${APPNAME} started OK." break else sleep ${inter} let i++ fi else sleep ${inter} let i++ fi done if ((i == time));then echo "${APPNAME} started FAIL in $((inter*time)) second!" exit 1 fi else echo "${APPNAME} is still running with pid ${PID}!" exit 1 fi } stop(){ if [ ! -z ${PID} ];then kill -9 ${PID} && echo "${APPNAME} was killed." else echo "${APPNAME} is not running!" exit 1 fi } restart(){ stop start } status(){ if [ ! -z ${PID} ];then echo "${APPNAME} is running with pid ${PID}" else echo "${APPNAME} is not running." fi } # the main program started get_pid case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status ;; *) echo $"Usage: $0 {start|stop|restart|status}" exit 2 esac exit $?
http://192.168.60.235:8707/base-dev.yml
說明服務(wù)端已經(jīng)啟動(dòng)成功;
二、客戶端
1.在linux目錄“/home/wshop/service/config”下增加共享配置文件“bootstrap.yml”:
其內(nèi)內(nèi)容如下:
spring:
cloud:
config:
uri: http://127.0.0.1:8707/ #Config server的uri
profile: dev #指定的環(huán)境
name: base
啟動(dòng)客戶端應(yīng)用jar中增加配置:
/home/wshop/service/config/bootstrap.yml
完整啟動(dòng)命令:
nohup java ${JAVAOPT} -Dlogging.config=${BASEDIR}/logback-spring.xml -D$APPNAME -jar ${BASEDIR}/${APPNAME}-${VERSION}.jar --spring.config.location=${BASEDIR}/application.yml,/home/wshop/service/config/bootstrap.yml &>/dev/null &
重新啟動(dòng)客戶端,即實(shí)現(xiàn)客戶端應(yīng)用接入配置中心功能。
上述就是小編為大家分享的微服務(wù)spring-cloud 配置中心config-server本地化部署是怎樣的了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享名稱:微服務(wù)spring-cloud配置中心config-server本地化部署是怎樣的
網(wǎng)址分享:http://www.rwnh.cn/article38/jijjsp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、網(wǎng)頁設(shè)計(jì)公司、響應(yīng)式網(wǎng)站、定制開發(fā)、網(wǎng)站排名、外貿(mào)網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)