Nacos2.4.1版本适配人大金仓kingbase数据库

打印 上一主题 下一主题

主题 956|帖子 956|积分 2868

提示:文章写完后,目次可以自动天生,怎样天生可参考右边的帮助文档
  
  

前言

随着国家书息技术应用创新(信创)战略的深入推进,越来越多的关键技术和组件正徐徐被替换为国产化的产品与服务。这一变化不光是为了增强国家的信息安全,淘汰对外部技术的依赖,更是为了促进本土信息技术财产的自主创新本领和发展。在这一过程中,包括操纵体系、数据库、中心件、服务器硬件以及核心芯片在内的多个范畴都在经历着一场深刻的变革。
具体而言,国产化替换涉及以下几个方面:

  • 操纵体系:推广利用如麒麟软件、统信UOS等国产操纵体系,以替换传统的Windows或Unix体系。
  • 数据库管理体系:研发并部署达梦、人大金仓Kingbase等国产数据库,淘汰对Oracle、SQL Server等国外产品的依赖。
  • 中心件:诸如东方通、中创中心件等国产产品正在逐渐取代IBM WebSphere和Oracle WebLogic等外资品牌。
  • 服务器及PC终端:利用基于国产CPU架构(如龙芯、飞腾、兆芯等)的服务器和电脑,以替换Intel和AMD等厂商的产品。
  • 基础软件与工具:包括办公软件、设计软件等,也在向WPS Office、中望CAD等国产化方向迁移。
此外,政策层面的支持也在不停加码,通过设立专项基金、制定行业标准、举行各类信创大赛等方式,激励企业和科研机构加快技术创新和产品迭代。同时,市场需求的增长也为国产信息技术产品和服务提供了广阔的市场空间,促进了整个财产链的成熟与发展。随着这些措施的有效实施,不光能够提拔国家书息基础办法的安全性和自主性,还将极大地推动中国信息技术财产的整体进步与国际竞争力的提拔。
提示:以下是本篇文章正文内容,下面案例可供参考
一、Nacos2.4.1版本适配人大金仓数据库

近期,Nacos爆出了任意文件读写毛病,Nacos2版本影响的为2.0.0-2.4.0.1,需要升级到2.4.1版本,为了相应国家号召,本次利用了人大金仓数据库,版本为8.6.0
二、适配步骤

1.修改Nacos最外层pom,参加人大金仓依赖版本

  1.   <properties>
  2.         <kingbase8-connector-java.version>8.6.0</kingbase8-connector-java.version>
  3.   </properties>
  4.   
  5.     <dependencyManagement>
  6.         <dependencies>            
  7.             <dependency>
  8.                 <groupId>com.kingbase8</groupId>
  9.                 <artifactId>kingbase8</artifactId>
  10.                 <version>${kingbase8-connector-java.version}</version>
  11.             </dependency>
  12.         </dependencies>
  13.     </dependencyManagement>
复制代码
2.修改config模块下的pom,增加人大金仓依赖

  1.         <dependency>
  2.             <groupId>com.kingbase8</groupId>
  3.             <artifactId>kingbase8</artifactId>
  4.         </dependency>
复制代码
3.修改console模块下resources中的application.properties和distribution模块下conf包中的application.properties

