文章旨在 简单易懂,学习交流;文章中会尽量避免其他 关联内容;
其他关联的 微服务内容会单独 启动专题说明;也可留言,会第一时间解答,相互交流
非喜勿喷;
下载 安装包
https://github.com/alibaba/nacos/releases
配置文件说明
#*************** Spring Boot Related Configurations ***************#
### Default web context path:
server.servlet.contextPath=/nacos
### 端口
### Default web server port:
server.port=8842
#*************** 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 ***************#
### 默认 内嵌式数据库 Derby 数据存放在 /nacos/data/derby-data 目录
### 如果使用mysql 存储数据 打开一下配置
### 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_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456
单体模式
Linux/Unix/Mac
Run the following command to start(standalone means non-cluster mode):
sh startup.sh -m standalone
If you are using a ubuntu system, or encounter this error message [[symbol not found, try running as follows:
bash startup.sh -m standalone
Windows
Run the following command to start(standalone means non-cluster mode):
cmd startup.cmd -m standalone
集群模式
此处 本地机器 多实例 模拟伪集群 目录如下:
配置文件修改
cd nacos8840/conf
#2022-11-06T14:46:24.643
### 配置所有节点的 ip:port
${真实ip}:8840
${真实ip}:8842
${真实ip}:8844
启动
所有节点单独启动 即可
sh startup.sh
方便启动 编写 shell
shutdown.sh
sh ./nacos8840/bin/shutdown.sh;
sh ./nacos8842/bin/shutdown.sh;
sh ./nacos8844/bin/shutdown.sh
startup.sh
sh ./nacos8840/bin/startup.sh;
sh ./nacos8842/bin/startup.sh;
sh ./nacos8844/bin/startup.sh
window 可自行百度
访问
- 可以 每台机器 单独访问
- 配合nginx 负载
nginx配置如下:
upstream nacos-cluster {
server 127.0.0.1:8840;
server 127.0.0.1:8842;
server 127.0.0.1:8844;
}
server {
listen 8848;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location /nacos {
proxy_pass http://nacos-cluster/nacos;
}
}
访问界面
各实例单独访问: localhost:8840/nacos localhost:8840/nacos localhost:8840/nacos
nginx : localhost:8848/nacos
参考资料
https://nacos.io/en-us/docs/quick-start.html