./startup.sh -m standalone
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
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:
gRPC: A high-performance, cross-language RPC framework developed by Google, using Protocol Buffers (protobuf) as the default serialization protocol.
Apache Dubbo: A Java-based high-performance, lightweight RPC framework that provides rich functions and pluggable extension points.
Apache Thrift: A cross-language RPC framework developed by Apache that supports multiple programming languages and provides rich data types and service definitions.
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:
Choose an RPC framework that suits your needs, and add related dependencies to the project.
Configure and implement the server and client according to the documentation and examples of the RPC framework.
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:
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.
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.
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.
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.
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.
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.
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
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
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
Upload the downloaded sentinel-dashboard-1.7.2.jar
package 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
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/sentinel
in 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
create container
docker run --name sentinel -p 8081:8081 -p 8719:8719 -d sentinel-dashboard:1.8.4
docker ps
docker start sentinel
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();
Add the group to contact the author vx: xiaoda0423
Warehouse address: https://github.com/webVueBlog/JavaGuideInterview