Nacos尽量保证1.4+

@SpringBootApplication 
@EnableAdminServer // 作为AdminServer启动
@EnableDiscoveryClient // 开启服务发现

admin依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <!--        <version>2.1.6.RELEASE</version>-->
        <version>2.3.2.RELEASE</version>

        <relativePath/>
    </parent>
    <artifactId>admin-server</artifactId>
    <packaging>jar</packaging>
    <url>http://maven.apache.org</url>
    <name>admin-server</name>
    <description>admin-server-project</description>


    <properties>
        <java.version>1.8</java.version>
        <spring-boot-admin.version>2.1.6</spring-boot-admin.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
<!--                <version>${spring-boot-admin.version}</version>-->
                <version>2.2.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
<!--                <version>Greenwich.RELEASE</version>-->
                <version>Hoxton.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.alibaba.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
<!--                <version>2.1.1.RELEASE</version>-->
                <version>2.2.3.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!--安全模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
<!--            使用log4j2处理日志需要排除掉logback-classic-->
            <exclusions>
                <exclusion>
                    <artifactId>spring-boot-starter-logging</artifactId>
                    <groupId>org.springframework.boot</groupId>
                </exclusion>
            </exclusions>
        </dependency>

<!--        引入log4j2处理日志文件-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-log4j2</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--Admin Server-->
        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter</artifactId>
        </dependency>
        <!--nacos 配置中心客户端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            <version>0.9.0.RELEASE</version>
        </dependency>
        <!--nacos 注册中心客户端-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>0.9.0.RELEASE</version>
        </dependency>
        <!--作为AdminServer的客户端时必须引入的依赖 start-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-actuator</artifactId>-->
<!--        </dependency>-->
<!--        &lt;!&ndash;用于开放JMX操作&ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>org.jolokia</groupId>-->
<!--            <artifactId>jolokia-core</artifactId>-->
<!--        </dependency>-->
        <!--作为AdminServer的客户端时必须引入的依赖 end-->

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

admin的配置文件 bootstrap.yml


server:
  port: 9099

spring:
  application:
    name: admin-server
###########security验证配置####################
  security:
    user:
      name: root
      password: root
####################nacos配置########################
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
        namespace: pro
      config:
        server-addr: 127.0.0.1:8848
        namespace: pro
        file-extension: yml
###########开放端点提供服务健康监控###########
management:
  endpoints:
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: ALWAYS
logging:
  file:
    name: AdminServerLogs/admin-server.log

log4j2-spring. xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration status="off">
    <properties>
        <property name="LOG_HOME">AdminServerLogs</property>
        <!-- 日志备份目录 -->
        <property name="BACKUP_HOME">backup</property>
        <property name="SERVER_NAME">admin-server</property>
        <property name="EVERY_FILE_SIZE">50M</property><!-- 日志切割的最小单位 -->
        <property name="OUTPUT_LOG_LEVEL">INFO</property><!-- 日志输出级别 -->
    </properties>
    <appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="NEUTRAL"/>

            <!--<PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %level [%C{1}:%L] - %msg%n" />-->
            <PatternLayout
                    pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{requestId}] [%thread] %level %logger{36}.%M@%L - %msg%n"/>
        </Console>
        <RollingFile name="RollingFile"
                     fileName="${LOG_HOME}/${SERVER_NAME}.log"
                     filePattern="${LOG_HOME}/${BACKUP_HOME}/%d{yyyy-MM-dd}/${SERVER_NAME}.%i.log">
            <PatternLayout
                    pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{requestId}] [%thread] %level %logger{36}.%M@%L - %msg%n"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="${EVERY_FILE_SIZE}"/>
                <!--<TimeBasedTriggeringPolicy interval="1" modulate="true"/>-->
            </Policies>
            <DefaultRolloverStrategy max="99999"/>
            <Filters>
                <ThresholdFilter level="trace" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
        </RollingFile>
        <!-- 只显示error级别的信息 -->
        <RollingFile name="RollingFileError"
                     fileName="${LOG_HOME}/${SERVER_NAME}_error.log"
                     filePattern="${LOG_HOME}/${BACKUP_HOME}/%d{yyyy-MM-dd}/${SERVER_NAME}_error.%i.log">
            <PatternLayout
                    pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{requestId}] [%thread] %level %logger{36}.%M@%L - %msg%xEx%n"/>
            <Policies>
                <SizeBasedTriggeringPolicy size="${EVERY_FILE_SIZE}"/>
                <!--<TimeBasedTriggeringPolicy interval="1" modulate="true"/>-->
            </Policies>
            <DefaultRolloverStrategy max="99999"/>
            <Filters>
                <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
            </Filters>
        </RollingFile>
    </appenders>

    <loggers>
        <AsyncLogger name="org.springframework" level="INFO"/>
        <AsyncLogger name="com.chinaunicom" level="${OUTPUT_LOG_LEVEL}" additivity="false" includeLocation="true">
            <appender-ref ref="Console"/>
            <appender-ref ref="RollingFile"/>
            <appender-ref ref="RollingFileError"/>
        </AsyncLogger>
        <Root level="INFO">
            <appender-ref ref="Console"/>
            <appender-ref ref="RollingFile"/>
            <appender-ref ref="RollingFileError"/>
        </Root>
    </loggers>
</configuration>

客户端依赖 安全模块自选开不开启动 我没加 加了以后gateway网关转发访问服务报401

        <!--安全模块-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
               <!--作为AdminServer的客户端时必须引入的依赖 start-->
<!--        <dependency>-->
<!--            <groupId>org.springframework.boot</groupId>-->
<!--            <artifactId>spring-boot-starter-actuator</artifactId>-->
<!--        </dependency>-->
<!--        &lt;!&ndash;用于开放JMX操作&ndash;&gt;-->
<!--        <dependency>-->
<!--            <groupId>org.jolokia</groupId>-->
<!--            <artifactId>jolokia-core</artifactId>-->
<!--        </dependency>-->
        <!--作为AdminServer的客户端时必须引入的依赖 end-->

客户端的 配置文件 propertise格式

#定义服务名称,nacos会去配置中心以项目名称为dataid拉取该项目的配置信息
server.port=10022
spring.application.name=xxxxxx
#nacos命名空间id pro生产  dev开发
spring.cloud.nacos.config.namespace=pro
#nacos配置中心地址
spring.cloud.nacos.config.timeout=3000
#nacos注册中心地址&配置中心地址

spring.cloud.nacos.server-addr=127.0.0.1:8848
#nacos服务空间id
spring.cloud.nacos.discovery.namespace=pro
#调用指定配置文件 test dev pro  测试 开发 生产   ${prefix} - ${spring.profiles.active} . ${file-extension}
#配置文件类型默认properties
spring.cloud.nacos.config.file-extension=properties

#############security访问的用户名和密码####################
#spring.security.user.name=root
#spring.security.user.password=TY^%$SD9SO
## 将本服务实例注册到服务中心时,在元信息中携带访问本服务使用的用户名和密码
#spring.cloud.nacos.discovery.metadata.user.name=root
#spring.cloud.nacos.discovery.metadata.user.password=root

###########开放端点提供服务健康监控###########
management.endpoints.web.exposure.include=*
management.endpoint.health.show-details=ALWAY