nacos集群部署和VIP部署

2024-09-01 06:36
文章标签 部署 集群 nacos vip

本文主要是介绍nacos集群部署和VIP部署,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. 准备工作

nacos版本2.2.1
nginx版本1.24.0

2. nacos集群部署

2.1 下载nacos版本后,解压,然后复制三份nacos
在这里插入图片描述
2.2 分别修改三个nacos文件下config目录下的application.properties文件,三个nacos的端口修改为8846,8848,8850
在这里插入图片描述
2.3 修改conf文件夹下的cluster.conf.example文件的后缀,去掉.example(变成cluster.conf文件),并在里面添加内容,将这个文件分别复制到3个nacos下的conf目录下;
在这里插入图片描述
2.4 在启动三个nacos前需要进行的修改操作
由于nacos2.0之后需要配置密钥,分别修改三个nacos文件下config目录下的application.properties文件,添加密钥。
在这里插入图片描述
完整的文件内容(只有生效的部分):


server.servlet.contextPath=/nacos
server.error.include-message=ALWAYS
server.port=8848#注意这里我是本地指定唯一网卡地址,如果是远程的话,该地址填写远程地址
nacos.inetutils.ip-address=127.0.0.1spring.datasource.platform=mysql
spring.sql.init.platform=mysql### Count of DB:
db.num=1### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
db.user.0=root
db.password.0=123456### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2management.metrics.export.elastic.enabled=falsemanagement.metrics.export.influx.enabled=falseserver.tomcat.accesslog.enabled=trueserver.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}iserver.tomcat.basedir=file:.
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**nacos.core.auth.system.type=nacosnacos.core.auth.enabled=falsenacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=false
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=securitynacos.core.auth.plugin.nacos.token.cache.enable=false
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789
nacos.istio.mcp.server.enabled=false

2.5 在nacos的bin目录下使用集群启动命令(3个nacos都需要执行启动命令);

#集群启动nacos(请确保先切换到nacos的bin目录)
startup.cmd -m cluster

启动结果:
在这里插入图片描述
2.6 点击集群管理>>节点管理,如果显示3个nacos记录,即为集群启动成功;
在这里插入图片描述

3. 微服务中如何配置多个nacos地址

在微服务的配置文件里需要配置多个nacos地址,以逗号分割。这种配置多个nacos地址的方式,显然很难实现nacos集群的扩缩容,nacos一旦增加或者减少,就需要在每个微服务里进行修改,很繁琐。

spring:cloud:nacos:discovery:server-addr: 127.0.0.1:8846,127.0.0.1:8848,127.0.0.1:8850

如果有有一个代理地址可以代替这三个地址,通过代理负载分发到nacos集群中,而微服务只需要配置代理的地址即可,也就是下面的 nginx+nacos集群(VIP模式)
在这里插入图片描述

4. nginx+nacos集群(VIP模式)

4.1 安装nginx1.24.0并进行解压缩
4.2 配置nginx转发,并修改nginx.conf文件
在这里插入图片描述
在这里插入图片描述


#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 nacos{#weight表示权重,默认是轮循,此处表示8848访问一次,8849访问1,8850访问1,按照这个方式循环调用server 127.0.0.1:8848 weight=1;server 127.0.0.1:8846 weight=1;server 127.0.0.1:8850 weight=1;}server {listen       18888;server_name  localhost;#listen       80;#server_name  localhost;#charset koi8-r;#access_log  logs/host.access.log  main;location / {root   html;index  index.html index.htm;proxy_pass http://nacos;}#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;#    }#}}

4.3 1、 启动nginx,并访问nacos,http://localhost:18888/nacos/,默认账号名和密码都是nacos;
在这里插入图片描述

5. 微服务中配置nginx

通过nginx+nacos集群,我们只需要在微服务中配置nginx的转发地址即可,不需要填写具体的nacos地址

spring:cloud:nacos:discovery:server-addr: 127.0.0.1:18888

6. 数据库主备高可用的配置

除了配置多节点外,高可用还需要配置多数据源。
配置两个数据源,在conf目录下的application.properties添加配置数据源(数据库主备高可用)
在这里插入图片描述
7. 问题点
问题1:节点显示多了
如果用户是多网卡,则会出现下面的问题,8848端口只有1个nacos,但是显示两行记录。
在这里插入图片描述
解决办法:
打开对应出错的nacos的conf目录下application.properties文件,指定ip;

