SpringCloudAlibaba-Nacos集群搭建

基础环境搭建

文件下载

可以在git上面下载
https://github.com/alibaba/nacos/releases/download/2.0.2/nacos-server-2.0.2.tar.gz
接着把文件放到三个服务器上
由于演示就用一个虚拟机搞了

环境搭建

这里使用mysql数据库作为持久化容器,执行sql在下载的文件里面

[root@localhost ~]# tar -zxvf nacos-server-2.0.4.tar.gz 
nacos/LICENSE
nacos/NOTICE
nacos/target/nacos-server.jar
nacos/conf/
nacos/conf/1.4.0-ipv6_support-update.sql
nacos/conf/schema.sql
nacos/conf/nacos-mysql.sql
nacos/conf/application.properties.example
nacos/conf/nacos-logback.xml
nacos/conf/cluster.conf.example
nacos/conf/application.properties
nacos/bin/startup.sh
nacos/bin/startup.cmd
nacos/bin/shutdown.sh
nacos/bin/shutdown.cmd

我们使用的就是conf里面的nacos-mysql.sql文件

新建数据库

image.png

执行sql

/*
 * Copyright 1999-2018 Alibaba Group Holding Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info   */
/******************************************/
CREATE TABLE `config_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(255) DEFAULT NULL,
  `content` longtext NOT NULL COMMENT 'content',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
  `app_name` varchar(128) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  `c_desc` varchar(256) DEFAULT NULL,
  `c_use` varchar(64) DEFAULT NULL,
  `effect` varchar(64) DEFAULT NULL,
  `type` varchar(64) DEFAULT NULL,
  `c_schema` text,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfo_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_aggr   */
/******************************************/
CREATE TABLE `config_info_aggr` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(255) NOT NULL COMMENT 'group_id',
  `datum_id` varchar(255) NOT NULL COMMENT 'datum_id',
  `content` longtext NOT NULL COMMENT '内容',
  `gmt_modified` datetime NOT NULL COMMENT '修改时间',
  `app_name` varchar(128) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfoaggr_datagrouptenantdatum` (`data_id`,`group_id`,`tenant_id`,`datum_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='增加租户字段';


/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_beta   */
/******************************************/
CREATE TABLE `config_info_beta` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL COMMENT 'content',
  `beta_ips` varchar(1024) DEFAULT NULL COMMENT 'betaIps',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfobeta_datagrouptenant` (`data_id`,`group_id`,`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_beta';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_info_tag   */
/******************************************/
CREATE TABLE `config_info_tag` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
  `tag_id` varchar(128) NOT NULL COMMENT 'tag_id',
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL COMMENT 'content',
  `md5` varchar(32) DEFAULT NULL COMMENT 'md5',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  `src_user` text COMMENT 'source user',
  `src_ip` varchar(50) DEFAULT NULL COMMENT 'source ip',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_configinfotag_datagrouptenanttag` (`data_id`,`group_id`,`tenant_id`,`tag_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_info_tag';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = config_tags_relation   */
/******************************************/
CREATE TABLE `config_tags_relation` (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `tag_name` varchar(128) NOT NULL COMMENT 'tag_name',
  `tag_type` varchar(64) DEFAULT NULL COMMENT 'tag_type',
  `data_id` varchar(255) NOT NULL COMMENT 'data_id',
  `group_id` varchar(128) NOT NULL COMMENT 'group_id',
  `tenant_id` varchar(128) DEFAULT '' COMMENT 'tenant_id',
  `nid` bigint(20) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`nid`),
  UNIQUE KEY `uk_configtagrelation_configidtag` (`id`,`tag_name`,`tag_type`),
  KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='config_tag_relation';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = group_capacity   */
/******************************************/
CREATE TABLE `group_capacity` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `group_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Group ID,空字符表示整个集群',
  `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
  `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
  `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
  `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数,,0表示使用默认值',
  `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
  `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='集群、各Group容量信息表';

/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = his_config_info   */
/******************************************/
CREATE TABLE `his_config_info` (
  `id` bigint(64) unsigned NOT NULL,
  `nid` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `data_id` varchar(255) NOT NULL,
  `group_id` varchar(128) NOT NULL,
  `app_name` varchar(128) DEFAULT NULL COMMENT 'app_name',
  `content` longtext NOT NULL,
  `md5` varchar(32) DEFAULT NULL,
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `src_user` text,
  `src_ip` varchar(50) DEFAULT NULL,
  `op_type` char(10) DEFAULT NULL,
  `tenant_id` varchar(128) DEFAULT '' COMMENT '租户字段',
  PRIMARY KEY (`nid`),
  KEY `idx_gmt_create` (`gmt_create`),
  KEY `idx_gmt_modified` (`gmt_modified`),
  KEY `idx_did` (`data_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='多租户改造';


/******************************************/
/*   数据库全名 = nacos_config   */
/*   表名称 = tenant_capacity   */
/******************************************/
CREATE TABLE `tenant_capacity` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键ID',
  `tenant_id` varchar(128) NOT NULL DEFAULT '' COMMENT 'Tenant ID',
  `quota` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '配额,0表示使用默认值',
  `usage` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '使用量',
  `max_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个配置大小上限,单位为字节,0表示使用默认值',
  `max_aggr_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '聚合子配置最大个数',
  `max_aggr_size` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '单个聚合数据的子配置大小上限,单位为字节,0表示使用默认值',
  `max_history_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '最大变更历史数量',
  `gmt_create` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  `gmt_modified` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='租户容量信息表';


CREATE TABLE `tenant_info` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `kp` varchar(128) NOT NULL COMMENT 'kp',
  `tenant_id` varchar(128) default '' COMMENT 'tenant_id',
  `tenant_name` varchar(128) default '' COMMENT 'tenant_name',
  `tenant_desc` varchar(256) DEFAULT NULL COMMENT 'tenant_desc',
  `create_source` varchar(32) DEFAULT NULL COMMENT 'create_source',
  `gmt_create` bigint(20) NOT NULL COMMENT '创建时间',
  `gmt_modified` bigint(20) NOT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_tenant_info_kptenantid` (`kp`,`tenant_id`),
  KEY `idx_tenant_id` (`tenant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin COMMENT='tenant_info';

CREATE TABLE `users` (
	`username` varchar(50) NOT NULL PRIMARY KEY,
	`password` varchar(500) NOT NULL,
	`enabled` boolean NOT NULL
);

CREATE TABLE `roles` (
	`username` varchar(50) NOT NULL,
	`role` varchar(50) NOT NULL,
	UNIQUE INDEX `idx_user_role` (`username` ASC, `role` ASC) USING BTREE
);

CREATE TABLE `permissions` (
    `role` varchar(50) NOT NULL,
    `resource` varchar(255) NOT NULL,
    `action` varchar(8) NOT NULL,
    UNIQUE INDEX `uk_role_permission` (`role`,`resource`,`action`) USING BTREE
);

INSERT INTO users (username, password, enabled) VALUES ('nacos', '$2a$10$EuWPZHzz32dJN7jexM34MOeYirDdFAZm2kuWj7VEOJhhZkDrxfvUu', TRUE);

INSERT INTO roles (username, role) VALUES ('nacos', 'ROLE_ADMIN');

执行完毕如下:
image.png

配置文件修改

修改application.properties

#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
spring.datasource.platform=mysql

### Count of DB:
db.num=1

### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456

### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

新增cluster文件

我这里是用的本机三个端口

[root@localhost conf]# cp cluster.conf.example cluster.conf
[root@localhost conf]# vim cluster.conf
[root@localhost conf]# cat cluster.conf
#
# Copyright 1999-2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#it is ip
#example
192.168.76.128:8848
192.168.76.128:8869
192.168.76.128:8890

复制nacos文件,修改端口

[root@localhost nacos-cluster]# cp -r nacos8848 ./nacos8869
[root@localhost nacos-cluster]# cp -r nacos8848 ./nacos8890
[root@localhost nacos-cluster]# ll
总用量 0
drwxr-xr-x. 5 root root 72 59 10:00 nacos8848
drwxr-xr-x. 5 root root 72 59 10:13 nacos8869
drwxr-xr-x. 5 root root 72 59 10:13 nacos8890

接着修改每一个节点的application.properties文件

修改成不同的端口8848,8869,8890

开机自启配置

创建启动脚本

根据自己路径不同创建三份启动文件

vim /lib/systemd/system/nacos8848.service

[Unit]
Description=nacos8848
After=network.target

[Service]
Type=forking
ExecStart=/opt/nacos-cluster/nacos8848/bin/startup.sh
ExecReload=/opt/nacos-cluster/nacos8848/bin/startup.sh
ExecStop=/opt/nacos-cluster/nacos8848/bin/shutdown.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

其它的修改路径

修改start.sh

image.png

依次启动

[root@localhost bin]# systemctl start nacos8848
[root@localhost bin]# systemctl start nacos8869
[root@localhost bin]# systemctl start nacos8890

登录nacos

可以看到集群节点up
image.png

创建springcloud微服务看是否能注册

引入依赖

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- 统一依赖管理 -->
        <spring.boot.version>2.7.17</spring.boot.version>
        <spring.cloud.version>2021.0.5</spring.cloud.version>
        <spring.cloud.alibaba.version>2021.0.4.0</spring.cloud.alibaba.version>
        <!-- Web 相关 -->
        <servlet.versoin>2.5</servlet.versoin>
        <spring.cloud.bootstrap.version>3.1.7</spring.cloud.bootstrap.version>
        <jackson.version>2.13.2</jackson.version>
    </properties>



    <dependencies>
        <!-- 管理SpringBoot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring.boot.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <!-- 管理SpringCloud Netflix -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring.cloud.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <!-- 管理SpringCloud alibaba -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-alibaba-dependencies</artifactId>
            <version>${spring.cloud.alibaba.version}</version>
            <scope>import</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>${spring.boot.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
            <version>${spring.cloud.bootstrap.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
            <version>${spring.cloud.alibaba.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
            <version>${spring.cloud.alibaba.version}</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson.version}</version>
        </dependency>
    </dependencies>

创建bootstrap.yml

server:
  port: 8080


spring:
  cloud:
    nacos:
      server-addr: 192.168.76.128:8848,192.168.76.128:8869,192.168.76.128:8890
      discovery:
        namespace: dev # 命名空间。这里使用 dev 开发环境
  application:
    name: config-client


--- #################### 配置中心相关配置 ####################

spring:
  cloud:

    nacos:
      # Nacos Config 配置项,对应 NacosConfigProperties 配置属性类
      config:
        server-addr: 192.168.76.128:8848,192.168.76.128:8869,192.168.76.128:8890
        namespace: dev # 命名空间。这里使用 dev 开发环境
        group: DEFAULT_GROUP # 使用的 Nacos 配置分组,默认为 DEFAULT_GROUP
        name: # 使用的 Nacos 配置集的 dataId,默认为 spring.application.name
        file-extension: yml # 使用的 Nacos 配置集的 dataId 的文件拓展名,同时也是 Nacos 配置集的配置格式,默认为 properties

创建启动类

@SpringBootApplication
@EnableDiscoveryClient
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class,args);
    }
}

可以看到控制台输出了

2024-05-09 14:14:31.773  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [RpcClientFactory] create a new rpc client of fed634db-759b-42c3-9f26-3ac32ebb4f5c
2024-05-09 14:14:31.773  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] RpcClient init label, labels = {module=naming, source=sdk}
2024-05-09 14:14:31.774  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] RpcClient init, ServerListFactory = com.alibaba.nacos.client.naming.core.ServerListManager
2024-05-09 14:14:31.774  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Registry connection listener to current client:com.alibaba.nacos.client.naming.remote.gprc.redo.NamingGrpcRedoService
2024-05-09 14:14:31.774  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Register server push request handler:com.alibaba.nacos.client.naming.remote.gprc.NamingPushRequestHandler
2024-05-09 14:14:31.774  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Try to connect to server on start up, server: {serverIp = '192.168.76.128', server main port = 8890}
2024-05-09 14:14:31.899  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Success to connect to server [192.168.76.128:8890] on start up, connectionId = 1715235271834_192.168.76.1_55144
2024-05-09 14:14:31.900  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient$ConnectResetRequestHandler
2024-05-09 14:14:31.900  INFO 29300 --- [t.remote.worker] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Notify connected event to listeners.
2024-05-09 14:14:31.900  INFO 29300 --- [           main] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Register server push request handler:com.alibaba.nacos.common.remote.client.RpcClient$$Lambda$332/910504711
2024-05-09 14:14:31.958  INFO 29300 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2024-05-09 14:14:31.973  INFO 29300 --- [           main] c.a.c.n.registry.NacosServiceRegistry    : nacos registry, DEFAULT_GROUP config-client 10.1.32.44:8080 register finished
2024-05-09 14:14:32.160  INFO 29300 --- [           main] com.tom.Main                             : Started Main in 3.794 seconds (JVM running for 4.327)
2024-05-09 14:14:32.164  INFO 29300 --- [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=config-client, group=DEFAULT_GROUP
2024-05-09 14:14:32.164  INFO 29300 --- [           main] c.a.c.n.refresh.NacosContextRefresher    : [Nacos Config] Listening config: dataId=config-client.yml, group=DEFAULT_GROUP
2024-05-09 14:14:32.500  INFO 29300 --- [ient-executor-6] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Receive server push request, request = NotifySubscriberRequest, requestId = 1
2024-05-09 14:14:32.502  INFO 29300 --- [ient-executor-6] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Ack server push request, request = NotifySubscriberRequest, requestId = 1

命名里面又有了
image.png
如果这个时候8890宕机了

[root@localhost bin]# systemctl stop nacos8890

那么它会自动进行切换

2024-05-09 14:16:03.618 ERROR 29300 --- [ent-executor-30] c.a.n.c.remote.client.grpc.GrpcClient    : [1715235271834_192.168.76.1_55144]Request stream error, switch server,error={}

com.alibaba.nacos.shaded.io.grpc.StatusRuntimeException: CANCELLED: HTTP/2 error code: CANCEL
Received Rst Stream
	at com.alibaba.nacos.shaded.io.grpc.Status.asRuntimeException(Status.java:533) ~[nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:442) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:700) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:399) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:510) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:66) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:630) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:518) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:692) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:681) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) [nacos-client-2.0.4.jar:na]
	at com.alibaba.nacos.shaded.io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) [nacos-client-2.0.4.jar:na]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_381]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_381]
	at java.lang.Thread.run(Thread.java:750) [na:1.8.0_381]

