spring cloud alibaba 之注册中心NACOS
2020-12-05 19:42
12661
3
什么是nacos
Nacos 支持基于 DNS 和基于 RPC 的服务发现(可以作为springcloud的注册中心)、动态配置服务(可以做配置中心)、动态 DNS 服务。
nacos作为注册中心
先在官网上下载nacos
安装
linux
tar -xvf nacos-server-1.0.0.tar.gz // 解压文件
sh startup.sh -m standalone // 启动nacos
bash startup.sh -m standalone // ubuntu系统,或者运行脚本报错提示 符号找不到,可尝试
windos
startup.cmd -m standalone //直接启动单机版本即可
配置 MySQL 数据库
集群模式必须使用MySQL
数据库,生产使用建议至少主备模式,或者采用高可用数据库
初始化 MySQL 数据库
脚本在nacos的conf目录下有配置文件nacos-mysql.sql
,直接执行即可
添加数据库配置
配置文件在nacos的conf目录下的application.properties
,添加以下配置
db.num=1
db.url.0=jdbc:mysql://192.168.28.131:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root
/**
*db.num 为数据库实例数量
*如果有多个数据库实例通过 db.url.0、db.url.1..... 指定不同的数据库链接
**/
修改Nacos端口(如果需要修改端口或使用集群模式)备:集群最少为三个节点
修改nacos的conf目录下application.properties
下的server.port
变量。
附带集群NGINX配置方案
upstream nacos {
server 127.0.0.1:10001;
server 127.0.0.1:10002;
server 127.0.0.1:10003;
}
server {
listen 80;
server_name test.nacos.com;
location / {
proxy_pass http://nacos;
}
}
全部评论