当前位置:网站首页>Nacos installation and service registration

Nacos installation and service registration

2022-07-06 09:08:00 look-word

Nacos Installation of and registration of services

We all know naocs It's a registry , So what is the Registration Center ?

  • What is a registry ?
    • It is similar to an intermediary role ( Free conscience intermediary ), Play the role of a link in microservices , It provides the mapping relationship between service and service address , The producer registers the service name and address here , consumer according to The service name Get a response Access address .
  • Why use the registry
    • When there is no registry , The caller needs to know when invoking the service domain name and port , When modified by the caller , You need to change the code , When there are many services called , Then we need to modify a lot of code , It is undoubtedly increasing our workload .

So how does he work on earth ?

working principle :

  1. producer ( Service providers ) Register your domain name and port with the registry
  2. Consumers pull the service list from the Registration Center , And make a remote call
  3. The registration center and service providers ensure that services can be provided normally by regularly checking the heartbeat

img

Nacos Prepare before use

nacos download

Download after decompression We need to get into bin Directory start nacos service Do not double-click to start

naocs It will be java Written stay target Under the table of contents You can see jar file

img

start-up :

In the search bar above Input cmd Enter the black window

command :startup.cmd -m standalone

img

When the bottom appears Program start time Just explain Successful launch

img

We came to the browser Input localhost:8848 You can see naocs The running interface We will carry out a series of configurations in it

  • The username and password are both naocs

img

All the services we register will appear in List of services in , Services can be offline and other operations !

img

Service registration

nacos There are three steps in the registration process

  • Add dependency
  • To configure nacos
  • Start the service
Add dependency
        <!-- Service registration  -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

To configure nacos

# Spring
spring: 
  application:
    #  apply name 
    name: project-xxxx 
  cloud:
    nacos:
      discovery:
        #  Service registration address  ip Add slogan 
        server-addr: 127.0.0.1:8848

Start the service

You can see , The service just started has appeared in the service list

img

原网站

版权声明
本文为[look-word]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060847221729.html