Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the localization deployment of microservice spring-cloud configuration center config-server

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about the localization deployment of microservice spring-cloud configuration center config-server. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

1. Server side: need to add configuration center server config-server project

1. Pom.xml adds relevant configuration information.

Org.springframework.cloud spring-cloud-config-server

2. Add to startup class

@ EnableConfigServer@SpringBootApplicationpublic class ConfigServerApplication {public static void main (String [] args) {SpringApplication.run (ConfigServerApplication.class, args);}}

3.yml profile

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. Add the shared configuration file "base-dev.yml" under the linux directory "/ home/wshop/service/config":

The contents of the file include:

# configure hystrix

Feign:

Hystrix:

Enabled: true

Ribbon:

ReadTimeout: 400000

ConnectTimeout: 400000

# configure hystrix

Hystrix:

Metrics:

Enabled: true

Threadpool:

Default:

CoreSize: number of core threads in the thread pool

Command:

Default:

Execution:

Isolation:

Thread:

TimeoutInMilliseconds: 400000 # timeout. If the timeout occurs, service degradation will be implemented.

CircuitBreaker:

RequestVolumeThreshold: 100 # when this number is reached within the configuration time window, short circuit is performed. Default is 20.

SleepWindowInMilliseconds: 5000 # how long after the short circuit starts to try whether to recover or not? default is 5s.

ErrorThresholdPercentage: 50% # error percentage threshold, when this threshold is reached, the short circuit begins. Default 50%

Management:

Endpoint:

Health:

Show-details: always

Web:

Exposure:

Include: hystrix.stream

The 4.run script starts and accesses the test

Sample run script:

#! / bin/bash#### File Name: run.sh# Function:# Author: Mason# Version: V1.0# Created Time: 28/1/2019 11:41:48# # chkconfig:-98 3 hours description: Starts and stops the java project daemon\ # used to provide some java jar packet services.source / etc/profile# base env parameters settingBASEDIR=$ (dirname $(readlink-f $0) ) APPNAME=config-serverVERSION=1.0.0JAVAOPT= "- Xms256m-Xmx512m-XX:PermSize=128M-XX:MaxPermSize=256M" # define some functionsget_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 iTun0 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 iTunes + fi else sleep ${inter} let iTunes + 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 startedget_pidcase "$1" in start) start;; stop) stop;; restart) restart;; status) status; *) echo $"Usage: $0 {start | stop | restart | status}" exit 2esacexit $?

Http://192.168.60.235:8707/base-dev.yml

It indicates that the server has started successfully.

II. Client

1. Add the shared configuration file "bootstrap.yml" under the linux directory "/ home/wshop/service/config":

The contents are as follows:

Spring:

Cloud:

Config:

Uri: uri of http://127.0.0.1:8707/ # Config server

Profile: environment specified by dev #

Name: base

Start the client application jar to add the configuration:

/ home/wshop/service/config/bootstrap.yml

Full launch command:

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 &

Restart the client, that is, to achieve the client application access configuration center function.

This is what the microservice spring-cloud configuration center config-server localization deployment is like. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report