一个更易于构建云原生应用的动态服务发现、配置管理和服务管理平台
Nacos 官网:https://nacos.io/zh-cn/index.html
Nacos - github:https://github.com/alibaba/nacos/tags
Nacos 鉴权:https://nacos.io/zh-cn/docs/v2/guide/user/auth.html
Nacos 多数据源插件:https://nacos.io/zh-cn/docs/v2/plugin/datasource-plugin.html
Nacos 集群部署说明 :https://nacos.io/zh-cn/docs/v2/guide/admin/cluster-mode-quick-start.html
CentOS7安装部署Java11:https://blog.csdn.net/u011424614/article/details/132418561
CentOS7安装部署MySQL80:https://blog.csdn.net/u011424614/article/details/132418916
keepalived识别MGR主节点:https://blog.csdn.net/u011424614/article/details/133222266
nginx入门和使用实践:https://blog.csdn.net/u011424614/article/details/107051875
CentOS基础操作命令:https://blog.csdn.net/u011424614/article/details/94555916
端口 | 描述 |
---|---|
7848 | 集群数据同步端口 |
8848 | Web管理端访问端口 |
9848 | 客户端gRPC请求服务端端口,用于客户端向服务端发起连接和请求 |
9849 | 服务端gRPC请求服务端端口,用于服务间同步等 |
机器名 | IP | 软件包 |
---|---|---|
sys-cluster-01 | 192.168.249.131 | Nacos |
sys-cluster-02 | 192.168.249.132 | Nacos |
sys-cluster-03 | 192.168.249.133 | Nacos |
sys-cluster-04 | 192.168.249.134 | MySQL |
# 131 执行
hostnamectl set-hostname sys-cluster-01 --static
hostnamectl set-hostname sys-cluster-01 --transient
# 132 执行
hostnamectl set-hostname sys-cluster-02 --static
hostnamectl set-hostname sys-cluster-02 --transient
# 133 执行
hostnamectl set-hostname sys-cluster-03 --static
hostnamectl set-hostname sys-cluster-03 --transient
# 134 执行
hostnamectl set-hostname sys-cluster-04 --static
hostnamectl set-hostname sys-cluster-04 --transient
# 查询状态
hostnamectl status
cat > /etc/hosts <
#--关闭防火墙
systemctl stop firewalld.service
#--开机禁用防火墙
systemctl disable firewalld.service
#--防火墙状态
systemctl status firewalld.service
在 4 台服务器上安装JDK
/opt/java/jdk-11.0.19
在 134 服务器上安装MySQL
/usr/local/mysql
/var/lib/mysql
/var/log/mysql
/etc/mysql
root
密码:Root@#123456
在 134 服务器上执行
mkdir /opt/nacos
cd /opt/nacos
# 下载
wget https://github.com/alibaba/nacos/releases/download/2.2.3/nacos-server-2.2.3.tar.gz --no-check-certificate
# 解压
tar -xzf nacos-server-2.2.3.tar.gz
mysql -ruoot -p
# 创建数据库
CREATE DATABASE nacos_config;
USE nacos_config;
# 执行 sql 文件
SOURCE /opt/nacos/nacos/conf/mysql-schema.sql
# 查询
show tables;
在 131 服务器上执行
mkdir /opt/nacos
cd /opt/nacos
# 下载
wget https://github.com/alibaba/nacos/releases/download/2.2.3/nacos-server-2.2.3.tar.gz --no-check-certificate
# 解压
tar -xzf nacos-server-2.2.3.tar.gz
【Config Module Related Configurations】段:配置 MySQL 数据库
【Access Control Related Configurations】段:开启鉴权
vim /opt/nacos/nacos/conf/application.properties
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://sys-cluster-04:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=Root@#123456
### If turn on auth system:
nacos.core.auth.enabled=true
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=nacos
nacos.core.auth.server.identity.value=nacos
### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=amxramxramtsamFkc2Zhc2RmYXNkZmE1NjQ1NmY0NWFzZDRmNjU0YXM1NmRmNDZhNXNk
# 执行权限
chmod +x /opt/nacos/nacos/bin/startup.sh
chmod +x /opt/nacos/nacos/bin/shutdown.sh
cd /opt/nacos/nacos/bin
# 启动
./startup.sh -m standalone
# 停止
./shutdown.sh
# 实时输出
tail -f /opt/nacos/nacos/logs/start.out
# 静态输出
cat /opt/nacos/nacos/logs/start.out
http://192.168.249.131:8848/nacos
cat > /etc/systemd/system/nacos.service <
systemctl daemon-reload
systemctl start nacos.service
systemctl enable nacos.service
systemctl status nacos.service
在 131 服务器上执行
mkdir /opt/nacos
cd /opt/nacos
# 下载
wget https://github.com/alibaba/nacos/releases/download/2.2.3/nacos-server-2.2.3.tar.gz --no-check-certificate
# 解压
tar -xzf nacos-server-2.2.3.tar.gz
在 131 服务器上执行
【Config Module Related Configurations】段:配置 MySQL 数据库
【Access Control Related Configurations】段:配置鉴权信息
vim /opt/nacos/nacos/conf/application.properties
### If use MySQL as datasource:
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://sys-cluster-04:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=Root@#123456
### If turn on auth system:
nacos.core.auth.enabled=true
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=nacos
nacos.core.auth.server.identity.value=nacos
### The default token (Base64 String):
nacos.core.auth.plugin.nacos.token.secret.key=amxramxramtsamFkc2Zhc2RmYXNkZmE1NjQ1NmY0NWFzZDRmNjU0YXM1NmRmNDZhNXNk
# 拷贝
cp /opt/nacos/nacos/conf/cluster.conf.example /opt/nacos/nacos/conf/cluster.conf
# 编辑
vim /opt/nacos/nacos/conf/cluster.conf
#it is ip
192.168.249.131:8848
192.168.249.132:8848
192.168.249.133:8848
在 131 服务器上执行
scp -r /opt/nacos [email protected]:/opt/nacos
scp -r /opt/nacos [email protected]:/opt/nacos
在 131、132、133 服务器上执行
# 执行权限
chmod +x /opt/nacos/nacos/bin/startup.sh
chmod +x /opt/nacos/nacos/bin/shutdown.sh
cd /opt/nacos/nacos/bin
# 启动
./startup.sh
# 停止
./shutdown.sh
# 实时输出
tail -f /opt/nacos/nacos/logs/start.out
# 静态输出
cat /opt/nacos/nacos/logs/start.out
http://192.168.249.131:8848/nacos
http://192.168.249.132:8848/nacos
http://192.168.249.133:8848/nacos
在 131、132、133 服务器上执行
cat > /etc/systemd/system/nacos.service <
systemctl daemon-reload
systemctl start nacos.service
systemctl enable nacos.service
systemctl status nacos.service
Nacos 集群部署说明 :https://nacos.io/zh-cn/docs/v2/guide/admin/cluster-mode-quick-start.html
Nginx 负载均衡
Nginx + Keepalived 双机主备
Nginx + Keepalived 双主热备
命令 | 说明 |
---|---|
systemctl daemon-reload | 重新加载服务配置 |
systemctl start nacos.service | 启动服务 |
systemctl enable nacos.service | 开机自启动服务 |
systemctl status nacos.service | 查询服务状态 |
systemctl stop nacos.service | 停止服务 |
systemctl restart nacos.service | 重启服务 |
systemctl disable nacos.service | 禁用开机自启动服务 |