SpringCloud-Alibaba之nacos集群配置

nacos 集群配置

  • linux服务器上mysql数据库安装并配置(nacos脚本数据准备好)

  • application.properties文件配置内容:

spring.datasource.platform=mysql

db.num=1
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=nacos_devtest
db.password=youdontknow
  • linux服务器上nacos的集群配置cluster.conf

cp cluster.conf.example cluster.conf:备份

配置各个节点:

#it is ip
#example

192.168.154.128:3333
192.168.154.128:4444
192.168.154.128:5555
  • 编辑nacos的启动脚本startup.sh,使它能够接受不同的启动端口(./startup.sh -p xxx,传递不同的端口号启动不同的nacos实例)

  • nginx的配置,由它来做负载均衡

修改nginx的配置文件nginx.conf

按照指定内容启动(linux -c参数表示指定配置文件)

启动nacos各节点

启动并通过nginx访问nacos:

Caused by: java.lang.RuntimeException: Nacos Server did not start because dumpservice bean construction failure :

No DataSource set (无数据源设置问题 )

分析:无数据源设置问题,可能加载的配置有问题,可能数据源无法访问等等.

访问地址:http://192.168.154.128:1111/nacos/#/login

NICE!成功访问!

手动新建配置服务,相关信息成功记录到linnux-mysql中:

启动一个服务,由Nginx代理转发到Nacos某节点完成注册:

小结:nacos集群的启动,如果指定了数据源,则需要事先启动mysql并完成授权验证,否则nacos的日志中将出现该问题。

参考:https://www.ayunw.cn/archives/505

linux下Nacos Cluster架构:

常用命令

  • ps -ef|grep nacos|grep -v grep|wc -l:查看集群节点总数

  • ./nginx -c /usr/local/nginx/conf/nginx.conf:关联配置文件启动

  • nginx -s reload: 修改后重载(需在Nginx启动后使用,否则会出现没有相应PID问题)

  • nginx -s stop 或 ./nginx -s stop : 关闭nginx

  • ln -s /usr/local/nginx/sbin/nginx /usr/bin/:创建nginx软链接

  • netstat -nplt:查看网络情况(包含当前所有端口)

  •  service iptables status/systemctl status firewalld:查看防火墙状态(注意版本)

  • centOS6查看防火墙状态命令: systemctl stop iptables.service

  • centOS7查看防火墙状态命令: systemctl stop firewalld.service

  • grant all privileges on *.* to 'root'@'192.168.154.128' identified by 'root'; :授权允许远程登录(需通过密码验证)

  • service mysqld/mysql restart:重启Mysql服务

  • curl ifconfig.me:查看外网ip

  • ifconfig:查看内网ip

  • show variables like '%timeout%'; :查看mysql超时时间

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;

    server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #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;
    #    }
    #}

}

猜你喜欢

转载自blog.csdn.net/wxd772113786/article/details/107570652
今日推荐