zoukankan      html  css  js  c++  java
  • & SpringCloud-SpringCloudAlibabaNacos入门

    Edit

    SpringCloud-SpringCloudAlibabaNacos入门

    Nacos简介

    为什么叫nacos

    前四个字母为Nameing和Configuration的前两个字母,最后的s为Service

    Nacos就是注册中心+配置中心的组合
    Nacos=Eureka+Config+Bus

    nacos官方文档

    https://github.com/alibaba/Nacos

    nacos能干嘛?

    替代Eureka做服务注册中心
    替代Config做服务配置中心

    各个注册中心对比

    Alt text

    安装并运行Nacos

    Nacos作为服务注册中心

    Windows切换持久化配置derby->mysql

    Nacos默认自带的是嵌入式数据库derby

    Alt text

    执行sql脚本

    nacos/conf/目录下有出厂自带的sql脚本

    Alt text

    创建数据库nacos_config,并执行sql脚本

    Alt text

    修改nacos properties配置信息

    1.###
    2.
    3.spring.datasource.platform=mysql
    4.
    5.db.num=1
    6.db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
    7.db.user=root
    8.db.password=zb224989

    Alt text

    重新启动nacos

    新建配置

    Alt text

    查看mysql数据库

    Alt text

    Nacos集群配置(linux)

    环境

    centos虚拟机 * 3
    192.168.13.131 mysql+nginx+nacos1
    192.168.13.132 nacos2
    192.168.13.133 nacos3

    nacos linux安装

    下载nacos linux压缩包

    https://github.com/alibaba/nacos/releases

    Alt text

    tar -zxvf nacos-server-1.1.4.tar.gz

    安装完成

    mysql配置

    Alt text

    创建nacos_config数据库
    并执行nacos-mysql.sql脚本

    Alt text

    nacos->application.properties配置

    192.168.13.131 nacos application.properties

    Alt text

    192.168.13.132 nacos application.properties

    Alt text

    192.168.13.133 nacos application.properties

    Alt text

    nacos集群配置cluster.conf

    192.168.13.131 nacos cluster.conf

    Alt text

    192.168.13.132 nacos cluster.conf

    Alt text

    192.168.13.133 nacos cluster.conf

    Alt text

    nginx 配置

    Alt text

    访问 http://192.168.13.131:1111/nacos

    访问http://192.168.13.131:1111/nacos
    并添加配置

    将cloudalibaba-provider-payment9002注册进nacos集群

    修改cloudalibaba-provider-payment9002 配置文件

    1.server:
    2. port: 9002
    3.
    4.spring:
    5. application:
    6. name: nacos-payment-provider
    7. cloud:
    8. nacos:
    9. discovery:
    10. #server-addr: localhost:8848 #配置nacos地址
    11. #换成nginx的1111端口,集群
    12. server-addr: 192.168.13.131:1111
    13.
    14.#暴露监控端点
    15.management:
    16. endpoints:
    17. web:
    18. exposure:
    19. include: "*"
    20.

    启动查看
    http://192.168.13.131:1111/nacos服务列表

    %23%20SpringCloud-SpringCloudAlibabaNacos%u5165%u95E8%0A%5Btoc%5D%0A%0A%0A%0A%23%23%20Nacos%u7B80%u4ECB%0A%0A%23%23%23%20%u4E3A%u4EC0%u4E48%u53EBnacos%0A%u524D%u56DB%u4E2A%u5B57%u6BCD%u4E3ANameing%u548CConfiguration%u7684%u524D%u4E24%u4E2A%u5B57%u6BCD%2C%u6700%u540E%u7684s%u4E3AService%0A%0A%0ANacos%u5C31%u662F%u6CE8%u518C%u4E2D%u5FC3+%u914D%u7F6E%u4E2D%u5FC3%u7684%u7EC4%u5408%0ANacos%3DEureka+Config+Bus%0A%0A%23%23%23%20nacos%u5B98%u65B9%u6587%u6863%0Ahttps%3A//github.com/alibaba/Nacos%0A%0A%0A%0A%0A%23%23%23%20nacos%u80FD%u5E72%u561B%3F%0A%u66FF%u4EE3Eureka%u505A%u670D%u52A1%u6CE8%u518C%u4E2D%u5FC3%0A%u66FF%u4EE3Config%u505A%u670D%u52A1%u914D%u7F6E%u4E2D%u5FC3%0A%0A%0A%0A%0A%23%23%23%20%u5404%u4E2A%u6CE8%u518C%u4E2D%u5FC3%u5BF9%u6BD4%0A%21%5BAlt%20text%5D%28./1598231671980.png%29%0A%0A%0A%0A%0A%23%23%20%u5B89%u88C5%u5E76%u8FD0%u884CNacos%0A%0A*%20%u672C%u5730Java8+Maven%u73AF%u5883%u5DF2%u7ECFok%0A*%20%u5B98%u7F51%u4E0B%u8F7DNacos%20%0A%20%20%20%20*%20https%3A//github.com/alibaba/nacos/releases%0A*%20%u89E3%u538B%u5B89%u88C5%u5305%uFF0C%u76F4%u63A5%u8FD0%u884Cbin%u76EE%u5F55%u4E0B%u7684startup.cmd%0A*%20%u547D%u4EE4%u8FD0%u884C%u6210%u529F%u540E%u76F4%u63A5%u8BBF%u95EEhttp%3A//localhost%3A8848/nacos%0A%20%20%20%20*%20%u9ED8%u8BA4%u7528%u6237%u540D%u5BC6%u7801%u90FD%u662Fnacos%0A*%20%21%5BAlt%20text%5D%28./1598231694174.png%29%0A%0A%0A%0A%0A%23%23%20Nacos%u4F5C%u4E3A%u670D%u52A1%u6CE8%u518C%u4E2D%u5FC3%0A%0A%0A%0A%0A%0A%0A%23%23%20Windows%u5207%u6362%u6301%u4E45%u5316%u914D%u7F6Ederby-%3Emysql%0A%0A**Nacos%u9ED8%u8BA4%u81EA%u5E26%u7684%u662F%u5D4C%u5165%u5F0F%u6570%u636E%u5E93derby**%0A%21%5BAlt%20text%5D%28./1598231819029.png%29%0A%0A%0A%23%23%23%20%u6267%u884Csql%u811A%u672C%0A%0A**nacos/conf/%u76EE%u5F55%u4E0B%u6709%u51FA%u5382%u81EA%u5E26%u7684sql%u811A%u672C**%0A%21%5BAlt%20text%5D%28./1598231857349.png%29%0A%0A%0A**%u521B%u5EFA%u6570%u636E%u5E93nacos_config%2C%u5E76%u6267%u884Csql%u811A%u672C**%0A%21%5BAlt%20text%5D%28./1598231864936.png%29%0A%0A%0A%23%23%23%20%u4FEE%u6539nacos%20properties%u914D%u7F6E%u4FE1%u606F%0A%60%60%60%0A%23%23%23%0A%0Aspring.datasource.platform%3Dmysql%0A%0Adb.num%3D1%0Adb.url.0%3Djdbc%3Amysql%3A//127.0.0.1%3A3306/nacos_config%3FcharacterEncoding%3Dutf8%26connectTimeout%3D1000%26socketTimeout%3D3000%26autoReconnect%3Dtrue%0Adb.user%3Droot%0Adb.password%3Dzb224989%0A%60%60%60%0A%21%5BAlt%20text%5D%28./1598231902475.png%29%0A%0A%0A%23%23%23%20%u91CD%u65B0%u542F%u52A8nacos%0A%u65B0%u5EFA%u914D%u7F6E%0A%21%5BAlt%20text%5D%28./1598231923368.png%29%0A%0A%0A%u67E5%u770Bmysql%u6570%u636E%u5E93%0A%21%5BAlt%20text%5D%28./1598231934350.png%29%0A%0A%0A%0A%0A%0A%0A%0A%0A%0A%23%23%20Nacos%u96C6%u7FA4%u914D%u7F6E%28linux%29%0A%23%23%23%20%u73AF%u5883%0A%0Acentos%u865A%u62DF%u673A%20*%203%0A192.168.13.131%20mysql+nginx+nacos1%0A192.168.13.132%20nacos2%0A192.168.13.133%20nacos3%0A%0A%0A%23%23%23%20nacos%20linux%u5B89%u88C5%0A%u4E0B%u8F7Dnacos%20linux%u538B%u7F29%u5305%0A%0Ahttps%3A//github.com/alibaba/nacos/releases%0A%0A%21%5BAlt%20text%5D%28./1598232054960.png%29%0A%0Atar%20-zxvf%20nacos-server-1.1.4.tar.gz%0A%0A%u5B89%u88C5%u5B8C%u6210%0A%0A%0A%23%23%23%20mysql%u914D%u7F6E%0A%21%5BAlt%20text%5D%28./1598232094730.png%29%0A%0A%u521B%u5EFAnacos_config%u6570%u636E%u5E93%0A%u5E76%u6267%u884Cnacos-mysql.sql%u811A%u672C%0A%0A%21%5BAlt%20text%5D%28./1598232107359.png%29%0A%0A%0A%0A%23%23%23%20nacos-%3Eapplication.properties%u914D%u7F6E%0A%0A192.168.13.131%20nacos%20application.properties%0A%21%5BAlt%20text%5D%28./1598232149080.png%29%0A%0A%0A%0A192.168.13.132%20nacos%20application.properties%0A%21%5BAlt%20text%5D%28./1598232159487.png%29%0A%0A%0A%0A192.168.13.133%20nacos%20application.properties%0A%21%5BAlt%20text%5D%28./1598232168740.png%29%0A%0A%0A%0A%0A%0A%0A%0A%23%23%23%20nacos%u96C6%u7FA4%u914D%u7F6Ecluster.conf%0A%0A192.168.13.131%20nacos%20cluster.conf%0A%21%5BAlt%20text%5D%28./1598232194023.png%29%0A%0A%0A192.168.13.132%20nacos%20cluster.conf%0A%21%5BAlt%20text%5D%28./1598232199497.png%29%0A%0A%0A192.168.13.133%20nacos%20cluster.conf%0A%21%5BAlt%20text%5D%28./1598232209600.png%29%0A%0A%0A%0A%23%23%23%20nginx%20%u914D%u7F6E%0A%21%5BAlt%20text%5D%28./1598232244775.png%29%0A%0A%0A%23%23%23%20%u8BBF%u95EE%20http%3A//192.168.13.131%3A1111/nacos%0A%0A%0A%u8BBF%u95EEhttp%3A//192.168.13.131%3A1111/nacos%0A%u5E76%u6DFB%u52A0%u914D%u7F6E%0A%0A%0A%0A%23%23%23%20%u5C06cloudalibaba-provider-payment9002%u6CE8%u518C%u8FDBnacos%u96C6%u7FA4%0A%0A%u4FEE%u6539cloudalibaba-provider-payment9002%20%u914D%u7F6E%u6587%u4EF6%0A%0A%60%60%60%0Aserver%3A%0A%20%20port%3A%209002%0A%0Aspring%3A%0A%20%20application%3A%0A%20%20%20%20name%3A%20nacos-payment-provider%0A%20%20cloud%3A%0A%20%20%20%20nacos%3A%0A%20%20%20%20%20%20discovery%3A%0A%20%20%20%20%20%20%20%20%23server-addr%3A%20localhost%3A8848%20%23%u914D%u7F6Enacos%u5730%u5740%0A%20%20%20%20%20%20%20%20%23%u6362%u6210nginx%u76841111%u7AEF%u53E3%2C%u96C6%u7FA4%0A%20%20%20%20%20%20%20%20server-addr%3A%20192.168.13.131%3A1111%0A%0A%23%u66B4%u9732%u76D1%u63A7%u7AEF%u70B9%0Amanagement%3A%0A%20%20endpoints%3A%0A%20%20%20%20web%3A%0A%20%20%20%20%20%20exposure%3A%0A%20%20%20%20%20%20%20%20include%3A%20%22*%22%0A%0A%60%60%60%0A%0A%u542F%u52A8%u67E5%u770B%0Ahttp%3A//192.168.13.131%3A1111/nacos%u670D%u52A1%u5217%u8868%0A%0A

  • 相关阅读:
    ABC223
    ABC224
    线代口胡
    「数学」计算几何
    「字符串」后缀数组
    插值计算
    2021年11月 环太湖骑行记(骑行开始30公里后,因疫情而中止)
    工作感受月记202111月
    js 调用本地 exe 方法(通用,支持目前 大部分主流浏览器,chrome,火狐,ie)
    8.23第七周
  • 原文地址:https://www.cnblogs.com/doagain/p/14969353.html
Copyright © 2011-2022 走看看