nacos使用
版本:1.4.0
下载
从nacos官网下载,https://nacos.io/zh-cn/docs/quick-start.html
单机
启动:startup.cmd -m standalone
因为默认是集群启动,所以这里要加上单机的参数
浏览器上访问,http:localhost:8848/nacos/index.html
集群
复制
复制出2个nacos,一共3个来搭建集群
创建mysql数据库
单机默认使用内嵌的数据库,集群时需要配置mysql数据库
create database nacos
使用nacso-mysql.sql中的sql语句创建表
修改配置文件
application.properties添加如下配置
spring.datasource.platform=mysql
db.num=1
db.url=jdbc:mysql://localhost:3306/nacos?serverTimezone=UTC
db.user=test
db.password=test
cluster.conf添加节点的ip和port,应该是用来同步数据使用的
localhost:8847
localhost:8848
localhost:8849
启动
startup.cmd
配置nginx
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 8082;
server_name localhost;
location / {
proxy_pass http://nacosCluster;
}
}
upstream nacosCluster {
server 127.0.0.1:8847;
server 127.0.0.1:8848;
server 127.0.0.1:8849;
}
}
访问
http://localhost:8082/nacos/index.html