注意,其中{}中的内容替换成本身的
  1. #
  2. # Copyright 1999-2021 Alibaba Group Holding Ltd.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. #      http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. #*************** Spring Boot Related Configurations ***************#
  17. ### Default web context path:
  18. server.servlet.contextPath=/nacos
  19. ### Default web server port:
  20. server.port=8858
  21. #*************** Network Related Configurations ***************#
  22. ### If prefer hostname over ip for Nacos server addresses in cluster.conf:
  23. # nacos.inetutils.prefer-hostname-over-ip=false
  24. ### Specify local server's IP:
  25. # nacos.inetutils.ip-address=
  26. #*************** Config Module Related Configurations ***************#
  27. ### If use MySQL or KingbaseES as datasource:
  28. spring.datasource.platform=mysql
  29. ### Count of DB:
  30. db.num=1
  31. ### Connect URL of DB:
  32. # 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
  33. # db.user.0=nacos
  34. # db.password.0=nacos
  35. ### KingbaseES
  36. db.jdbcDriverName=com.kingbase8.Driver
  37. db.url.0=jdbc:kingbase8://{ip}:{port}/{dataSourceName}
  38. db.user.0={username}
  39. db.password.0={password}
  40. ### Connection pool configuration: hikariCP
  41. db.pool.config.connectionTimeout=30000
  42. db.pool.config.validationTimeout=10000
  43. db.pool.config.maximumPoolSize=20
  44. db.pool.config.minimumIdle=2
  45. #*************** Naming Module Related Configurations ***************#
  46. ### Data dispatch task execution period in milliseconds: Will removed on v2.1.X, replace with nacos.core.protocol.distro.data.sync.delayMs
  47. # nacos.naming.distro.taskDispatchPeriod=200
  48. ### Data count of batch sync task: Will removed on v2.1.X. Deprecated
  49. # nacos.naming.distro.batchSyncKeyCount=1000
  50. ### Retry delay in milliseconds if sync task failed: Will removed on v2.1.X, replace with nacos.core.protocol.distro.data.sync.retryDelayMs
  51. # nacos.naming.distro.syncRetryDelay=5000
  52. ### If enable data warmup. If set to false, the server would accept request without local data preparation:
  53. # nacos.naming.data.warmup=true
  54. ### If enable the instance auto expiration, kind like of health check of instance:
  55. # nacos.naming.expireInstance=true
  56. ### will be removed and replaced by `nacos.naming.clean` properties
  57. nacos.naming.empty-service.auto-clean=true
  58. nacos.naming.empty-service.clean.initial-delay-ms=50000
  59. nacos.naming.empty-service.clean.period-time-ms=30000
  60. ### Add in 2.0.0
  61. ### The interval to clean empty service, unit: milliseconds.
  62. # nacos.naming.clean.empty-service.interval=60000
  63. ### The expired time to clean empty service, unit: milliseconds.
  64. # nacos.naming.clean.empty-service.expired-time=60000
  65. ### The interval to clean expired metadata, unit: milliseconds.
  66. # nacos.naming.clean.expired-metadata.interval=5000
  67. ### The expired time to clean metadata, unit: milliseconds.
  68. # nacos.naming.clean.expired-metadata.expired-time=60000
  69. ### The delay time before push task to execute from service changed, unit: milliseconds.
  70. # nacos.naming.push.pushTaskDelay=500
  71. ### The timeout for push task execute, unit: milliseconds.
  72. # nacos.naming.push.pushTaskTimeout=5000
  73. ### The delay time for retrying failed push task, unit: milliseconds.
  74. # nacos.naming.push.pushTaskRetryDelay=1000
  75. ### Since 2.0.3
  76. ### The expired time for inactive client, unit: milliseconds.
  77. # nacos.naming.client.expired.time=180000
  78. #*************** CMDB Module Related Configurations ***************#
  79. ### The interval to dump external CMDB in seconds:
  80. # nacos.cmdb.dumpTaskInterval=3600
  81. ### The interval of polling data change event in seconds:
  82. # nacos.cmdb.eventTaskInterval=10
  83. ### The interval of loading labels in seconds:
  84. # nacos.cmdb.labelTaskInterval=300
  85. ### If turn on data loading task:
  86. # nacos.cmdb.loadDataAtStart=false
  87. #*************** Metrics Related Configurations ***************#
  88. ### Metrics for prometheus
  89. #management.endpoints.web.exposure.include=*
  90. ### Metrics for elastic search
  91. management.metrics.export.elastic.enabled=false
  92. #management.metrics.export.elastic.host=http://localhost:9200
  93. ### Metrics for influx
  94. management.metrics.export.influx.enabled=false
  95. #management.metrics.export.influx.db=springboot
  96. #management.metrics.export.influx.uri=http://localhost:8086
  97. #management.metrics.export.influx.auto-create-db=true
  98. #management.metrics.export.influx.consistency=one
  99. #management.metrics.export.influx.compressed=true
  100. #*************** Access Log Related Configurations ***************#
  101. ### If turn on the access log:
  102. server.tomcat.accesslog.enabled=true
  103. ### The access log pattern:
  104. server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i
  105. ### The directory of access log:
  106. server.tomcat.basedir=file:.
  107. #*************** Access Control Related Configurations ***************#
  108. ### If enable spring security, this option is deprecated in 1.2.0:
  109. #spring.security.enabled=false
  110. ### The ignore urls of auth, is deprecated in 1.2.0:
  111. nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**
  112. ### The auth system to use, currently only 'nacos' and 'ldap' is supported:
  113. nacos.core.auth.system.type=nacos
  114. ### If turn on auth system:
  115. nacos.core.auth.enabled=true
  116. ### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
  117. nacos.core.auth.caching.enabled=true
  118. ### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
  119. nacos.core.auth.enable.userAgentAuthWhite=false
  120. ### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
  121. ### The two properties is the white list for auth and used by identity the request from other server.
  122. nacos.core.auth.server.identity.key=serverIdentity
  123. nacos.core.auth.server.identity.value=security
  124. ### worked when nacos.core.auth.system.type=nacos
  125. ### The token expiration in seconds:
  126. nacos.core.auth.plugin.nacos.token.expire.seconds=18000
  127. ### The default token:
  128. nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
  129. ### worked when nacos.core.auth.system.type=ldap?{0} is Placeholder,replace login username
  130. #nacos.core.auth.ldap.url=ldap://localhost:389
  131. #nacos.core.auth.ldap.basedc=dc=example,dc=org
  132. #nacos.core.auth.ldap.userDn=cn=admin,${nacos.core.auth.ldap.basedc}
  133. #nacos.core.auth.ldap.password=admin
  134. #nacos.core.auth.ldap.userdn=cn={0},dc=example,dc=org
  135. #*************** Istio Related Configurations ***************#
  136. ### If turn on the MCP server:
  137. nacos.istio.mcp.server.enabled=false
  138. #*************** Core Related Configurations ***************#
  139. ### set the WorkerID manually
  140. # nacos.core.snowflake.worker-id=
  141. ### Member-MetaData
  142. # nacos.core.member.meta.site=
  143. # nacos.core.member.meta.adweight=
  144. # nacos.core.member.meta.weight=
  145. ### MemberLookup
  146. ### Addressing pattern category, If set, the priority is highest
  147. # nacos.core.member.lookup.type=[file,address-server]
  148. ## Set the cluster list with a configuration file or command-line argument
  149. # 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
  150. ## for AddressServerMemberLookup
  151. # Maximum number of retries to query the address server upon initialization
  152. # nacos.core.address-server.retry=5
  153. ## Server domain name address of [address-server] mode
  154. # address.server.domain=jmenv.tbsite.net
  155. ## Server port of [address-server] mode
  156. # address.server.port=8080
  157. ## Request address of [address-server] mode
  158. # address.server.url=/nacos/serverlist
  159. #*************** JRaft Related Configurations ***************#
  160. ### Sets the Raft cluster election timeout, default value is 5 second
  161. # nacos.core.protocol.raft.data.election_timeout_ms=5000
  162. ### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
  163. # nacos.core.protocol.raft.data.snapshot_interval_secs=30
  164. ### raft internal worker threads
  165. # nacos.core.protocol.raft.data.core_thread_num=8
  166. ### Number of threads required for raft business request processing
  167. # nacos.core.protocol.raft.data.cli_service_thread_num=4
  168. ### raft linear read strategy. Safe linear reads are used by default, that is, the Leader tenure is confirmed by heartbeat
  169. # nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
  170. ### rpc request timeout, default 5 seconds
  171. # nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000
  172. #*************** Distro Related Configurations ***************#
  173. ### Distro data sync delay time, when sync task delayed, task will be merged for same data key. Default 1 second.
  174. # nacos.core.protocol.distro.data.sync.delayMs=1000
  175. ### Distro data sync timeout for one sync data, default 3 seconds.
  176. # nacos.core.protocol.distro.data.sync.timeoutMs=3000
  177. ### Distro data sync retry delay time when sync data failed or timeout, same behavior with delayMs, default 3 seconds.
  178. # nacos.core.protocol.distro.data.sync.retryDelayMs=3000
  179. ### Distro data verify interval time, verify synced data whether expired for a interval. Default 5 seconds.
  180. # nacos.core.protocol.distro.data.verify.intervalMs=5000
  181. ### Distro data verify timeout for one verify, default 3 seconds.
  182. # nacos.core.protocol.distro.data.verify.timeoutMs=3000
  183. ### Distro data load retry delay when load snapshot data failed, default 30 seconds.
  184. # nacos.core.protocol.distro.data.load.retryDelayMs=30000
