SoFunction
Updated on 2025-03-08

Solve the problem of nacos error:

Nacos error:

Problem background

Use LoadBalancerClient to report an error:

:
    at (:382) ~[na:1.8.0_221]
    at (:424) ~[na:1.8.0_221]
    at $(:349) ~[na:1.8.0_221]

Solution

1 The class cannot be found, which means that this dependency is not introduced. Then I looked at the introduction of nacos, but many dependencies have been excluded. This core is excluded, so an error is reported.

                <exclusion>
                    <artifactId>archaius-core</artifactId>
                    <groupId></groupId>
                </exclusion>

2 The normal introduced dependencies, because many other things are introduced, they are excluded, and many of them are removed according to their own needs.

        <dependency>
            <groupId></groupId>
            <artifactId>spring-cloud-alibaba-nacos-discovery</artifactId>
            <version>2.2.</version>
            <exclusions>
                <exclusion>
                    <artifactId>guava</artifactId>
                    <groupId></groupId>
                </exclusion>
                <exclusion>
                    <artifactId>HdrHistogram</artifactId>
                    <groupId></groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-cloud-commons</artifactId>
                    <groupId></groupId>
                </exclusion>
                <exclusion>
                    <artifactId>commons-codec</artifactId>
                    <groupId>commons-codec</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>commons-lang3</artifactId>
                    <groupId></groupId>
                </exclusion>
                <exclusion>
                    <artifactId>httpclient</artifactId>
                    <groupId></groupId>
                </exclusion>
                <exclusion>
                    <artifactId>spring-cloud-starter</artifactId>
                    <groupId></groupId>
                </exclusion>
            </exclusions>
        </dependency>

Common errors in starting nacos

1. Could not find or load main class

Error: Could not find or load main class
Caused by: :

Solution:

x JAVA_OPT_EXT_FIX="-=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
√ JAVA_OPT="${JAVA_OPT} -=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext"
x echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT}"
√ echo "$JAVA ${JAVA_OPT}"
x echo "$JAVA $JAVA_OPT_EXT_FIX ${JAVA_OPT}" > ${BASE_DIR}/logs/ 2>&1 &
x nohup "$JAVA" "$JAVA_OPT_EXT_FIX" ${JAVA_OPT} >> ${BASE_DIR}/logs/ 2>&1 &
√ echo "$JAVA ${JAVA_OPT}" > ${BASE_DIR}/logs/ 2>&1 &
√ nohup $JAVA ${JAVA_OPT} >> ${BASE_DIR}/logs/ 2>&1 &

2. Please set the JAVA_HOME variable in your environment

which: no javac in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
readlink: missing operand
Try 'readlink --help' for more information.
dirname: missing operand
Try 'dirname --help' for more information.
ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! !!

Find the reason:

  • Enter echo $JAVA_HOME and the result is empty
  • Indicates that no java environment variables are configured

Solution:

  • Configuring JAVA environment variables

2.1 Find the jdk installation path

[root@localhost bin]# ls -lrt /usr/bin/java
lrwxrwxrwx 1 root root 22 Mar 15 09:59 /usr/bin/java -> /etc/alternatives/java
[root@localhost bin]# ls -lrt /etc/alternatives/java
lrwxrwxrwx 1 root root 73 Mar 15 09:59 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre/bin/java
[root@localhost bin]# cd /usr/lib/jvm
[root@localhost jvm]# ll
total 4
drwxr-xr-x 3 root root 4096 Mar 15 09:59 java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64
lrwxrwxrwx 1 root root   21 Mar 15 09:59 jre -> /etc/alternatives/jre
lrwxrwxrwx 1 root root   27 Mar 15 09:59 jre-1.8.0 -> /etc/alternatives/jre_1.8.0
lrwxrwxrwx 1 root root   35 Mar 15 09:59 jre-1.8.0-openjdk -> /etc/alternatives/jre_1.8.0_openjdk
lrwxrwxrwx 1 root root   51 Mar 15 09:59 jre-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64 -> java-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/jre
lrwxrwxrwx 1 root root   29 Mar 15 09:59 jre-openjdk -> /etc/alternatives/jre_openjdk
2.2 Add the following code under /etc/profile file and execute
export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.242.b08-0.el7_7.x86_64/          
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
 
[root@localhost ~]# source /etc/profile

Summarize

The above is personal experience. I hope you can give you a reference and I hope you can support me more.