## 搭建生产可用的Nacos集群
```
软件包其中有JDK安装包
链接:https://pan.baidu.com/s/1QiWfPZVCg-kEmysfNSzHCg
提取码:virc
```
### 搭建方案
![](https://img.kancloud.cn/d0/3d/d03d68020fc9d13aa7e80333cc687469_889x455.png)
### 简介
生产环境中部署`nacos`需要使用集群模式`cluster`保证高可用,本文主要详细介绍如何搭建搭建生产可用的Nacos集群
* nacos采用raft协议实现集群,有leader的概念
![](https://img.kancloud.cn/2f/b5/2fb56e47353f346c52e62978ecd5abf4_1920x738.png)
### 主机规划
#### mysql
| 节点 | 端口 |
| :-- | :-- |
| 59.110.164.254| 3306|
#### nacos集群
| 节点 | 端口 |
| :-- | :-- |
| 192.168.235.130| 8848 |
| 192.168.235.131| 8848 |
| 192.168.235.132 | 8848 |
nacos集群中,每台机器安装JDK
##### jdk安装步骤
* 1.将下载好的jdk跟maven上传到服务器上
* 2.解压jdk到/usr/local/
tar -zxvf jdk-8u91-linux-x64.tar.gz -C /usr/local/
* 3.配置环境变量
vi /etc/profile
在最下面,按i进入insert模式,添加一下内容
JAVA\_HOME=/usr/local/jdk1.8.0\_91
export JAVA\_HOME
CLASSPATH=.:$JAVA\_HOME/lib
export CLASSPATH
PATH=$PATH:$JAVA\_HOME/bin:$CLASSPATH
export PATH
按esc进入命令行模式,再按:wq保存退出
* 4.激活配置
source /etc/profile
#### openresty集群
| 节点 | 端口 |
| :-- | :-- |
| 192.168.235.133| 80 |
| 192.168.235.134| 80|
VIP
> 192.168.235.135
### 准备阶段
mysql中新建数据库nacos,导入初始化脚本,本文采用单节点部署mysql方式,为了快速部署nacos集群,生产环境选用Galera mysql集群方式部署。
### 初始化脚本
![](https://img.kancloud.cn/06/79/06799a87078a9a05c456a344a704ccec_916x376.png)
找到 `conf/nacos-mysql.sql` ,将其导入到数据库中。
导入后查看数据库
![](https://img.kancloud.cn/76/a0/76a0f02b6e697bd422a8a653e46ed5c8_1192x448.png)
### 192.168.235.130
* 创建目录
```
mkdir /app
```
* 将文章顶部百度网盘中的文件上传到 192.168.235.130中的/app目录
![](https://img.kancloud.cn/b2/cf/b2cf732cfc08d6979f60da7f54ae83df_1917x242.png)
* 修改application.properties文件,最后部分增加如下配置
```
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://59.110.164.254:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root
```
* 修改cluster.conf文件,nacos集群的三台主机信息
```
# ip:port
192.168.235.130:8848
192.168.235.131:8848
192.168.235.132:8848
```
* 启动
```
cd /app/nacos-server/bin
./startup.sh
```
* 查看启动情况
```
tail -f /app/nacos-server/logs/start.out
```
### 192.168.235.131
* 创建目录
```
mkdir /app
```
* 将文章顶部百度网盘中的文件上传到 192.168.235.131中的/app目录
![](https://img.kancloud.cn/b2/cf/b2cf732cfc08d6979f60da7f54ae83df_1917x242.png)
* 修改application.properties文件,最后部分增加如下配置
```
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://59.110.164.254:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root
```
* 修改cluster.conf文件,nacos集群的三台主机信息
```
# ip:port
192.168.235.130:8848
192.168.235.131:8848
192.168.235.132:8848
```
* 启动
```
cd /app/nacos-server/bin
./startup.sh
```
* 查看启动情况
```
tail -f /app/nacos-server/logs/start.out
```
### 192.168.235.132
* 创建目录
```
mkdir /app
```
* 将文章顶部百度网盘中的文件上传到 192.168.235.132中的/app目录
![](https://img.kancloud.cn/b2/cf/b2cf732cfc08d6979f60da7f54ae83df_1917x242.png)
* 修改application.properties文件,最后部分增加如下配置
```
spring.datasource.platform=mysql
db.num=1
db.url.0=jdbc:mysql://59.110.164.254:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=root
db.password=root
```
* 修改cluster.conf文件,nacos集群的三台主机信息
```
# ip:port
192.168.235.130:8848
192.168.235.131:8848
192.168.235.132:8848
```
* 启动
```
cd /app/nacos-server/bin
./startup.sh
```
* 查看启动情况
```
tail -f /app/nacos-server/logs/start.out
```
### 192.168.235.133
* OpenResty安装
```
●Centos:yum install -y readline-devel pcre-devel openssl-devel gcc GeoIP-devel
●wget https://openresty.org/download/openresty-1.11.2.1.tar.gz
●tar -zxvf openresty-1.11.2.1.tar.gz
●cd openresty-1.11.2.1
●./configure --with-luajit --with-pcre --with-http_gzip_static_module --with-http_realip_module --with-http_geoip_module --with-http_ssl_module --with-http_stub_status_module --prefix=/app/openresty
●make && make install
```
* 安装完成
* ![](https://img.kancloud.cn/cf/48/cf48a4ca7226216c7aad5bd6685182ff_1025x356.png)
* OpenResty配置/app/openresty/nginx/conf/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 nacosCluster {
server 192.168.235.130:8848;
server 192.168.235.131:8848;
server 192.168.235.132:8848;
}
server {
listen 80;
server_name nacostest.com;
location / {
proxy_pass http://nacosCluster;
}
}
}
~
```
* OpenResty启动
```
cd /app/openresty/nginx/sbin
./nginx
```
* 验证
http://192.168.235.133/nacos
用户名/密码 nacos nacos
![](https://img.kancloud.cn/a8/13/a8136d9e4491577facd9a42ff8499928_1716x740.png)
### 192.168.235.134
* OpenResty安装
```
●Centos:yum install -y readline-devel pcre-devel openssl-devel gcc GeoIP-devel
●wget https://openresty.org/download/openresty-1.11.2.1.tar.gz
●tar -zxvf openresty-1.11.2.1.tar.gz
●cd openresty-1.11.2.1
●./configure --with-luajit --with-pcre --with-http_gzip_static_module --with-http_realip_module --with-http_geoip_module --with-http_ssl_module --with-http_stub_status_module --prefix=/app/openresty
●make && make install
```
* 安装完成
* ![](https://img.kancloud.cn/cf/48/cf48a4ca7226216c7aad5bd6685182ff_1025x356.png)
* OpenResty配置/app/openresty/nginx/conf/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 nacosCluster {
server 192.168.235.130:8848;
server 192.168.235.131:8848;
server 192.168.235.132:8848;
}
server {
listen 80;
server_name nacostest.com;
location / {
proxy_pass http://nacosCluster;
}
}
}
~
```
* OpenResty启动
```
cd /app/openresty/nginx/sbin
./nginx
```
* 验证
http://192.168.235.134/nacos
用户名/密码 nacos nacos
![](https://img.kancloud.cn/c4/83/c483d4d0aed9a10ed237520c7f7ded6f_1920x791.png)
### 192.168.235.133
* 安装keepalived
```
yum install -y net-tools psmisc net-snmp ipvsadm keepalived
```
![](https://img.kancloud.cn/21/ef/21efa6337b6060e0c07194f038d07422_948x438.png)
* 安装killall命令
```
yum install psmisc -y
```
* 配置执行脚本
vi /etc/keepalived/check_nginx.sh
```
#!/bin/bash
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")
if [ "$count" -eq 0 ];then
killall keepalived
fi
```
chmod +x /etc/keepalived/check_nginx.sh
* 配置/etc/keepalived/keepalived.conf,vip 192.168.235.135
```
! Configuration File for keepalived
global_defs {
# 陆脫脮始镁碌脴路
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
# 脫录镁路垄脣碌脴路
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id NGINX_MASTER
}
vrrp_script check_nginx {
script "/etc/keepalived/check_nginx.sh"
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51 # VRRP 路脫 ID实脌拢卢每赂枚媒禄碌脛
priority 100 # 脫脧录露拢卢卤赂路镁脦脝脡脰 90
advert_int 1 # 指露篓VRRP 脨脤掳眉盲时录洌兟
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.235.135/24
}
track_script {
check_nginx
}
}
```
* 启动keepalived
```
service keepalived start
service keepalived status
```
![](https://img.kancloud.cn/63/e5/63e5d61a487da067093baaa1a1c3b518_1447x407.png)
* 查看虚拟VIP
![](https://img.kancloud.cn/d6/72/d672034b102d5d4a246ae6421dcd7d9b_1315x341.png)
![](https://img.kancloud.cn/19/d2/19d28d1ea66dc61ba2854249b25f9543_1920x757.png)
### 192.168.235.134
* 安装keepalived
```
yum install -y net-tools psmisc net-snmp ipvsadm keepalived
```
![](https://img.kancloud.cn/21/ef/21efa6337b6060e0c07194f038d07422_948x438.png)
* 安装killall命令
```
yum install psmisc -y
```
* 配置执行脚本
vi /etc/keepalived/check_nginx.sh
```
#!/bin/bash
count=$(ps -ef |grep nginx |egrep -cv "grep|$$")
if [ "$count" -eq 0 ];then
killall keepalived
fi
```
chmod +x /etc/keepalived/check_nginx.sh
* 配置/etc/keepalived/keepalived.conf,vip 192.168.235.135
```
! Configuration File for keepalived
global_defs {
# 陆脫脮始镁碌脴路
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
# 脫录镁路垄脣碌脴路
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id NGINX_MASTER
}
vrrp_script check_nginx {
script "/etc/keepalived/check_nginx.sh"
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51 # VRRP 路脫 ID实脌拢卢每赂枚媒禄碌脛
priority 90 # 脫脧录露拢卢卤赂路镁脦脝脡脰 90
advert_int 1 # 指露篓VRRP 脨脤掳眉盲时录洌兟
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.235.135/24
}
track_script {
check_nginx
}
}
```
* 启动keepalived
```
service keepalived start
service keepalived status
```
![](https://img.kancloud.cn/63/e5/63e5d61a487da067093baaa1a1c3b518_1447x407.png)
* 查看虚拟VIP
![](https://img.kancloud.cn/d6/72/d672034b102d5d4a246ae6421dcd7d9b_1315x341.png)
![](https://img.kancloud.cn/19/d2/19d28d1ea66dc61ba2854249b25f9543_1920x757.png)
- 前言
- 1.项目说明
- 2.项目更新日志
- 3.文档更新日志
- 01.快速开始
- 01.maven构建项目
- 02.环境安装
- 03.STS项目导入
- 03.IDEA项目导入
- 04.数据初始化
- 05.项目启动
- 06.付费文档说明
- 02.总体流程
- 1.oauth接口
- 2.架构设计图
- 3.微服务介绍
- 4.功能介绍
- 5.梳理流程
- 03.模块详解
- 01.老版本1.0.1分支模块讲解
- 01.db-core模块
- 02.api-commons模块
- 03.log-core模块
- 04.security-core模块
- 05.swagger-core模块
- 06.eureka-server模块
- 07.auth-server模块
- 08.auth-sso模块解析
- 09.user-center模块
- 10.api-gateway模块
- 11.file-center模块
- 12.log-center模块
- 13.batch-center模块
- 14.back-center模块
- 02.spring-boot-starter-web那点事
- 03.自定义db-spring-boot-starter
- 04.自定义log-spring-boot-starter
- 05.自定义redis-spring-boot-starter
- 06.自定义common-spring-boot-starter
- 07.自定义swagger-spring-boot-starter
- 08.自定义uaa-server-spring-boot-starter
- 09.自定义uaa-client-spring-boot-starter
- 10.自定义ribbon-spring-boot-starter
- 11.springboot启动原理
- 12.eureka-server模块
- 13.auth-server模块
- 14.user-center模块
- 15.api-gateway模块
- 16.file-center模块
- 17.log-center模块
- 18.back-center模块
- 19.auth-sso模块
- 20.admin-server模块
- 21.zipkin-center模块
- 22.job-center模块
- 23.batch-center
- 04.全新网关
- 01.基于spring cloud gateway的new-api-gateway
- 02.spring cloud gateway整合Spring Security Oauth
- 03.基于spring cloud gateway的redis动态路由
- 04.spring cloud gateway聚合swagger文档
- 05.技术详解
- 01.互联网系统设计原则
- 02.系统幂等性设计与实践
- 03.Oauth最简向导开发指南
- 04.oauth jdbc持久化策略
- 05.JWT token方式启用
- 06.token有效期的处理
- 07.@PreAuthorize注解分析
- 08.获取当前用户信息
- 09.认证授权白名单配置
- 10.OCP权限设计
- 11.服务安全流程
- 12.认证授权详解
- 13.验证码技术
- 14.短信验证码登录
- 15.动态数据源配置
- 16.分页插件使用
- 17.缓存击穿
- 18.分布式主键生成策略
- 19.分布式定时任务
- 20.分布式锁
- 21.网关多维度限流
- 22.跨域处理
- 23.容错限流
- 24.应用访问次数控制
- 25.统一业务异常处理
- 26.日志埋点
- 27.GPRC内部通信
- 28.服务间调用
- 29.ribbon负载均衡
- 30.微服务分布式跟踪
- 31.异步与线程传递变量
- 32.死信队列延时消息
- 33.单元测试用例
- 34.Greenwich.RELEASE升级
- 35.混沌工程质量保证
- 06.开发初探
- 1.开发技巧
- 2.crud例子
- 3.新建服务
- 4.区分前后台用户
- 07.分表分库
- 08.分布式事务
- 1.Seata介绍
- 2.Seata部署
- 09.shell部署
- 01.eureka-server
- 02.user-center
- 03.auth-server
- 04.api-gateway
- 05.file-center
- 06.log-center
- 07.back-center
- 08.编写shell脚本
- 09.集群shell部署
- 10.集群shell启动
- 11.部署阿里云问题
- 10.网关安全
- 1.openresty https保障服务安全
- 2.openresty WAF应用防火墙
- 3.openresty 高可用
- 11.docker配置
- 01.docker安装
- 02.Docker 开启远程API
- 03.采用docker方式打包到服务器
- 04.docker创建mysql
- 05.docker网络原理
- 06.docker实战
- 6.01.安装docker
- 6.02.管理镜像基本命令
- 6.03.容器管理
- 6.04容器数据持久化
- 6.05网络模式
- 6.06.Dockerfile
- 6.07.harbor部署
- 6.08.使用自定义镜像
- 12.统一监控中心
- 01.spring boot admin监控
- 02.Arthas诊断利器
- 03.nginx监控(filebeat+es+grafana)
- 04.Prometheus监控
- 05.redis监控(redis+prometheus+grafana)
- 06.mysql监控(mysqld_exporter+prometheus+grafana)
- 07.elasticsearch监控(elasticsearch-exporter+prometheus+grafana)
- 08.linux监控(node_exporter+prometheus+grafana)
- 09.micoservice监控
- 10.nacos监控
- 11.druid数据源监控
- 12.prometheus.yml
- 13.grafana告警
- 14.Alertmanager告警
- 15.监控微信告警
- 16.关于接口监控告警
- 17.prometheus-HA架构
- 18.总结
- 13.统一日志中心
- 01.统一日志中心建设意义
- 02.通过ELK收集mysql慢查询日志
- 03.通过elk收集微服务模块日志
- 04.通过elk收集nginx日志
- 05.统一日志中心性能优化
- 06.kibana安装部署
- 07.日志清理方案
- 08.日志性能测试指标
- 09.总结
- 14.数据查询平台
- 01.数据查询平台架构
- 02.mysql配置bin-log
- 03.单节点canal-server
- 04.canal-ha部署
- 05.canal-kafka部署
- 06.实时增量数据同步mysql
- 07.canal监控
- 08.clickhouse运维常见脚本
- 15.APM监控
- 1.Elastic APM
- 2.Skywalking
- 01.docker部署es
- 02.部署skywalking-server
- 03.部署skywalking-agent
- 16.压力测试
- 1.ocp.jmx
- 2.test.bat
- 3.压测脚本
- 4.压力报告
- 5.报告分析
- 6.压测平台
- 7.并发测试
- 8.wrk工具
- 9.nmon
- 10.jmh测试
- 17.SQL优化
- 1.oracle篇
- 01.基线测试
- 02.调优前奏
- 03.线上瓶颈定位
- 04.执行计划解读
- 05.高级SQL语句
- 06.SQL tuning
- 07.数据恢复
- 08.深入10053事件
- 09.深入10046事件
- 2.mysql篇
- 01.innodb存储引擎
- 02.BTree索引
- 03.执行计划
- 04.查询优化案例分析
- 05.为什么会走错索引
- 06.表连接优化问题
- 07.Connection连接参数
- 08.Centos7系统参数调优
- 09.mysql监控
- 10.高级SQL语句
- 11.常用维护脚本
- 12.percona-toolkit
- 18.redis高可用方案
- 1.免密登录
- 2.安装部署
- 3.配置文件
- 4.启动脚本
- 19.消息中间件搭建
- 19-01.rabbitmq集群搭建
- 01.rabbitmq01
- 02.rabbitmq02
- 03.rabbitmq03
- 04.镜像队列
- 05.haproxy搭建
- 06.keepalived
- 19-02.rocketmq搭建
- 19-03.kafka集群
- 20.mysql高可用方案
- 1.环境
- 2.mysql部署
- 3.Xtrabackup部署
- 4.Galera部署
- 5.galera for mysql 集群
- 6.haproxy+keepalived部署
- 21.es集群部署
- 22.生产实施优化
- 1.linux优化
- 2.jvm优化
- 3.feign优化
- 4.zuul性能优化
- 23.线上问题诊断
- 01.CPU性能评估工具
- 02.内存性能评估工具
- 03.IO性能评估工具
- 04.网络问题工具
- 05.综合诊断评估工具
- 06.案例诊断01
- 07.案例诊断02
- 08.案例诊断03
- 09.案例诊断04
- 10.远程debug
- 24.fiddler抓包实战
- 01.fiddler介绍
- 02.web端抓包
- 03.app抓包
- 25.疑难解答交流
- 01.有了auth/token获取token了为啥还要配置security的登录配置
- 02.权限数据存放在redis吗,代码在哪里啊
- 03.其他微服务和认证中心的关系
- 04.改包问题
- 05.use RequestContextListener or RequestContextFilter to expose the current request
- 06./oauth/token对应代码在哪里
- 07.验证码出不来
- 08./user/login
- 09.oauth无法自定义权限表达式
- 10.sleuth引发线程数过高问题
- 11.elk中使用7x版本问题
- 12.RedisCommandTimeoutException问题
- 13./oauth/token CPU过高
- 14.feign与权限标识符问题
- 15.动态路由RedisCommandInterruptedException: Command interrupted
- 26.学习资料
- 海量学习资料等你来拿
- 27.持续集成
- 01.git安装
- 02.代码仓库gitlab
- 03.代码仓库gogs
- 04.jdk&&maven
- 05.nexus安装
- 06.sonarqube
- 07.jenkins
- 28.Rancher部署
- 1.rancher-agent部署
- 2.rancher-server部署
- 3.ocp后端部署
- 4.演示前端部署
- 5.elk部署
- 6.docker私服搭建
- 7.rancher-server私服
- 8.rancher-agent docker私服
- 29.K8S部署OCP
- 01.准备OCP的构建环境和部署环境
- 02.部署顺序
- 03.在K8S上部署eureka-server
- 04.在K8S上部署mysql
- 05.在K8S上部署redis
- 06.在K8S上部署auth-server
- 07.在K8S上部署user-center
- 08.在K8S上部署api-gateway
- 09.在K8S上部署back-center
- 30.Spring Cloud Alibaba
- 01.统一的依赖管理
- 02.nacos-server
- 03.生产可用的Nacos集群
- 04.nacos配置中心
- 05.common.yaml
- 06.user-center
- 07.auth-server
- 08.api-gateway
- 09.log-center
- 10.file-center
- 11.back-center
- 12.sentinel-dashboard
- 12.01.sentinel流控规则
- 12.02.sentinel熔断降级规则
- 12.03.sentinel热点规则
- 12.04.sentinel系统规则
- 12.05.sentinel规则持久化
- 12.06.sentinel总结
- 13.sentinel整合openfeign
- 14.sentinel整合网关
- 1.sentinel整合zuul
- 2.sentinel整合scg
- 15.Dubbo与Nacos共存
- 31.Java源码剖析
- 01.基础数据类型和String
- 02.Arrays工具类
- 03.ArrayList源码分析
- 32.面试专题汇总
- 01.JVM专题汇总
- 02.多线程专题汇总
- 03.Spring专题汇总
- 04.springboot专题汇总
- 05.springcloud面试汇总
- 文档问题跟踪处理