复制代码
3.修改persistence模块下com/alibaba/nacos/persistence/datasource包中ExternalDataSourceProperties类的JDBC_DRIVER_NAME常量

  1.     // private static final String JDBC_DRIVER_NAME = "com.mysql.cj.jdbc.Driver";
  2.     private static final String JDBC_DRIVER_NAME = "com.kingbase8.Driver";
复制代码
4.修改plugin模块下datasource子模块下com/alibaba/nacos/plugin/datasource/enums/mysql包中的TrustedMysqlFunctionEnum枚举类

  1.         //人大金仓中NOW()函数没有入参,该入参是mysql的now(integer)函数为了设置毫秒位数使用,而人大金仓中NOW()函数默认是带着毫秒的
  2.    // NOW("NOW()", "NOW(3)");
  3.    NOW("NOW()", "NOW()");
复制代码
5.利用命令打包

  1. mvn -Prelease-nacos "-Dmaven.test.skip=true" clean install -U --settings {自己的settings.xml路径}
复制代码
至此,全部完成,天生的jar会存放在项目的distribution模块的target中

总结

本次升级完成,由原来的mysql支持替换成人大金仓kingbase,2.4.1版本适配人大金仓相对比较简单,如需要前期其他版本,可以留言给我,谢谢。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

灌篮少年

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表