nacos介绍
Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据及流量管理。
nacos特性
服务发现和服务健康监测
动态配置服务
动态 DNS 服务
服务及其元数据管理
windows安装与启动nacos
nacos安装:https://nacos.io/zh-cn/docs/quick-start.html
下载最新的nacos,我下载的是nacos2.0.3的版本
由于nacos是基于数据库来配置系统:
运行sql,生成数据表
配置application.properties文件:
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://xxx.xxx.xxx.xxxx:3389/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=spy1679358426
运行项目:127.0.0.1:8848/nacos
注册服务
server:
port: 3802
spring:
application:
name: student-service
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848/
Docker安装与启动nacos
下载显示镜像
[root@ecs-140051 nacos]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
teacher-service v2 f7d17d63bf08 5 days ago 668MB
education v1 5637f6f48b52 5 days ago 677MB
tomcat v1-8 e82154b33e59 6 days ago 534MB
tomcat 8 ae1a89e0f415 11 days ago 482MB
tomcat latest 07eee1a00569 11 days ago 483MB
nginx latest 670dcc86b69d 13 days ago 142MB
mysql latest 33037edcac9b 2 weeks ago 444MB
nacos/nacos-server 2.0.3 433eb51fef8d 12 months ago 1.05GB
tomcat 8.5.54-jdk8-openjdk eb2cfb95e04d 2 years ago 529MB
centos 7.2.1511 9aec5c5fe4ba 3 years ago 195MB
java 8 d23bdf5b1b1b 5 years ago 643MB
编写启动文件:
docker run -d --name nacos-sunpy -p 8848:8848 --privileged=true --restart=always -e JVM_XMS=256m -e JVM_XMX=256m -e MODE=standalone -e PREFER_HOST_MODE=hostname -v /home/springcloud-alibaba/nacos/logs:/etc/nacos/logs -v /home/springcloud-alibaba/nacos/init.d/custom.properties:/etc/nacos/init.d/custom.properties nacos/nacos-server:2.0.3
报错:
nacos-server.sh: line 2: $'\r': command not found
nacos-server.sh: line 3: $'\r': command not found
nacos-server.sh: line 4: $'\r': command not found
nacos-server.sh: line 5: $'\r': command not found
nacos-server.sh: line 6: $'\r': command not found
nacos-server.sh: line 7: $'\r': command not found
nacos-server.sh: line 8: $'\r': command not found
nacos-server.sh: line 9: $'\r': command not found
nacos-server.sh: line 10: $'\r': command not found
命令模式设置
:set ff=unix
:wq!
执行:
[root@ecs-140051 nacos]# sh nacos-server.sh
c0da0a58a8e8ecddaa3929d7ffcb84466345c5f2c7fcf7c0669420c8df410f65
查看容器:
[root@ecs-140051 nacos]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c0da0a58a8e8 nacos/nacos-server:2.0.3 "bin/docker-startup.…" 31 seconds ago Up 30 seconds 0.0.0.0:8848->8848/tcp, :::8848->8848/tcp nacos-sunpy
692b8d4e49d9 teacher-service:v2 "java -jar teacher-s…" 5 days ago Up 5 days 0.0.0.0:3801->8080/tcp, :::3801->8080/tcp teacher-service-2
14c6ae3d049c mysql:latest "docker-entrypoint.s…" 6 days ago Up 6 days 33060/tcp, 0.0.0.0:3389->3306/tcp, :::3389->3306/tcp mysql
网友评论