Nacos集群搭建

1、集群架构

       

       初始化nacos必须的数据库表并配置

       

  • 在MySQL实例创建nacos_config库并导入脚本
  • 修改修改Nacos配置文件,指向MySQL实例,替换其内嵌数据库

  

spring.datasource.platform=mysql

db.num=1
db.url.0=jdbc:mysql://192.168.15.141:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&
socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC db.user=root db.password=123456
  • Nacos集群配置,修改cluster.conf文件
[root@localhost conf]# vim ./cluster.conf
#example
192.168.15.145
192.168.15.147
192.168.15.148

        三台nacos实例都需要做以上集群配置,至此关于nacos的配置结束了

       进入nacos_${port}/bin 目录,分别执行sh startup.sh命令来启动 3 个 Nacos 服务。

sh startup.sh

        Nignx配置

  • 修改Nginx配置文件nginx.conf
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    keepalive_timeout  65;

    #nacos集群负载均衡
    upstream nacos-cluster {
        server 192.168.15.145:8848;
        server 192.168.15.147:8848;
        server 192.168.15.148:8848;
    }

    server {
        listen       80;
        server_name  192.168.15.146;
                 
        location / {
            #root   html;
            #index  index.html index.htm;
            proxy_pass http://nacos-cluster;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

}
  • 启动Nginx
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  访问nacos集群

 

posted on 2021-03-07 18:18  溪水静幽  阅读(250)  评论(0)    收藏  举报