zoukankan      html  css  js  c++  java
  • 生产可用的Nacos集群

    搭建生产可用的Nacos集群

    软件包其中有JDK安装包
    链接:https://pan.baidu.com/s/1QiWfPZVCg-kEmysfNSzHCg
    提取码:virc

    搭建方案

    简介

    生产环境中部署nacos需要使用集群模式cluster保证高可用,本文主要详细介绍如何搭建搭建生产可用的Nacos集群

    • nacos采用raft协议实现集群,有leader的概念

    主机规划

    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集群方式部署。

    找到 conf/nacos-mysql.sql ,将其导入到数据库中。
    导入后查看数据库

    192.168.235.130

    • 创建目录

    mkdir /app

    • 将文章顶部百度网盘中的文件上传到 192.168.235.130中的/app目录

    • 修改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和192.168.235.132同理搭建

    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
    
    • 安装完成

    • 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 
    

    192.168.235.134 同理

    192.168.235.133

    • 安装keepalived
    yum install -y net-tools psmisc  net-snmp ipvsadm keepalived

    • 安装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
    

    • 查看虚拟VIP

    192.168.235.134 同理

  • 相关阅读:
    在Linux CentOS 6.6上安装Python 2.7.9
    CentOS yum 安装LAMP PHP5.4版本
    yum 安装php环境
    如何在Eclipse配置PyDev插件
    vagrant使用小结
    虚拟机下安装CentOS6.5系统教程
    python
    library cahce pin
    利用分析函数删除重复数据
    组合索引避免索引扫描后在过滤
  • 原文地址:https://www.cnblogs.com/cwshuo/p/14505344.html
Copyright © 2011-2022 走看看