Springboot Episode 33: nacos diagram

./startup.sh -m standalone

aa310e4a89cf6471628a7daa484ab84e.jpeg

  • Nacos is an internal microservice component that needs to run on a trusted internal network and cannot be exposed to the public network environment to prevent security risks.

  • Nacos provides a simple authentication implementation, a weak authentication system to prevent business misuse, not a strong authentication system to prevent malicious attacks.

authentication

https://nacos.io/zh-cn/docs/v2/guide/user/auth.html

d4cf0efa0d502ff650ac0589bdaf922b.png

3e915d414a077d166bbd3a1b805b7c55.png

6fbc2ba918f49989c4692139e28b173e.png

8e86393ee30f2796b9cf942df0f89c46.png
049511e3d3d09ccfcb0512fab2520c2d.png

d7d5aebf4574ec2584aed34d445bae2f.png
image.png
c7f3369eda3557a8b0cf60a5fa93cda7.png
image.png
5c19d8dd07b321eaa512658158a5bc9c.png
image.png
ceebf8d5f5f497f351c67a599cd7840b.png
image.png
59cc455b9154aa5673bf3865577a55e6.png
image.png
6039f106b15c761ff4f96a8b6e8da540.png
image.png
4f994a826df3452187fca1be80b666bb.png
image.png
f6bbc08adc00a60d958df3c53e504b4f.png
image.png
1ba5bae102d0bad88853c67f188d8fce.png
image.png

In the Spring Boot backend, RPC stands for Remote Procedure Call (Remote Procedure Call). RPC is a communication mechanism that allows programs on different computers or processes to call each other's functions or methods, just like calling local functions.

In a distributed system, RPC is very useful when various parts of the application are distributed on different servers and need to communicate and cooperate with each other. With RPC, applications can send requests to methods or services on remote servers and get results back as if those methods or services were executed locally.

Spring Boot itself does not provide RPC implementation, but it can be integrated with other RPC frameworks, such as:

  1. gRPC: A high-performance, cross-language RPC framework developed by Google, using Protocol Buffers (protobuf) as the default serialization protocol.

  2. Apache Dubbo: A Java-based high-performance, lightweight RPC framework that provides rich functions and pluggable extension points.

  3. Apache Thrift: A cross-language RPC framework developed by Apache that supports multiple programming languages ​​and provides rich data types and service definitions.

  4. Spring Cloud: Although not specifically an RPC framework, it provides the ability to implement RPC-style communication in microservice architectures, for example through RESTful APIs or Feign clients.

To use RPC in a Spring Boot application, you need:

  1. Choose an RPC framework that suits your needs, and add related dependencies to the project.

  2. Configure and implement the server and client according to the documentation and examples of the RPC framework.

  3. Invoke the method of the remote service in the client, send the request to the remote server and process the return result.

It should be noted that RPC usually involves more network communication than local method calls, so network delay and exception handling need to be considered when designing RPC interfaces to ensure system reliability and performance.

Communicating and interacting with hardware is a common requirement in IoT applications. As a back-end framework, Spring Boot can communicate with hardware to realize the function of Internet of Things. The following are the basic steps to implement the Internet of Things in general and the method of back-end processing:

  1. Hardware device selection: First, you need to choose the right hardware device for your IoT project. This could be sensors, actuators, embedded devices, etc., depending on your specific application.

  2. Communication protocol selection: When communicating with hardware, you need to select an appropriate communication protocol. Common communication protocols include MQTT, CoAP, HTTP, etc. You should choose the most suitable protocol according to the characteristics of hardware equipment and network environment.

  3. Connecting hardware devices: In the Spring Boot backend, you can use corresponding communication libraries or frameworks to communicate with hardware devices. For example, if you choose the MQTT protocol, you can use Eclipse Paho or Spring Integration's MQTT support to establish connections with hardware devices.

  4. Design API and data format: Define the API and data format for interacting with hardware devices. This involves how to send commands to the hardware device, and how to parse the data sent back by the hardware device. Use JSON or other lightweight data formats to facilitate data exchange.

  5. Processing data and business logic: Once the connection with the hardware device is established and the API is interacted with, the backend needs to process the data received from the hardware device. You can write corresponding business logic to process these data, such as storing to database, performing real-time analysis, etc.

  6. Security: Security is very important in IoT applications. To ensure that communication with hardware devices is secure, encryption and authentication mechanisms can be used to protect the security of communications.

  7. Exception handling: When communicating with hardware devices, communication failures or other abnormal conditions may occur. The backend needs to handle exceptions well to ensure the stability and reliability of the system.

Sentinel environment

Fuse downgrade components, https://github.com/alibaba/Sentinel/releases

java -Dserver.port=8080 -Dcsp.sentinel.dashboard.server = localhost:8080 -Dproject.name = sentinel-dashboard -jar sentinel-dashboard-1.8.x.jar
0ed785886dc07ef9be7d3c4587393b1c.png
image.png

1. docker install sentinel
docker pull bladex/sentinel-dashboard

2. Start the image
docker run --name sentinel -d -p 8858:8858 -d bladex/sentinel-dashboard

