目錄
簡介
此文介紹配置管理中心 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.1
至v.1.3.0-beta
- 版本升級后:
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
- 版本升級后:
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
- 版本升級后:
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
- 版本升級后:
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
,使用新版本的配置文件。
- 由於數據庫已配置主主,Nacas通過配置文件中的相關配置讀取數據庫,因此,需要修改數據庫相關配置;
- 開啟配置文件中的
prometheus
監控選項:management.endpoints.web.exposure.include=*
- 需要將
bin/
、conf/application.properties
、target/nacos-server.jar
更換為新的配置。
升級
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
- 查看解壓后的安裝包有哪些文件
# 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. 更換配置
- 更換服務啟停腳本
# cp /opt/nacos/bin/shutdown.sh /usr/local/nacos/bin/shutdown.sh
# cp /opt/nacos/bin/startup.sh /usr/local/nacos/bin/startup.sh
- 更換主配置文件
# cp /opt/nacos/conf/application.properties /usr/local/nacos/conf/application.properties
- 更換庫文件
# cp /opt/nacos/target/nacos-server.jar /usr/local/nacos/target/nacos-server.jar
6. 啟動服務
# systemctl start nacos