#要指定你网卡里有的ip,不要瞎设置
nacos.inetutils.ip-address=127.0.0.1

问题2:
在这里插入图片描述
如果出现这样的问题,检查一下三个nocos下的application.properties的数据源问题
在这里插入图片描述
问题3:Error occurred during initialization of VM
堆内存不足
解决办法:
关掉一些应用,或者增加内存。

问题4:如果三个nacos集群在同一台机器部署,建议使用nacos的端口号不要连续,如本文设计的8846,8848,8850

这篇关于nacos集群部署和VIP部署的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1126213

相关文章

ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法

《ElasticSearch+Kibana通过Docker部署到Linux服务器中操作方法》本文介绍了Elasticsearch的基本概念,包括文档和字段、索引和映射,还详细描述了如何通过Docker... 目录1、ElasticSearch概念2、ElasticSearch、Kibana和IK分词器部署

部署Vue项目到服务器后404错误的原因及解决方案

《部署Vue项目到服务器后404错误的原因及解决方案》文章介绍了Vue项目部署步骤以及404错误的解决方案,部署步骤包括构建项目、上传文件、配置Web服务器、重启Nginx和访问域名,404错误通常是... 目录一、vue项目部署步骤二、404错误原因及解决方案错误场景原因分析解决方案一、Vue项目部署步骤

Linux流媒体服务器部署流程

《Linux流媒体服务器部署流程》文章详细介绍了流媒体服务器的部署步骤,包括更新系统、安装依赖组件、编译安装Nginx和RTMP模块、配置Nginx和FFmpeg,以及测试流媒体服务器的搭建... 目录流媒体服务器部署部署安装1.更新系统2.安装依赖组件3.解压4.编译安装(添加RTMP和openssl模块

0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型的操作流程

《0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeekR1模型的操作流程》DeepSeekR1模型凭借其强大的自然语言处理能力,在未来具有广阔的应用前景,有望在多个领域发... 目录0基础租个硬件玩deepseek,蓝耘元生代智算云|本地部署DeepSeek R1模型,3步搞定一个应

redis群集简单部署过程

《redis群集简单部署过程》文章介绍了Redis,一个高性能的键值存储系统,其支持多种数据结构和命令,它还讨论了Redis的服务器端架构、数据存储和获取、协议和命令、高可用性方案、缓存机制以及监控和... 目录Redis介绍1. 基本概念2. 服务器端3. 存储和获取数据4. 协议和命令5. 高可用性6.

Deepseek R1模型本地化部署+API接口调用详细教程(释放AI生产力)

《DeepseekR1模型本地化部署+API接口调用详细教程(释放AI生产力)》本文介绍了本地部署DeepSeekR1模型和通过API调用将其集成到VSCode中的过程,作者详细步骤展示了如何下载和... 目录前言一、deepseek R1模型与chatGPT o1系列模型对比二、本地部署步骤1.安装oll

nginx部署https网站的实现步骤(亲测)

《nginx部署https网站的实现步骤(亲测)》本文详细介绍了使用Nginx在保持与http服务兼容的情况下部署HTTPS,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值... 目录步骤 1:安装 Nginx步骤 2:获取 SSL 证书步骤 3:手动配置 Nginx步骤 4:测

Tomcat高效部署与性能优化方式

《Tomcat高效部署与性能优化方式》本文介绍了如何高效部署Tomcat并进行性能优化,以确保Web应用的稳定运行和高效响应,高效部署包括环境准备、安装Tomcat、配置Tomcat、部署应用和启动T... 目录Tomcat高效部署与性能优化一、引言二、Tomcat高效部署三、Tomcat性能优化总结Tom

如何在本地部署 DeepSeek Janus Pro 文生图大模型

《如何在本地部署DeepSeekJanusPro文生图大模型》DeepSeekJanusPro模型在本地成功部署,支持图片理解和文生图功能,通过Gradio界面进行交互,展示了其强大的多模态处... 目录什么是 Janus Pro1. 安装 conda2. 创建 python 虚拟环境3. 克隆 janus

本地私有化部署DeepSeek模型的详细教程

《本地私有化部署DeepSeek模型的详细教程》DeepSeek模型是一种强大的语言模型,本地私有化部署可以让用户在自己的环境中安全、高效地使用该模型,避免数据传输到外部带来的安全风险,同时也能根据自... 目录一、引言二、环境准备(一)硬件要求(二)软件要求(三)创建虚拟环境三、安装依赖库四、获取 Dee