Nacos部署
一、单机部署
1.1、环境依赖
- 64 bit OS,支持 Linux/Unix/Mac/Windows,推荐选用 Linux/Unix/Mac
- 64 bit JDK 1.8+;
- Maven 3.2.x+;
1.2、下载
# 版本自己挑: https://github.com/alibaba/nacos/releases
[root@nacos ~]# wget https://github.com/alibaba/nacos/releases/download/2.0.0-bugfix/nacos-server-2.0.0.tar.gz
1.3、部署
[root@nacos ~]# tar -xvf nacos-server-2.0.0.tar.gz -C /app/
1.4、单机启动
[root@nacos ~]# cd /app/nacos/bin/
[root@nacos bin]# sh startup.sh -m standalone
1.5、验证
[root@nacos ~]# tail -f /app/nacos/logs/start.out
2021-08-17 09:16:27,881 INFO Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@ef1695a, org.springframework.security.web.context.SecurityContextPersistenceFilter@b835727, org.springframework.security.web.header.HeaderWriterFilter@10cd6753, org.springframework.security.web.csrf.CsrfFilter@168cd36b, org.springframework.security.web.authentication.logout.LogoutFilter@319c3a25, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@2c8662ac, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@77eb5790, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@58860997, org.springframework.security.web.session.SessionManagementFilter@47af099e, org.springframework.security.web.access.ExceptionTranslationFilter@3901f6af]
2021-08-17 09:16:28,210 INFO Initializing ExecutorService 'taskScheduler'
2021-08-17 09:16:28,267 INFO Exposing 16 endpoint(s) beneath base path '/actuator'
2021-08-17 09:16:28,560 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'
# 端口校验
[root@nacos conf]# ss -ntl | grep 8848
LISTEN 0 100 :::8848 :::*
1.6、页面访问
http://192.168.1.55:8848/nacos/
默认账号密码:nacos/nacos
1.7、OPENAPI验证
# 服务注册
[root@nacos ~]# curl -X PUT 'http://127.0.0.1:8848/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'
caused: service not found, namespace: public, service: Service{namespace='public', group='DEFAULT_GROUP', name='nacos.naming.serviceName', ephemeral=true, revision=0};
# 服务发现
[root@nacos ~]# curl -X GET 'http://127.0.0.1:8848/nacos/v1/ns/instance/list?serviceName=nacos.naming.serviceName'
{"name":"DEFAULT_GROUP@@nacos.naming.serviceName","groupName":"DEFAULT_GROUP","clusters":"","cacheMillis":10000,"hosts":[],"lastRefTime":1629164329309,"checksum":"","allIPs":false,"reachProtectionThreshold":false,"valid":true}
# 发布配置
[root@nacos ~]# curl -X POST "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=helloWorld"
true
# 获取配置
[root@nacos ~]# curl -X GET "http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test"
helloWorld
1.8、关闭
[root@nacos bin]# sh shutdown.sh
The nacosServer(20159) is running...
Send shutdown request to nacosServer(20159) OK
1.9、外部MySQL数据库支持
- 版本要求:5.6.5+ ,mysql 8 以下 (自行安装)
- 初始化mysql数据库,新建数据库nacos_config,数据库初始化文件
/app/nacos/conf/nacos-mysql.sql
- 修改
/conf/application.properties
文件
# 1、创建数据库
CREATE DATABASE IF NOT EXISTS nacos_devtest CHARACTER SET utf8;
# 2、导入nacos-mysql.sql
use nacos_devtest
source /app/nacos-mysql.sql
- 修改配置文件,末尾增加
[root@nacos conf]# vim /app/nacos/conf/application.properties
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.1.208:3306/nacos_devtest?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=username
db.password=password
1.10、再次启动
[root@nacos ~]# cd /app/nacos/bin/
[root@nacos bin]# sh startup.sh -m standalone
二、集群部署
https://nacos.io/zh-cn/docs/cluster-mode-quick-start.html