概述
Nacos简介
[if !supportLists]n [endif]Nacos是Dynamic Naming and Configuration Service的首字母简称,一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台。Nacos是构建以“服务”为中心的现代应用架构的服务基础设施。我们可以将Nacos作为配置中心和注册中心使用。
[if !supportLists]n [endif]云原生:是基于分布部署和统一运管的分布式云,以容器、微服务、DevOps等技术为基础建立的一套云技术产品体系。
[if !supportLists]n [endif]Nacos相当于Eureka、Config、Bus三大组件的集合体。
官网与手册
[if !supportLists]n [endif]官方网站:https://nacos.io/zh-cn/
[if !supportLists]n [endif]中文手册:https://nacos.io/zh-cn/docs/what-is-nacos.html
安装与运行
[if !supportLists]n [endif]下载:
[if !supportLists]n [endif]文件夹结构:
[if !supportLists]n [endif]修改nacos/conf/application.properties配置文件,配置Nacos数据源:
#*************** 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=111111
[if !supportLists]n [endif]修改nacos/bin/startup.cmd启动文件,配置启动模式:
set MODE="standalone"
[if !supportLists]n [endif]执行nacos/config/nacos-mysql.sql脚本文件,注意先在本机的MYSQL数据库中创建nacos数据库;
[if !supportLists]n [endif]注意:MYSQL数据库必须时5.7以上的版本,因为在nacos-mysql.sql文件中,创建表时多个字段采用了“DEFAULT CURRENT_TIMESTAMP”子句,在低版本的MYSQL中一个表只允许使用一次该子句,例如:
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';
[if !supportLists]n [endif]打开CMD命令窗口,启动Nacos,看到如下启动信息代表启动成功:
D:\Softwave\nacos\bin>startup.cmd
"nacos is starting with standalone"
,--.
,--.'|
,--,: : | Nacos 1.4.6
,`--.'`| ' : ,---. Running in stand alone mode, All function modules
| : : | | ' ,'\ .--.--. Port: 8848
: | \ | : ,--.--. ,---. / / | / / ' Pid: 47620
| : ' '; | / \ / \. ; ,. :| : /`./ Console: http://192.168.3.99:8848/nacos/index.html
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
| | | \ | \__\/: . .. ' / ' | .; : \ \ `. https://nacos.io
' : | ; .' ," .--.; |' ; :__| : | `----. \
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
' : | ; : .' \ : : `----' '--'. /
; |.' | , .-./\ \ / `--'---'
'---' `--`---' `----'
2023-11-25 14:01:01,456 INFO Tomcat initialized with port(s): 8848 (http)
2023-11-25 14:01:01,785 INFO Root WebApplicationContext: initialization completed in 2236 ms
2023-11-25 14:01:03,213 INFO Adding welcome page: class path resource [static/index.html]
2023-11-25 14:01:03,479 WARN You are asking Spring Security to ignore Ant [pattern='/**']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2023-11-25 14:01:03,479 INFO Will not secure Ant [pattern='/**']
2023-11-25 14:01:03,495 INFO Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@2dd80673, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@4af0df05, org.springframework.security.web.context.SecurityContextPersistenceFilter@3700ec9c, org.springframework.security.web.header.HeaderWriterFilter@5f6722d3, org.springframework.security.web.csrf.CsrfFilter@178213b, org.springframework.security.web.authentication.logout.LogoutFilter@2d1dee39, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@5911e990, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1d470d0, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@57ea113a, org.springframework.security.web.session.SessionManagementFilter@294e5088, org.springframework.security.web.access.ExceptionTranslationFilter@2c5529ab]
2023-11-25 14:01:03,526 INFO Exposing 1 endpoint(s) beneath base path '/actuator'
2023-11-25 14:01:03,571 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'
2023-11-25 14:01:03,589 INFO Nacos started successfully in stand alone mode. use external storage
[if !supportLists]n [endif]打开浏览器,访问Nacos Web管理界面,如下图: