Nacos:使用指南

tech2023-09-18  96

Nacos的使用指南

Nacos 致力于帮助您发现、配置和管理微服务。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。

相关文档:https://nacos.io/zh-cn/docs/deployment.html Github地址:https://github.com/alibaba/nacos

1.安装

安装依赖

Nacos运行时需要JDK 1.8+环境。 Nacos需要mysql 5.6.5+数据库。 Nacos集群版需要至少三个节点。

服务器

系统:centos 7.x 网络:支持访问公网 服务器:单机版 1台 集群版 3

配置示例

# 配置文件 /opt/nacos/conf/application.properties #*************** Spring Boot Related Configurations ***************# ### Default web context path: server.servlet.contextPath=/nacos ### Default web server port: server.port=8848 #*************** Network Related Configurations ***************# ### If prefer hostname over ip for Nacos server addresses in cluster.conf: # nacos.inetutils.prefer-hostname-over-ip=false ### Specify local server's IP: # nacos.inetutils.ip-address= #*************** Config Module Related Configurations ***************# ### If user MySQL as datasource: spring.datasource.platform=mysql ### Count of DB: db.num=1 ### Connect URL of DB: db.url.0=jdbc:mysql://192.168.1.11:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true db.user=root db.password=123456 #*************** Naming Module Related Configurations ***************# ### Data dispatch task execution period in milliseconds: # nacos.naming.distro.taskDispatchPeriod=200 ### Data count of batch sync task: # nacos.naming.distro.batchSyncKeyCount=1000 ### Retry delay in milliseconds if sync task failed: # nacos.naming.distro.syncRetryDelay=5000 ### If enable data warmup. If set to false, the server would accept request without local data preparation: # nacos.naming.data.warmup=true ### If enable the instance auto expiration, kind like of health check of instance: # nacos.naming.expireInstance=true ### If enable the empty service auto clean, services with an empty instance are automatically cleared nacos.naming.empty-service.auto-clean=false ### The empty service cleanup task delays startup time in milliseconds nacos.naming.empty-service.clean.initial-delay-ms=60000 ### The empty service cleanup task cycle execution time in milliseconds nacos.naming.empty-service.clean.period-time-ms=20000 #*************** CMDB Module Related Configurations ***************# ### The interval to dump external CMDB in seconds: # nacos.cmdb.dumpTaskInterval=3600 ### The interval of polling data change event in seconds: # nacos.cmdb.eventTaskInterval=10 ### The interval of loading labels in seconds: # nacos.cmdb.labelTaskInterval=300 ### If turn on data loading task: # nacos.cmdb.loadDataAtStart=false #*************** Metrics Related Configurations ***************# ### Metrics for prometheus #management.endpoints.web.exposure.include=* ### Metrics for elastic search management.metrics.export.elastic.enabled=false #management.metrics.export.elastic.host=http://localhost:9200 ### Metrics for influx management.metrics.export.influx.enabled=false #management.metrics.export.influx.db=springboot #management.metrics.export.influx.uri=http://localhost:8086 #management.metrics.export.influx.auto-create-db=true #management.metrics.export.influx.consistency=one #management.metrics.export.influx.compressed=true #*************** Access Log Related Configurations ***************# ### If turn on the access log: server.tomcat.accesslog.enabled=true ### The access log pattern: server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i ### The directory of access log: server.tomcat.basedir= #*************** Access Control Related Configurations ***************# ### If enable spring security, this option is deprecated in 1.2.0: #spring.security.enabled=false ### The ignore urls of auth, is deprecated in 1.2.0: spring.security.enabled=false management.security=false nacos.security.ignore.urls=/** #nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/** ### The auth system to use, currently only 'nacos' is supported: nacos.core.auth.system.type=nacos ### If turn on auth system: nacos.core.auth.enabled=false ### The token expiration in seconds: nacos.core.auth.default.token.expire.seconds=18000 ### The default token: nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789 ### 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 #*************** Istio Related Configurations ***************# ### If turn on the MCP server: nacos.istio.mcp.server.enabled=false # 配置文件 /opt/nacos/conf/cluster.conf # ip:port 192.168.1.11:8848 192.168.1.12:8848 192.168.1.13:8848

Nacos 1.2.1版本安装(单机版):

服务器1:jdk、Nacos-server、mysql # 下载nacos cd /opt # zip版本 wget https://github.com/alibaba/nacos/releases/download/1.3.0/nacos-server-1.3.0.zip # tar.gz版本 wget https://github.com/alibaba/nacos/releases/download/1.3.0/nacos-server-1.3.0.tar.gz # 安装jdk

# 安装mysql

# 解压 cd /opt unzip nacos-server-1.2.1.zip

# 创建 nacos_config 数据库 mysql -h192.168.1.11 -P3306 -uroot -p123456 -e "create database nacos_config;" mysql -h192.168.1.11 -P3306 -uroot -p123456 -e "show databases;"

vim /opt/nacos/conf/nacos-mysql.sql 在最上端增加:use nacos_config

# 导入 nacos sql 脚本 mysql -h192.168.1.11 -P3306 -uroot -p123456 < /opt/nacos/conf/nacos-mysql.sql

# 配置文件(复制配置示例修改即可) vim /opt/nacos/conf/application.properties(见配置示例)

# 启动单机版 nacos cd /opt/nacos/bin/ sh startup.sh -m standalone

# 访问 nacos 在浏览器输入:192.168.1.11:8848/nacos

Nacos 1.2.1版本安装(集群版):

服务器1:jdk、Nacos-server 、mysql 服务器2:jdk、Nacos-server 服务器3:jdk、Nacos-server 在三台服务器分别安装 Nacos-server 单机版 部署完成后需要将单机版 Nacos 停掉(为了启动 Nacos 集群) # 在三台服务器进行操作 # 配置集群版配置文件(复制配置示例修改即可) vim /opt/nacos/conf/cluster.conf

# 在三台服务器进行操作 # 启动集群版 nacos cd /opt/nacos/bin/ sh startup.sh

# 访问 nacos 在浏览器输入任一节点IP、Port:192.168.1.11:8848/nacos

最新回复(0)