In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about the use of Nacos and the creation of gateway centers. The article is rich in content and analyzed and described from a professional point of view. I hope you can get something after reading this article.
1. Brief introduction to Nacos1.1
Nacos can be used to discover, configure, and manage microservices. It provides a set of easy-to-use feature sets that can quickly implement dynamic service discovery, service configuration, service metadata and traffic management.
Nacos is used to build, deliver, and manage micro-service platforms more quickly and easily. Nacos is the service foundation setting for building modern application architecture with "service" as the center, such as micro-service paradigm and cloud native paradigm.
This is what we usually call the configuration center and the service discovery center.
1.2 build and start
The current version of Nacos does not support the creation of services in the form of Spring boot. It must be run separately as a Java package or as a Docker service. Let's talk about running locally.
Download the installation package:
Curl https://github.com/alibaba/nacos/releases/download/1.2.1/nacos-server-1.2.1.zip
Unzip nacos-server-$version.zip or tar-xvf nacos-server-$version.tar.gz
Cd nacos/bin
Install using source code:
Git clone https://github.com/alibaba/nacos.git
Cd nacos/
Mvn-Prelease-nacos-Dmaven.test.skip=true clean install-U
Ls-al distribution/target/
/ / change the $version to your actual path
Cd distribution/target/nacos-server-$version/nacos/bin
Start:
Linux/Unix/Mac
Start command (standalone stands for stand-alone mode, non-cluster mode):
Sh startup.sh-m standalone
If you are using a ubuntu system, or if you run the script with an error [[symbol not found, try the following:
Bash startup.sh-m standalone
Windows
Start the command:
Cmd startup.cmd
Or double-click startup.cmd to run the file.
2. Spring Cloud Gateway
For the entire gateway service, we use Spring Cloud Gateway. In Spring Cloud microservices, the whole system only exposes the gateway, while other services are not visible to the public. So we need to set up a gateway service that we can use.
Create a gateway directory under nature/manager and add pom.xml:
Club.attachie
Manager
${revision}
4.0.0
Club.attachie
Gateway
Jar
${revision}
Register the module under manager:
Gateway
2.1 add Gateway
After you create the completed project, you need to add a dependency package:
Org.springframework.cloud
Spring-cloud-starter-gateway
In the gateway project, create the following directory:
├── pom.xml
└── src
└── main
├── java
│ └── club
│ └── attachie
│ └── gateway
│ └── SpringGatewayApplication.java
└── resources
└── bootstrap.yml
Create the SpringGateAppliction.java file as follows:
Package club.attachie.gateway
Import org.springframework.boot.SpringApplication
Import org.springframework.boot.autoconfigure.SpringBootApplication
Import org.springframework.cloud.client.discovery.EnableDiscoveryClient
Import org.springframework.cloud.context.config.annotation.RefreshScope
/ * *
* @ author attaching
, /
@ SpringBootApplication
@ EnableDiscoveryClient
@ RefreshScope
Public class SpringGatewayApplication {
Public static void main (String [] args) {
SpringApplication.run (SpringGatewayApplication.class, args)
}
}
Create a bootstrap.yml under the resource directory:
Spring:
Application:
Name: gateway
Yml is a configuration file format for Spring, where the names application and bootstrap,bootstrap are loaded before application.
2.2 add nacos
First add the nacos version number to nature/pom.xml:
2.2.1.RELEASE
Then add nacos related dependency management under dependencyManagement > dependencies:
Com.alibaba.cloud
Spring-cloud-starter-alibaba-nacos-discovery
${nacos.version}
Com.alibaba.cloud
Spring-cloud-alibaba-starters
${nacos.version}
In the Gateway project, pom.xml adds:
Com.alibaba.cloud
Spring-cloud-starter-alibaba-nacos-discovery
Com.alibaba.cloud
Spring-cloud-starter-alibaba-nacos-discovery
Then go back and set it in bootstrap:
Spring:
Application:
Name: gateway
Cloud:
Nacos:
Config:
Server-addr: 127.0.0.1 server-addr 8848 this is what the editor shares about the creation of a Nacos and gateway center. 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.