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

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: ②. 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

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
4天前
|
SpringCloudAlibaba 应用服务中间件 Nacos
【微服务 SpringCloudAlibaba】实用篇 · Nacos配置中心(下)
【微服务 SpringCloudAlibaba】实用篇 · Nacos配置中心
16 0
|
4天前
|
JSON SpringCloudAlibaba Java
【微服务 SpringCloudAlibaba】实用篇 · Nacos配置中心(上)
【微服务 SpringCloudAlibaba】实用篇 · Nacos配置中心
17 1
|
4天前
|
Nacos
nacos 配置页面的模糊查询
nacos 配置页面的模糊查询
|
4天前
|
Linux Nacos 数据库
【微服务】生产部署nacos集群(三个节点)
【微服务】生产部署nacos集群(三个节点)
29 1
|
4天前
|
算法 Nacos Docker
docker部署nacos集群
docker部署nacos集群
31 0
|
4天前
|
机器学习/深度学习 Java Nacos
Nacos 配置中心(2023旧笔记)
Nacos 配置中心(2023旧笔记)
21 0
|
4天前
|
Java Nacos Sentinel
Spring Cloud Alibaba 面试题及答案整理,最新面试题
Spring Cloud Alibaba 面试题及答案整理,最新面试题
257 0
|
4天前
|
SpringCloudAlibaba Java 持续交付
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
【构建一套Spring Cloud项目的大概步骤】&【Springcloud Alibaba微服务分布式架构学习资料】
204 0
|
4天前
|
Java API Nacos
第十二章 Spring Cloud Alibaba Sentinel
第十二章 Spring Cloud Alibaba Sentinel
30 0
|
4天前
|
存储 前端开发 Java
第十一章 Spring Cloud Alibaba nacos配置中心
第十一章 Spring Cloud Alibaba nacos配置中心
29 0