SpringCloud07_Nacos的概述、安装、搭建提供者、消费者工程案列、配置中心、Namespace、Group、Data ID、高可用的集群配置(八)

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: ②. nacos集群前置知识点③. 集群配置步骤写在最前面:

②. nacos集群前置知识点


①. 预计需要,1个nginx+3个nacos注册中心+1个mysql


②. 安装linux环境,安装Jdk1.8、Nginx1.8、Mysql5.7.24、nacos


③. Nacos下载linux版本


链接:https://pan.baidu.com/s/131QEa12Kc1OJa1NYJncZ-g


提取码:1234


将nacos-server-1.1.4.tar.gz上传到/opt下


在/opt下解压: tar -zxvf nacos-server-1.1.4.tar.gz


将解压好的nacos,复制到/usr/local下: cp -rv nacos /usr/local


微信图片_20220108183503.png


③. 集群配置步骤


  • ①. Linux服务器上mysql数据库配置(nacos-mysql.sql | application.properties)


微信图片_20220108183524.png


微信图片_20220108183529.png


②. application.properties


spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://1.7.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root


微信图片_20220108183600.png


微信图片_20220108183606.png


  • ③. Linux服务器上nacos的集群配置cluster.conf


  1. 梳理出3台nacos机器的不同服务端口号(3333、4444、5555)


  1. 复制出cluster.conf


微信图片_20220108183624.png


微信图片_20220108183639.png


3. 这个IP不能写127.0.0.1,必须是Linux命令hostname -i能够识别的IP


微信图片_20220108183645.png


  • ④. 编辑Nacos的启动脚本startup.sh,使它能够接受不同的启动端
  1. /mynacos/nacos/bin目录下有startup.sh
  2. 修改如下


微信图片_20220108183708.png


微信图片_20220108183732.png


执行方式如下


微信图片_20220108183746.png


查看nacos有多少个节点(ps -ef | grep nacos | grep -v grep|wc -l)


微信图片_20220108183801.png


  • ④. Nginx的配置,由它作为负载均衡器


  1. 修改nginx的配置文件


微信图片_20220108183815.png


nginx.conf


微信图片_20220108183842.png


#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    upstream cluster{
        server 127.0.0.1:3333;
        server 127.0.0.1:4444;
        server 127.0.0.1:5555;
    }
    server {
        listen       1111;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://cluster;
        }
        #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;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}


按照指定启动


微信图片_20220108183911.png


  • ⑤. 截止到此处,1个Nginx+3个nacos注册中心+1个mysql
  1. 测试通过nginx访问nacos(https://写你自己虚拟机的ip:1111/nacos/#/login)
  2. 新建一个配置测试


微信图片_20220108183928.png


linux服务器的mysql插入一条记录


微信图片_20220108183943.png


⑥. 测试:输入192.168.68.129:1111/nacos/#/login


微信图片_20220108183959.png


微信图片_20220108184004.png


微信图片_20220108184008.png


微信图片_20220108184012.png


⑦. 高可用小总结


微信图片_20220108184049.png

相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
2月前
|
存储 SpringCloudAlibaba Java
【SpringCloud Alibaba系列】一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论
一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论。
【SpringCloud Alibaba系列】一文全面解析Zookeeper安装、常用命令、JavaAPI操作、Watch事件监听、分布式锁、集群搭建、核心理论
|
3月前
|
SpringCloudAlibaba Java Nacos
SpringCloud概述
SpringCloud概述
52 1
SpringCloud概述
|
7月前
|
Java 开发工具 git
实现基于Spring Cloud的配置中心
实现基于Spring Cloud的配置中心
|
7月前
|
消息中间件 Java 开发者
Spring Cloud微服务框架:构建高可用、分布式系统的现代架构
Spring Cloud是一个开源的微服务框架,旨在帮助开发者快速构建在分布式系统环境中运行的服务。它提供了一系列工具,用于在分布式系统中配置、服务发现、断路器、智能路由、微代理、控制总线、一次性令牌、全局锁、领导选举、分布式会话、集群状态等领域的支持。
228 5
|
7月前
|
Java 开发工具 数据安全/隐私保护
深入理解Spring Cloud中的配置中心
深入理解Spring Cloud中的配置中心
|
8月前
|
Nacos 数据安全/隐私保护
springCloud之nacos服务注册与发现、配置中心
springCloud之nacos服务注册与发现、配置中心
333 0
|
8月前
springCloud之配置中心Config
springCloud之配置中心Config
|
9月前
|
负载均衡 Java 网络架构
【SpringCloud】如何理解分布式、微服务、集群
【SpringCloud】如何理解分布式、微服务、集群
88 1
|
9月前
|
存储 前端开发 Java
第十一章 Spring Cloud Alibaba nacos配置中心
第十一章 Spring Cloud Alibaba nacos配置中心
93 0
|
9月前
|
SpringCloudAlibaba Java Nacos
SpringCloud Alibaba微服务 -- Nacos使用以及注册中心和配置中心的应用(保姆级)
SpringCloud Alibaba微服务 -- Nacos使用以及注册中心和配置中心的应用(保姆级)