Standalone is configured and the database is also configured, but Nacos still fails to start

Problem found:

When I was learning Nacos today, I downloaded, installed and decompressed the Nacos package. I downloaded the latest version of Nacos 2.2.1 at present (2023.3.27), but at startup, whether it is using the official command "startup.cmd - m standalone" or directly double-click "startup.cmd" will crash, and the natural startup will also fail.

Solve the window flashback problem:

Then I searched for information and found that I need to add at the end of "startup.cmd":

pause
endlocal

This way the window will not flash back.

View exception information:

After the window flashback problem is solved, you can see the complete exception information. My error message is very long. There are about six or seven paragraphs of error. I can only read it from the beginning. The first paragraph of error is (very long, I only put the key typed out in code):

 ERROR Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException.

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat

Solution steps:

1. Configure standalone:

 Of course, I can't understand it myself, but it literally means that there is a problem with Tomcat startup, so I can only search for "Unable to start embedded Tomcat", so the following results appear:

 The general meaning is: the default startup mode of Nacos is cluster startup, but we personally only have one host, so we should choose the stand-alone startup mode, so it needs to be reconfigured. For details, please refer to the article: http://t.csdn.cn/uDVW7 , the blogger also said the second error: "Failed to create database '/data/soft/nacos/data/derby-data'", But I haven't encountered it, so I won't go into details here. If you need it, you can read the article in the link above.

before fixing:

After modification:

 

 So far, the startup mode has been modified, but the startup error report has not been reduced, which is very annoying.

2. Configure the database (I personally think that you can not modify it, but I still write it out for your reference):

Then I saw the second answer:

 It means that there is a database file in the configuration file/conf, so the reason for the error may be that the corresponding database environment is required when Nacos starts, you can refer to the article: http://t.csdn.cn/NfXbj and http ://t.csdn .cn/b0rYp , the second article is more detailed, you can refer to it, but my package is different from the one he gave:

He gave:

mine: 

My steps are given below:

Open Navicat; create a new database (I don’t know if the name can be created casually, because some answers are to create a new database casually, but the blogger above mentioned "Nacos", so I also used "Nacos", after all. It looks more professional); then run mysql-schema.sql, although the name of the running file is different from that of the above blogger, but I saw that the built table is the same; modify the conf/application configuration file:

 Circle this part and change it to the user name and password of your own database.

It's over, but the error report still hasn't decreased.

3. Check whether the port is occupied:

It is very distressing, because there are only the above two answers in a lot of information I found, I thought that my problem might be a niche problem, could it be that my computer port 8848 (the default port of Nacos) is occupied , so I checked my port usage:

Open cmd->enter the netstat -ano command->find the port number, the port number is after the colon after the local address ip (the part circled below):

If you want to find a specific port number, you can use the netstat -ano | findstr "port number" command. Unfortunately, after careful inspection, I found that the port is not occupied.

4. Positive solution: Modify the Key value in the configuration file:

Because I learned by watching the springcloud video of Dark Horse 2021, the Nacos version they use is still 1.x, I think it may be some problems with the new version, so I plan to give up using the latest version and use 1 in the supporting materials .x version, but when I was about to close the cmd black window, I saw the last error message:

Caused by: java.lang.IllegalArgumentException: The specified key byte array is 0 bits which is not secure enough for any JWT HMAC-SHA algorithm.  The JWT JWA Specification (RFC 7518, Section 3.2) states that keys used with HMAC-SHA algorithms MUST have a size >= 256 bits (the key size must be greater than or equal to the hash output size).  See https://tools.ietf.org/html/rfc7518#section-3.2 for more information.
        at com.alibaba.nacos.plugin.auth.impl.jwt.NacosJwtParser.<init>(NacosJwtParser.java:56)
        at com.alibaba.nacos.plugin.auth.impl.token.impl.JwtTokenManager.processProperties(JwtTokenManager.java:71)
        ... 115 common frames omitted

I googled this error with the attitude of giving it a try, and saw the following answer: 

 

 It means: the key used to generate the JWT token in the new version (after 2.x) Nacos configuration file defaults to a null value, you need to set it in the conf/application file yourself, and you can set it to the official default value: SecretKey012345678901234567890123456789012345678901234567890123456789 , You can also set it yourself. When customizing the key, it is recommended to set the configuration item to a Base64-encoded string, and the length of the original key should not be less than 32 characters. You can refer to the article: http://t.csdn.cn/cdtH8 . I went to the official documentation, and the official documentation says this:

Modify the files confin the directory application.properties.

Set the value, see Authentication-Custom Keynacos.core.auth.plugin.nacos.token.secret.key for details .

Note that the default values ​​in the document are public default values SecretKey012345678901234567890123456789012345678901234567890123456789​​and can be used for temporary testing. Please be sure to replace them with other valid custom values VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=​​in actual use .

The official strongly recommends customizing the key, but you can actually use the default value above. I will use the default value to show you the modified place, which is actually the file confin the directory application.properties:

 After the modification, double-click "startup.cmd", and finally it can start normally:

 Hold down Ctrl and click the URL circled above, you can also jump to the Nacos configuration management page normally:

 I have logged in, and the first successful jump is to jump to the login page. The default user name and password are both: "nacos", and you can reach the above page after logging in.

Summarize:

In fact, this problem can be solved quickly by looking at the official documents carefully. However, I have never been in the habit of reading official documents, so I spent a lot of time this time, which can be regarded as a long memory for me.

I think that the configuration of the database can be changed without changing it. Let’s sum it up. For the configuration of stand-alone startup (), the database is also configured, but Nacos still fails to start. Check whether you have configured the files in the directory and set confthe application.propertiesvalue nacos.core.auth.plugin.nacos.token.secret.key. . If this article still can't solve your problem, remember to read the official documentation: Nacos Quick Start .

Guess you like

Origin blog.csdn.net/m0_56680022/article/details/129798194