3. Open port
firewall-cmd --permanent --add-port=8858/tcp

4. Login:
http://192.168.1.58:8858/#/dashboard/flow/sentinel-dashboard
The default account password is: sentinel

brew install redis

brew services restart redis

ps -ef|grep redis

7458be5952a8a5e0b8ae369048f7ecbc.png
image.png
cd /Users/xiaolige/app
## 创建 redis master 节点配置文件目录
mkdir -p redis/redisSentinel/master
## 创建 redis slave 节点配置文件目录
mkdir -p redis/redisSentinel/slave
## 创建 redis sentinel 节点配置文件目录
mkdir -p redis/redisSentinel/sentinel
## 创建 redis 启动相关脚本目录
mkdir -p redis/redisSentinel/script
## 创建 redis 日志目录
mkdir -p redis/redisSentinel/logs
a60b49e1d6fed703ddd32d8a42d5a0fb.png
image.png

Upload the downloaded sentinel-dashboard-1.7.2.jarpackage to the server /usr/local
and enter the /usr/local directory to start

cd /usr/local

Start Sentinel

Start the sentinel console directly

java -jar sentinel-dashboard-1.7.2.jar

Start as a background process

nohup java -jar sentinel-dashboard-1.7.2.jar >sentinel.log &

Manage Sentinels

Browser access:http://localhost:8080

Default account password
Account: sentinel
Password:sentinel

nacos is starting with standalone

./startup.sh -m standalone

nacos is starting,you can check the /Users/jeskson/Downloads/nacos/logs/start.out

901948bcaf881c44b2e98618bb87c59c.png
image.png
9de79ab6d0f70311f1eb33c0215c0d45.png
image.png

Docker install Sentinel (Mac)

java -jar sentinel-dashboard-1.8.6.jar

startup.cmd -m standalone

Pull dependent java:8-alpine image

docker pull java:8-alpine

Create Dockerfile

Create a Dockerfile under the directory  /Users/xxx/docker/sentinel(customized as needed) and authorize

sentinel % pwd /Users/luyou/docker/sentinel

sentinel % touch Dockerfile # authorized directory

chmod -R 777 sentinel

cd sentinel

will be  sentinel-dashboard-1.8.4.jar placed  /Users/xxx/docker/sentinelin the directory

FROM java:8-alpine
COPY ./sentinel-dashboard-1.8.4.jar /tmp/sentinel-dashboard-1.8.4.jar
EXPOSE 8081 8719
ENTRYPOINT java -Dserver.port=8081 -Dcsp.sentinel.dashboard.server=localhost:8081 -Dproject.name=sentinel-dashboard -jar /tmp/sentinel-dashboard-1.8.4.jar

docker build . -t sentinel-dashboard:1.8.4

226b6ca77f985efb104273ae25da88a2.png

create container

docker run --name sentinel -p 8081:8081 -p 8719:8719 -d sentinel-dashboard:1.8.4

docker ps

docker start sentinel

f07ad46c55a8890b3b7fccb7e14b20be.png
image.png

docker stop sentinel

docker rm sentinel

docker logs -f sentinel

into the container

docker exec -it sentinel bash

exit container

exit

Docker install Seata

Docker install Nacos

Docker install Mongodb

Docker install RabbitMQ

java -jar sentinel-dashboard-1.8.6.jar

nslookup github.com 8.8.8.8

java -jar -Dserver.port=8080 sentinel-dashboard-1.8.6.jar

java -jar -Dserver.port=8718 sentinel-dashboard-1.8.6.jar

./startup.sh -m standalone

http://localhost:8848/nacos/#

8718

问题 异常提示:JWT signature does not match locally computed signature. JWT validity cannot be asserted and should not be trusted.

Meaning in Chinese: The JWT signature does not match the locally computed signature. JWT validity cannot be asserted and JWT validity should not be trusted.

The solution to this exception is:

1. The key used to generate the token is inconsistent with the key used to verify the signature. Use the breakpoint to debug to check whether the keys in the two places are consistent.

2. The token used for signature verification is wrong. Check whether the generated token is consistent with the returned token by means of a break point.

public static void addAuthentication(HttpServletResponse res, String username, String role) {
  String JWT = Jwts.builder()
    .setSubject(username)
    .setExpiration(new Date(System.currentTimeMillis() + EXPIRATIONTIME))
    .claim("roleName", role)
    .signWith(SignatureAlgorithm.HS512, SECRET)
    .compact();
  res.addHeader(HEADER_STRING, TOKEN_PREFIX + " " + JWT);
}
// parse the token.
Claims body = Jwts.parser()
  .setSigningKey(SECRET)
  .parseClaimsJws(token.replace(TOKEN_PREFIX, ""))
  .getBody();
String username = body.getSubject();
0e5af9da4660c4044b1b0d41f7607c3d.jpeg
image.png

Add the group to contact the author vx: xiaoda0423

Warehouse address: https://github.com/webVueBlog/JavaGuideInterview

Guess you like

Origin blog.csdn.net/qq_36232611/article/details/132062360
33