Building Seata Server and Nacos Server (Mall 7)

Insert image description here

1. Introduction to Nacos

(1) What is Nacos

1. Nacos is the abbreviation of Dynamic Naming and Configuration Service. In comparison, it is easier to build a dynamic service discovery, configuration management and service management platform for cloud native applications.
2. Nacos helps you discover, configure and manage microservices. Nacos provides a simple and easy-to-use feature set to help you quickly implement dynamic service discovery, service configuration, service metadata and traffic management.
3. Nacos helps you build, deliver and manage microservice platforms more agilely and easily. Nacos is a service infrastructure for building modern application architecture centered on "services" (such as microservice paradigm, cloud native paradigm).

(2) Why Nacos is needed

In the early days of software development, enterprises still relied on the traditional monolithic application architecture, packaging all functions into an application service for deployment. As the business system continues to develop and expand, the disadvantages of the monolithic application architecture are becoming increasingly apparent.
It would be great if a large application service could be split into several sub-services according to different dimensions and fields. Each business team only needs to focus on the services they are responsible for and carry out development and deployment iterations without affecting each other. Therefore, the traditional unit application architecture began to evolve towards the microservice architecture. The first question in the evolution process is how do microservices find each other and call each other? We call this ability to discover and call each other microservice registration discovery. Nacos has this microservice registration and discovery capability.
As one of the current mainstream service registration, discovery and configuration centers, Nacos has become the first choice for domestic developers and has a broad mass base.
The CSE service registration discovery configuration center engine service-center currently supports SpringCloud Huawei and ServiceComb microservice frameworks. The current domestic mainstream frameworks are based on SpringCloud Alibaba, Dubbo, etc. These frameworks integrate Nacos as the registration discovery configuration center.
In order to embrace the registration discovery and configuration center of the open source system, improve the competitiveness of CSE, and attract more users, CSE has added the feature of supporting hosted Nacos clusters.

(3) Key features of CSE Nacos

  1. Health Check
    Provides two health check mechanisms: health check of temporary instances and health check of permanent instances. A temporary instance is a microservice in which the client actively sends a heartbeat to the server to tell the server "I am still alive". If the client and the server "lost contact", the server actively logs off the client lock registration. For a permanent instance, the server actively detects whether the client is "alive". If the detection fails, the microservice is offline.
  2. Service management
    supports Rest-based and gRPC-based service discovery, with long connection capabilities.
    Support management of services. Search services, query service details, create services, and delete services based on service names and group names.
    Supports setting service instance weight. The greater the weight, the greater the traffic allocated to the instance.
    Supports setting service protection thresholds, realizing flow control of microservice calls, and ensuring service availability. As a service registration discovery center, CSE Nacos will only return healthy service provider instances to service consumers under normal circumstances. When user application visits surge, all calls will only be forwarded to healthy instances, which may lead to the collapse of the service. Avalanche effect. By setting the protection threshold, CSE Nacos will trigger the protection mechanism when the number of healthy instances/total number of instances <= the protection threshold and forward some requests to unhealthy service provider instances to achieve the flow limiting effect. Although some traffic is lost, Guaranteed service availability.
    The range of the protection threshold is a floating point number of 0-1, 0 means that the threshold protection will not be triggered no matter what, and 1 means the threshold protection will be triggered no matter what.
  3. Configuration management
    supports the creation, deletion, import and export of configuration files, and supports multiple configuration file formats. When the user's microservice application system is complex and large, it may have a large number of configuration files, and even the configuration files are in various formats. Using the import and export function can help users conveniently set configuration items and quickly migrate applications to CSE.
    Supports monitoring and querying of configurations. The client can proactively discover changes in configuration files, re-read the contents of the configuration files, and take effect in seconds. This enables hot updates of configurations without the need to redeploy applications and services, making configuration management more efficient and agile.
    Supports configuration version management and can roll back to historical versions.
  4. Subscriber query
    supports querying service subscribers, helping users better maintain subscription relationships in management services.
  5. Namespace management
    supports addition, deletion, modification, and query of namespaces for tenant-granular configuration isolation. Configurations of the same Group or Data ID can exist in different namespaces. One of the common scenarios for namespaces is the differentiation and isolation of configurations in different environments, such as the isolation of resources (such as configurations and services) between development and testing environments and production environments.
    Specifications of CSE Nacos

2. Nacos server configuration

(1) Download nacos version 1.4.1

(2) Configure mysql

1. Log in to mysql using root
Insert image description here

2. Use the create database command to create a database and write the database command to be created into Notepad.

Insert image description here

3. Paste the command in Notepad into the mysql command window
Insert image description here

4. show database; view the existing database list
Insert image description here

5. Execute mysql
Insert image description here
Insert image description here

(3) Modify the configuration file and connect to the database

1. Check the network card IP address
Insert image description here