2024-05-09 14:16:03.619  INFO 29300 --- [t.remote.worker] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Try to reconnect to a new server, server is  not appointed, will choose a random server.
2024-05-09 14:16:03.761  INFO 29300 --- [t.remote.worker] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Success to connect a server [192.168.76.128:8848], connectionId = 1715235363689_192.168.76.1_55410
2024-05-09 14:16:03.761  INFO 29300 --- [t.remote.worker] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Abandon prev connection, server is 192.168.76.128:8890, connectionId is 1715235271834_192.168.76.1_55144
2024-05-09 14:16:03.761  INFO 29300 --- [t.remote.worker] com.alibaba.nacos.common.remote.client   : Close current connection 1715235271834_192.168.76.1_55144
2024-05-09 14:16:03.765  INFO 29300 --- [t.remote.worker] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Notify disconnected event to listeners
2024-05-09 14:16:03.766  INFO 29300 --- [t.remote.worker] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Notify connected event to listeners.
2024-05-09 14:16:05.575  INFO 29300 --- [ent-executor-36] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Receive server push request, request = NotifySubscriberRequest, requestId = 2
2024-05-09 14:16:05.575  INFO 29300 --- [ent-executor-36] com.alibaba.nacos.common.remote.client   : [fed634db-759b-42c3-9f26-3ac32ebb4f5c] Ack server push request, request = NotifySubscriberRequest, requestId = 2

从控制台可以看到切换到8848了,到这里配置完成

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值