配置中心Nacas版本升级

简介

此文介绍配置管理中心 Nacos 的升级问题。

升级目标

Nacos版本:v1.2.1 -> v.1.3.0-beta

版本升级原因:Nacos服务器端版本1.2.1版本中出现配置项的内容md5化后,会出现少一位的现象,少的一位大部分是0这个字符串,这个bug会引起客户端的配置不断刷新本地配置,继而导致对应项目的配置不断刷新。

服务器配置信息

主机名 IP 配置
nacos01 192.168.17.37 4C8G100G
nacos02 192.168.17.38 4C8G100G
nacos03 192.168.17.39 4C8G100G

两个版本之间主配置文件异同

Nacos v1.2.1主配置文件:application.properties

# egrep -v "^$|#" conf/application.properties
server.servlet.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.14.2:23306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=********
nacos.naming.empty-service.auto-clean=false
nacos.naming.empty-service.clean.initial-delay-ms=60000
nacos.naming.empty-service.clean.period-time-ms=20000
management.endpoints.web.exposure.include=*
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
server.tomcat.basedir=
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
nacos.core.auth.default.token.expire.seconds=18000
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
nacos.core.auth.caching.enabled=false
nacos.istio.mcp.server.enabled=false

Nacos v.1.3.0-beta主配置文件新增加内容

###*************** Add from 1.3.0-BETA ***************###


#*************** Core Related Configurations ***************#

### set the WorkerID manually
# nacos.core.snowflake.worker-id=

### Member-MetaData
# nacos.core.member.meta.site=
# nacos.core.member.meta.adweight=
# nacos.core.member.meta.weight=

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server,discovery]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for DiscoveryMemberLookup
# If you want to use cluster node self-discovery, turn this parameter on
# nacos.member.discovery=false
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5

#*************** JRaft Related Configurations ***************#

## 集群一致性相关配置 ##

### Sets the Raft cluster election timeout, default value is 5 second

# 选举超时时间
# nacos.core.protocol.raft.data.election_timeout_ms=5000

# 集群以中性数据快照间隔时间
### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
# nacos.core.protocol.raft.data.snapshot_interval_secs=30

# 请求失败尝试次数
### Requested retries, default value is 1
# nacos.core.protocol.raft.data.request_failoverRetries=1

# 线程个数
### raft internal worker threads
# nacos.core.protocol.raft.data.core_thread_num=8

# 客户端线程请求数
### Number of threads required for raft business request processing
# nacos.core.protocol.raft.data.cli_service_thread_num=4

# 一致性线性读策略
### raft linear read strategy, defaults to index
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe

# RPC 请求超时时间
### rpc request timeout, default 5 seconds
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000

版本升级后默认修改的参数

注意:以下版本升级仅针对1.2.1v.1.3.0-beta

  1. 版本升级后:nacos.naming.empty-service.auto-clean参数由false改为true
### If enable the empty service auto clean, services with an empty instance are automatically cleared
nacos.naming.empty-service.auto-clean=false
->
nacos.naming.empty-service.auto-clean=true
  1. 版本升级后:nacos.naming.empty-service.clean.initial-delay-ms参数由60000改为50000
### The empty service cleanup task delays startup time in milliseconds
nacos.naming.empty-service.clean.initial-delay-ms=60000 
->
nacos.naming.empty-service.clean.initial-delay-ms=50000
  1. 版本升级后:nacos.naming.empty-service.clean.period-time-ms参数由20000该为30000
### The empty service cleanup task cycle execution time in milliseconds
nacos.naming.empty-service.clean.period-time-ms=20000
->
nacos.naming.empty-service.clean.period-time-ms=30000
  1. 版本升级后:nacos.core.auth.caching.enabled参数由false改为true
### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=false
->
nacos.core.auth.caching.enabled=true

升级策略

目前nacos采用三节点方式部署,升级过程中选择逐台升级

注意事项

由于版本不同导致配置文件都有差异,因此,需要将原v1.2.1的配置全部配置到v.1.3.0-beta,使用新版本的配置文件。

  1. 由于数据库已配置主主,Nacas通过配置文件中的相关配置读取数据库,因此,需要修改数据库相关配置;
  2. 开启配置文件中的prometheus监控选项:management.endpoints.web.exposure.include=*
  3. 需要将bin/conf/application.propertiestarget/nacos-server.jar更换为新的配置。

升级

1. 准备安装包

  1. 准备 Nacos v.1.3.0-beta 安装包
# cd /opt
# wget https://github.com/alibaba/nacos/releases/download/1.3.0-beta/nacos-server-1.3.0-BETA.tar.gz
# tar -xf nacos-server-1.3.0-BETA.tar.gz
  1. 查看解压后的安装包有哪些文件
# tree /opt/nacos
/opt/nacos
├── bin
│   ├── shutdown.cmd
│   ├── shutdown.sh
│   ├── startup.cmd
│   └── startup.sh
├── conf
│   ├── application.properties
│   ├── application.properties.example
│   ├── cluster.conf.example
│   ├── nacos-logback.xml
│   ├── nacos-mysql.sql
│   └── schema.sql
├── LICENSE
├── NOTICE
└── target
    └── nacos-server.jar

3 directories, 13 files

2.提前配置好新版本的配置文件

# egrep -v "^$|#" /opt/nacos/conf/application.properties
server.servlet.contextPath=/nacos
server.port=8848
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.14.2:23306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=********
nacos.naming.empty-service.auto-clean=true
nacos.naming.empty-service.clean.initial-delay-ms=50000
nacos.naming.empty-service.clean.period-time-ms=30000
management.endpoints.web.exposure.include=*
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i
server.tomcat.basedir=
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
nacos.core.auth.default.token.expire.seconds=18000
nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
nacos.core.auth.caching.enabled=true
nacos.istio.mcp.server.enabled=false

3. 停止服务

# systemctl stop nacos

4. 备份目前 v1.2.1 的配置

# cd /usr/local/nacos
# tar -cvzf nacos.backup.1.2.1.tar.gz bin/ conf/ target/

5. 更换配置

  1. 更换服务启停脚本
# cp /opt/nacos/bin/shutdown.sh /usr/local/nacos/bin/shutdown.sh 
# cp /opt/nacos/bin/startup.sh /usr/local/nacos/bin/startup.sh 
  1. 更换主配置文件
# cp /opt/nacos/conf/application.properties /usr/local/nacos/conf/application.properties
  1. 更换库文件
# cp /opt/nacos/target/nacos-server.jar /usr/local/nacos/target/nacos-server.jar 

6. 启动服务

# systemctl start nacos
posted @ 2020-05-20 22:23  McSiberiaWolf  阅读(3180)  评论(0编辑  收藏  举报