2. Change the current directory to nacos
Insert image description here

3. Find the file application-properties in the directory
Insert image description here

4. Vi application-properties, find the server address corresponding to mysql, and change it to the locally configured mysq address.
Insert image description here

5. The modified result is as shown below:
Insert image description here

(4) Liunx startup

1. Check the files in the bin directory and find startup.sh
Insert image description here

2. Before executing the following command, check whether startup.sh is executable. If not, execute chmod +x startup.sh
(1) Execute startup.sh
Insert image description here

(2) Use the command chmod +7 *.sh to configure permissions
Insert image description here

3. Enter nacos\nacos-server-1.4.1\nacos\bin and execute nacos
nohup bash startup.sh -m standalone & in the background.
Insert image description here

4. Check whether the firewall on the nacos server has opened port 8848.
(1) If the connection fails, the port is not opened.
Insert image description here

(2) Use the netstat –ano command to check the opened port numbers, as shown below:
Insert image description here

5. Use the command to open port 8848
Sudo firewall-cmd –add-port=8848/tcp --permanent
Insert image description here

6. Access address http://XXXX:8848/nacos Default account password nacos yuanfeng021
(1) A login box will appear when accessing, as shown below:
Insert image description here

(2) Enter the user name and password nacos yuanfeng021. After logging in, as shown below:
Insert image description here

In the picture above, the configuration pro has been created and the .xml configuration file has been added. At this point, the Nacos server is set up.

2. Seata configuration

(1) What is Seata

Seata is an open source distributed transaction solution dedicated to providing high-performance and easy-to-use distributed transaction services. Seata will provide users with AT, TCC, SAGA and XA transaction modes to create a one-stop distributed solution for users.
1. Distributed transactions
A business operation needs to span multiple data sources or require remote calls across multiple systems, which will cause distributed transaction problems.
In a distributed system environment, transactions completed by remote collaboration between different services through the network are called distributed transactions. For example, creating order minus inventory transactions, bank transfer transactions, etc. are distributed transaction
cases: user placing orders, designing order database to add order data, inventory database to reduce inventory information; account database to reduce amount operations, involving 3 databases, 2 times Remote calls have obvious distributed transaction problems.
2. The role and components of seata
Seata is a solution for solving distributed transactions and is committed to providing high-performance and easy-to-use distributed transaction services under a microservice architecture.
Insert image description here

(2) Seata working mode

1. AT mode
Premise
(1) Based on a relational database that supports local ACID transactions.
(2) Java application, accessing the database through JDBC
2. TCC mode
Review the description in the overview: a distributed global transaction, the whole is a two-phase commit model. The global transaction is composed of several branch transactions. The branch transaction must meet the two-stage commit model requirements, that is, each branch transaction needs to have its own:
(1) One-stage prepare behavior
(2) Two-stage commit or rollback behavior
3. Saga mode
Saga mode is a long transaction solution provided by SEATA. In Saga mode, each participant in the business process submits a local transaction. When a participant fails, the previous successful participants are compensated. One stage is forward. Both services and second-stage compensation services are implemented by business development.

(3) Applicable scenarios:

The business process is long and there are many business processes. Participants include other companies or legacy system services, which cannot provide the three interfaces required by the TCC model.

(4) Advantages:

Submit local transactions in one phase, lock-free, high performance. Event-driven architecture, participants can execute asynchronously and achieve high throughput. Compensation services are easy to implement

(5) Disadvantages:

No guarantee of isolation

(6) Configure seata server

1. Find the configuration target conf
Insert image description here

2. Change the current directory to conf, as shown below:
Insert image description here

3. Modify file.conf to the data link where mysql is located, as shown below:
Insert image description here

Mainly modify the line:
url =”jdbc:mysql://192.168.0.131:3306”
user=”root”
password=”root”
registry.conf Modify the nacos access address
4. Modify the registry.conf registration configuration file and change it to nacos username and password.
Insert image description here

5. Start the seata server
(1) Check whether seata-server.sh is executable before executing the following command, as shown below:
Insert image description here

(2) The above figure shows that the definition of JAVA_HOME is incorrect. You need to check the setting of JAVA_HOME and the installation path of JDK.
(3) If it cannot be executed, grant permissions to seata-server.sh, as shown below:
chmod +7 seata-server.sh
Insert image description here

6. Start the seata server in the background
(1) nohup ./bin/seata-server.sh -p 8091 -h XXX.XXX.XXX -m file >nohup.out 2>1 &
Note: XXX.XXX Change .XXX to your own server IP and execute as shown below:
Insert image description here

(2) There is no error prompt after the execution is completed, as shown below:
Insert image description here

7. Check the seata log to display the log information, as shown below:
Insert image description here

At this point, the seata service is started.

Guess you like

Origin blog.csdn.net/weixin_43075093/article/details/135016856