广州番禺做网站,开发软件学什么专业,wordpress仿微信公众号,模板无忧官方给出的集群部署架构图 集群部署说明 (nacos.io)3个或3个以上nacos节点才能构成集群当前示例中包含3个nacos节点#xff0c;同时一个负载均衡器代理3个nacos#xff0c;本示例中负载均衡器可使用的是nginx 准备并安装好正常运行的nginx#xff0c;本示例略准备并安装好正…官方给出的集群部署架构图 集群部署说明 (nacos.io)3个或3个以上nacos节点才能构成集群当前示例中包含3个nacos节点同时一个负载均衡器代理3个nacos本示例中负载均衡器可使用的是nginx 准备并安装好正常运行的nginx本示例略准备并安装好正常运行的MySQL数据库本示例略3个nacos节点地址信息 节点ipportnacos1192.168.xxx.xxx8841nacos2192.168.xxx.xxx18841nacos3192.168.xxx.xxx28841根据自己的实际情况设置端口建议不要设置为连续的防止nacos启动时有可能存在端口冲突最好不同nacos的节点的端口相差有一定的步数步数大于1002以上开始搭建nacos集群 下载nacos安装包 https://github.com/alibaba/nacos/releases本示例下载的压缩包为nacos-server-2.3.0.tar.gz通过ssh远程工具将压缩包上传到Linux服务器中然后再解压 tar -zxvf nacos-server-2.3.0.tar.gz 初始化nacos的数据库脚本 在解压的文件中的conf文件夹中找到mysql-schema.sql这里是nacos建立数据库的相关SQL数据使用数据库管理工具新建一个数据库名称为nacos的数据库并将当前mysql-schema.sql的sql文件在nacos数据库中执行结果如下所示回到Linux服务中进入nacos的conf目录将配置文件cluster.conf.example重命名为cluster.conf mv cluster.conf.example cluster.conf 将配置文件cluster.conf修改为以下信息其中ip地址修改为自己的服务器ip地址端口设定为自己设定的nacos的服务端口 #
# Copyright 1999-2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the License);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
##it is ip
#example
192.168.xxx.xxx:8841
192.168.xxx.xxx:18841
192.168.xxx.xxx:28841修改配置文件application.properties添加数据库配置、开启鉴权等相关信息 ### 是否开启鉴权功能
### If turn on auth system:
nacos.core.auth.enabledtrue### 配置自定义身份识别的key不可为空和value不可为空
### Since 1.4.1, worked when nacos.core.auth.enabledtrue and nacos.core.auth.enable.userAgentAuthWhitefalse.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.keyexampleNacos
nacos.core.auth.server.identity.valueexampleNacos### 默认鉴权插件用于生成用户登陆临时accessToken所使用的密钥使用默认值有安全风险
### 自定义密钥时推荐将配置项设置为Base64编码的字符串且原始密钥长度不得低于32字符。 Base64 在线编码解码 https://base64.us/
### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.keySecretKey012345678901234567890123456789012345678901234567890123456789# mysql数据库配置信息
### If use MySQL as datasource:
### Deprecated configuration property, it is recommended to use spring.sql.init.platform replaced.
# spring.datasource.platformmysql
# 初始化使用的数据库为MySQL
spring.sql.init.platformmysql# 数据库连接数量
### Count of DB:
db.num1### Connect URL of DB:
# 连接mysql的url
db.url.0jdbc:mysql://192.168.xxx.xxx:3333/nacos?characterEncodingutf8connectTimeout1000socketTimeout3000autoReconnecttrueuseUnicodetrueuseSSLfalseserverTimezoneUTC
# 连接mysql的用户
db.user.0root
# 连接mysql的密码
db.password.0123456将解压之后的nacos的文件复制3份分别为nacos1、nacos2、nacos3 cp -rf nacos ./nacos1
cp -rf nacos ./nacos2
cp -rf nacos ./nacos3 分别修改nacos的application.properties将里面的server.port修改为指定的端口 nacos1 ### Default web server port:
server.port8841 nacos2 ### Default web server port:
server.port18841 nacos3 ### Default web server port:
server.port28841 分别给nacos1、nacos2、nacos3配置jdk环境修改startup.sh文件 # 配置JDK环境要求JDK 1.8
export JAVA_HOME/usr/local/project/openjdk-8
export JRE_HOME$JAVA_HOME/jre
export CLASSPATH$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH$JAVA_HOME/bin:$JRE_HOME/bin:$PATH然后分别启动nacos1、nacos2、nacos3的节点启动脚本文件为startup.sh /usr/local/project/nacos-group/nacos1/bin/startup.sh
/usr/local/project/nacos-group/nacos2/bin/startup.sh
/usr/local/project/nacos-group/nacos3/bin/startup.sh 访问地址http://192.168.xxx.xxx:8841/nacos/输入默认账号密码nacos/nacos登录可到达nacos控制台三个节点状态都是up则说明启动成功 同时如果都启动成功所有节点的端口的nacos的控制台都可以正常访问配置nginx的反向代理 默认端口占用情况 端口与主端口的偏移量描述88480主端口客户端、控制台及OpenAPI所使用的HTTP端口98481000客户端gRPC请求服务端端口用于客户端向服务端发起连接和请求98491001服务端gRPC请求服务端端口用于服务间同步等7848-1000Jraft请求服务端端口用于处理服务端间的Raft相关请求使用VIP/nginx请求时需要配置成TCP转发不能配置http2转发否则连接会被nginx断开。 9849和7848端口为服务端之间的通信端口请勿暴露到外部网络环境和客户端测。根据主端口偏移量可以计算出客户端gRPC请求服务端端口 8841100098411884110001984128841100029841nginx监听的是80端口则8010001080找到nginx的配置文件conf/nginx.conf 修改conf/nginx.conf的配置文件信息添加以下配置 在http块内添加 # upstream指令可以定义一组服务器upstream nacos-cluster {server 192.168.xxx.xxx:8841;server 192.168.xxx.xxx:18841;server 192.168.xxx.xxx:28841;} 在server块中添加 location /nacos {# 反向代理配置将请求转发到指定的服务proxy_pass http://nacos-cluster;} 在stream块用于做nacos的TCP转发 # stream块用于做nacos的TCP转发
stream {# upstream指令可以定义一组服务器upstream nacos-cluster {server 192.168.xxx.xxx:9841;server 192.168.xxx.xxx:19841;server 192.168.xxx.xxx:29841;}server {# 8010001080listen 1080;proxy_connect_timeout 30s;proxy_timeout 5m;# 反向代理配置将请求转发到指定的服务proxy_pass nacos-cluster;}} 启动nginx sudo /usr/local/project/nginx/sbin/nginx nginx监听的是80端口所以需要管理员权限启动nginx如果nginx启动报错类似于nginx: [emerg] unknown directive stream in /usr/local/project/nginx/conf/nginx.conf:159解决方案请参考作者当前博客链接nginx启动报错nginx: [emerg] unknown directive “stream“ in /usr/local/project/nginx/conf/nginx.conf:159-CSDN博客浏览器访问nginx监听的端口访问nacos当前示例访问地址为http://192.168.xxx.xxx/nacos/ 显示可以正常访问项目中连接nacos实现服务注册和服务发现 server:port: 18080
spring:application:#应用的名称name: nacos-user-servicecloud:nacos:# Nacos Server 启动监听的ip地址和端口server-addr: 192.168.163.100:80discovery:# nacos开启鉴权之后的用户名username: nacos# nacos开启鉴权之后的用户登录密码password: nacos# 配置服务实例的集群名称cluster-name: GD 生产环境优化建议 实际部署时我们最好给反向代理的nginx服务器设置一个域名这样后续如果有服务器迁移nacos的客户端也无需更改配置 Nacos的各个节点应该部署到多个不同的服务器上这样可以做到容灾和隔离