当前位置:网站首页>Nacos 下载启动、配置 MySQL 数据库
Nacos 下载启动、配置 MySQL 数据库
2022-07-02 06:29:00 【不懂一休】
官方网站: https://nacos.io/zh-cn/docs/quick-start.html
一、window 启动
1、Nacos 下载
Nacos 下载地址:https://github.com/alibaba/nacos/releases
2、nacos 配置 MySQL 数据库
- 将 nacos 目录下的 config/nacos-mysql.sql 导入到MySQL,库名随便指定
- 修改 config/application.properties 文件配置 MySQL 数据库
#*************** 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_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456
3、启动 nacos
开启 nacos
Linux/Unix/Mac
启动命令(standalone代表着单机模式运行,非集群模式):
sh startup.sh -m standalone
如果您使用的是ubuntu系统,或者运行脚本报错提示[[符号找不到,可尝试如下运行:
bash startup.sh -m standalone
Windows
启动命令(standalone代表着单机模式运行,非集群模式):
startup.cmd -m standalone
访问地址 http://127.0.0.1:8848/nacos ,默认登陆用户名密码 nacos/nacos,新增命名空间,新建配置文件如下
二、docker 启动
1、docker 拉取 nacos镜像
DockerHub 下载镜像 https://registry.hub.docker.com/r/nacos/nacos-server
docker pull nacos/nacos-server
2、初始化 MySQL 数据库脚本
https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql
3、docker 启动 nacos(配置 MySQL 连接)
docker run -d \
-e PREFER_HOST_MODE=ip \
-e MODE=standalone \
-e SPRING_DATASOURCE_PLATFORM=mysql \
-e MYSQL_SERVICE_HOST=42.0.0.0 \
-e MYSQL_SERVICE_PORT=3306 \
-e MYSQL_SERVICE_DB_NAME=nacos_config \
-e MYSQL_SERVICE_USER=root \
-e MYSQL_SERVICE_PASSWORD=123456 \
-e NACOS_APPLICATION_PORT=8848 \
-p 8848:8848 -p 9848:9848 -p 9849:9849 \
--name nacos \
--restart=always \
--privileged=true \
nacos/nacos-server
访问地址: http://42.0.0.0:8848/nacos 默认用户名密码: nacos/nacos,新增命名空间,新建配置文件如下
4、解决问题
①、Nacos Server did not start because dumpservice bean construction failure : No DataSource set
保证数据库连接正确,查看数据库名、刷新数据库连接、检查用户名密码、可加长连接超时时间、设置时区
②、server error: such as timeout. Request nacos server failed
如果是云服务器需要开启 8848、 9848 、9849 端口否则报错 server error: such as timeout. Request nacos server failed:
端口说明:https://nacos.io/zh-cn/docs/2.0.0-compatibility.html
Nacos2.0 (8848、 9848 、9849 )版本相比 1.X (8848)新增了gRPC的通信方式,因此需要增加2个端口。新增端口是在配置的主端口(server.port)基础上,进行一定偏移量自动生成。
端口 | 与主端口的偏移量 | 描述 |
---|---|---|
8848 | nacos 主端口号 | |
9848 | 1000 | 客户端 gRPC 请求服务端端口,用于客户端向服务端发起连接和请求 |
9849 | 1001 | 服务端 gRPC 请求服务端端口,用于服务间同步等 |
三、docker nacos 集群搭建
拉取镜像和初始化 nacos 数据库和上面的单机模式相同,以下 docker nacos 最新 2.0.4 版本部署成功,云服务器防火墙配置下面用到的端口
1、启动集群
注意需要开启 7848 端口,默认端口 8848 减去 1000,否则会报The Raft Group [naming_persistent_service] did not find the Leader node;
或Nacos cluster is running with 1.X mode, can't accept gRPC request temporarily. Please check the server status or close Double write to force open 2.0 mode. Detail https://nacos.io/en-us/docs/2.0.0-upgrading.html.
或caused: old raft protocol already stop;
192.168.1.1 服务器 nacos1
docker run -d\
-e PREFER_HOST_MODE=ip\
-e MODE=cluster\
-e SPRING_DATASOURCE_PLATFORM=mysql\
-e MYSQL_SERVICE_HOST=192.168.1.10\
-e MYSQL_SERVICE_PORT=3306\
-e MYSQL_SERVICE_DB_NAME=nacos_config\
-e MYSQL_SERVICE_USER=username\
-e MYSQL_SERVICE_PASSWORD=password\
-e NACOS_APPLICATION_PORT=8848\
-e NACOS_SERVERS="192.168.1.1:8848 192.168.1.1:8846 192.168.1.2:8848"\
-e NACOS_SERVER_IP=192.168.1.1\
-p 8848:8848 -p 9848:9848 -p 9849:9849 -p 7848:7848\
--name nacos --restart=always nacos/nacos-server
192.168.1.1 服务器 nacos 2
docker run -d\
-e PREFER_HOST_MODE=ip\
-e MODE=cluster\
-e SPRING_DATASOURCE_PLATFORM=mysql\
-e MYSQL_SERVICE_HOST=192.168.1.10\
-e MYSQL_SERVICE_PORT=3306\
-e MYSQL_SERVICE_DB_NAME=nacos_config\
-e MYSQL_SERVICE_USER=username\
-e MYSQL_SERVICE_PASSWORD=password\
-e NACOS_APPLICATION_PORT=8846\
-e NACOS_SERVERS="192.168.1.1:8848 192.168.1.1:8846 192.168.1.2:8848"\
-e NACOS_SERVER_IP=192.168.1.1\
-p 8846:8846 -p 9846:9846 -p 9847:9847 -p 7846:7846\
--name nacos2 --restart=always nacos/nacos-server
192.168.1.2 服务器 nacos3
docker run -d\
-e PREFER_HOST_MODE=ip\
-e MODE=cluster\
-e SPRING_DATASOURCE_PLATFORM=mysql\
-e MYSQL_SERVICE_HOST=192.168.1.10\
-e MYSQL_SERVICE_PORT=3306\
-e MYSQL_SERVICE_DB_NAME=nacos_config\
-e MYSQL_SERVICE_USER=username\
-e MYSQL_SERVICE_PASSWORD=password\
-e NACOS_APPLICATION_PORT=8848\
-e NACOS_SERVERS="192.168.1.1:8848 192.168.1.1:8846 192.168.1.2:8848"\
-e NACOS_SERVER_IP=192.168.1.2\
-p 8848:8848 -p 9848:9848 -p 9849:9849 -p 7848:7848\
--name nacos --restart=always nacos/nacos-server
2、查看集群
此时 随便进一个服务地址 即可
上面的状态全部是 up 不一定集群搭建成功,点击节点元数据查看是否能选取 leader
或者使用接口获取 leader
http://192.168.1.1:8080/nacos/v1/ns/raft/leader,更多 nacos 相关 API 可参考 https://nacos.io/zh-cn/docs/open-api.html
如果不能选取 leader, 可以查看 nacos/logs 目录下的 nacos.log、 naming-raft.log、protocol-raft.log、nacos-cluster.log 、naming-server.log 日志看是否报错
3、nginx 代理 nacos 集群
docker 下载启动 nginx 容器不做阐述
如果你已经挂载了 nginx 的配置文件直接修改即可,没有挂载也可以进入容器修改
default.conf 我配置的比较简单,权重自己配置
upstream nacosList {
server 192.168.1.1:8848 weight=1;
server 192.168.1.2:8848 weight=2;
server 192.168.1.1:8846 weight=3;
}
server {
listen 80;
listen [::]:80;
server_name 192.168.1.1;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /nacos {
proxy_pass http://nacosList/nacos;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
我的 nginx 8080 映射 80,如下 nginx f负载均衡成功
4、关闭双写
nacos 文档说明关闭双写可以节省性能开销
PUT : http://192.168.1.1:8848/nacos/v1/ns/operator/switches?entry=doubleWriteEnabled&value=false
logs/naming-server.log 日志中观察到 Disable Double write, stop and clean v1.x cache and features字样,说明关闭双写。
5、服务上下线
nacos 控制台注册的服务可以正常上下线
边栏推荐
- IP协议与IP地址
- c语言自定义类型枚举,联合(枚举的巧妙使用,联合体大小的计算)
- Matlab mathematical modeling tool
- Jupyter Notebook常用快捷键(在命令模式中按H也可查看)
- Carla-ue4editor import Roadrunner map file (nanny level tutorial)
- HCIA—應用層
- Carsim-路面3D形状文件参数介绍
- Web安全--核心防御机制
- Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
- Opencv's experience of confusing X and Y coordinates
猜你喜欢
STM32-新建工程(参考正点原子)
Installation and use of simple packaging tools
Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)
文件上传-upload-labs
How to build the alliance chain? How much is the development of the alliance chain
When a custom exception encounters reflection
File upload and download performance test based on the locust framework
Linked list classic interview questions (reverse the linked list, middle node, penultimate node, merge and split the linked list, and delete duplicate nodes)
sqli-labs第12关
Use of opencv3 6.2 low pass filter
随机推荐
Sparse matrix storage
什么是SQL注入
Vs code configuration problem
Force buckle method summary: sliding window
Use of OpenCV 6.4 median filter
Introduction to anti interception technology of wechat domain name
Force deduction method summary: find classes
Hcia - Application Layer
In depth understanding of prototype drawings
How to build the alliance chain? How much is the development of the alliance chain
【无标题】
Honeypot attack and defense drill landing application scheme
Web安全--核心防御机制
The source code of the live app. When the verification method is mailbox verification, the verification code is automatically sent to the entered mailbox
Carsim-实时仿真的动画同步问题
C language custom type enumeration, Union (clever use of enumeration, calculation of union size)
力扣每日一题刷题总结:二叉树篇(持续更新)
HCIA—應用層
Longest isometric subsequence
Matlab-其它