SpringCloud从入门到精通——基于Nacos集群部署方案

追求适度,才能走向成功;人在顶峰,迈步就是下坡;身在低谷,抬足既是登高;弦,绷得太紧会断;人,思虑过度会疯;水至清无鱼,人至真无友,山至高无树;适度,不是中庸,而是一种明智的生活态度。

导读:本篇文章讲解 SpringCloud从入门到精通——基于Nacos集群部署方案,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

基于Nacos集群部署方案

在这里插入图片描述

一、Nacos集群部署配置

  1. 将Nacos压缩包解压后复制三份,分别命名为:nacos--8748nacos--8849nacos--8950
    在这里插入图片描述

  2. 进入到nacos–8748/conf/目录下,打开application.properties文件,修改端口号、数据库配置信息:
    server.port=8748
    db.num=1
    db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
    db.user.0=root
    db.password.0=root
    在这里插入图片描述

  3. 在mysql中新建nacos数据库
    在这里插入图片描述

  4. 复制nacos–8748/conf/目录下的nacos-mysql.sql文件中的sql语句,粘贴到数据库中进行数据表创建
    在这里插入图片描述在这里插入图片描述

  5. 将nacos–8748/conf/目录下的cluster.conf.example文件重新命名为cluster.conf
    在这里插入图片描述

  6. 打开cluster.conf文件,将集群ip及端口号写入文件中(有几个集群就配置几个ip+端口号)
    在这里插入图片描述
    配置的IP一定为本机的IP地址,不可以写127.0.0.1!!
    在这里插入图片描述

  7. 进入到nacos–8748/bin/目录下,运行startup.cmd
    在这里插入图片描述

  8. nacos--8849nacos--8950配置方式如上
    在这里插入图片描述

  9. 访问Nacos管理界面,在节点列表中可以查看到刚刚启动的三个服务信息
    在这里插入图片描述

  10. Nginx配置

upstream backserver {
   	server 192.168.66.1:8748 weight=1;
   	server 192.168.66.1:8849 weight=1;
   	server 192.168.66.1:8950 weight=1;
   }
   server {
       listen       80;
       server_name  localhost;

       #charset koi8-r;

       #access_log  logs/host.access.log  main;

       location /{
   	 proxy_pass http://backserver/;
        index  index.html index.htm;
       }

       #error_page  404              /404.html;

       # redirect server error pages to the static page /50x.html
       #
       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }

       # proxy the PHP scripts to Apache listening on 127.0.0.1:80
       #
       #location ~ \.php$ {
       #    proxy_pass   http://127.0.0.1;
       #}

       # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
       #
       #location ~ \.php$ {
       #    root           html;
       #    fastcgi_pass   127.0.0.1:9000;
       #    fastcgi_index  index.php;
       #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
       #    include        fastcgi_params;
       #}

       # deny access to .htaccess files, if Apache's document root
       # concurs with nginx's one
       #
       #location ~ /\.ht {
       #    deny  all;
       #}
   }

  1. 客户端连接配置 默认使用AP模式注册
spring:
  application:
    ###服务的名称
    name: demo-nacos-client
  cloud:
    nacos:
      discovery:
        ###nacos注册地址
        server-addr: 127.0.0.1:8748,127.0.0.1:8849,127.0.0.1:8950
        enabled: true
      config:
        ###配置中心连接地址
        server-addr: 127.0.0.1:8748,127.0.0.1:8849,127.0.0.1:8950
        ###分组
        group: DEFAULT_GROUP
        ###类型
        file-extension: yaml

注意:

  1. nacos在windows版本下运行默认是单机版本需要指定startup.cmd -m cluster
  2. nacos在linux版本下运行默认是集群版本 如果想连接单机版本 startup.cmd –m standalone

Nacos 从1.0支持AP和CP模式
CP模式底层采用raft协议算法

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/131266.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!