neo4j社区版高可用搭建

    

整体技术方案采用keepalived+drbd主从

neo4j社区版高可用搭建_第1张图片

 1. 准备俩台机器、俩块磁盘 ,机器我用的是腾讯云的  。 因为阿里云的hvip已经下架了,估计是想卖他们的负载均衡

    neo4j社区版高可用搭建_第2张图片

        

       ip                    磁盘               hostname

      172.17.0.10      /dev/vdb1        VM_0_10_centos              主

      172.17.0.15      /dev/vdb1        VM_0_15_centos              从

       vip:  172.10.13    

     这个hvip 必须在先申请,详细请看https://cloud.tencent.com/document/product/215/20129

一、 搭建drbd 主从

    1. 修改hosts文件

       [root@VM_0_15_centos scripts]# vim /etc/hosts

    •          172.17.0.10 VM_0_10_centos

           172.17.0.15 VM_0_15_centos

         [root@VM_0_10_centos scripts]# vim /etc/hosts

           172.17.0.10 VM_0_10_centos

            172.17.0.15 VM_0_15_centos

     2.互相免密登陆

       [root@VM_0_10_centos ~]# ssh-keygen  

        [root@VM_0_10_centos ~]# ssh-copy-id  VM_0_15_centos

        [root@VM_0_15_centos ~]# ssh-keygen  

        [root@VM_0_15_centos ~]# ssh-copy-id  VM_0_10_centos

    3. 时钟同步         

     [root@VM_0_10_centos ~]# crontab -e

      */5 * * * * ntpdate cn.pool.ntp.org   ###添加任务 

     node2:

     [root@VM_0_15_centos ~]# crontab -e

      */5 * * * * ntpdate cn.pool.ntp.org   ###添加任务 

    4. 

5、现在我们就要开始安装drbd包在VM_0_10_centos和VM_0_15_centos操作:

    VM_0_10_centos上:

      [root@VM_0_10_centos ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

      [root@VM_0_10_centos ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

      [root@VM_0_10_centos ~]#yum install -y kmod-drbd84 drbd84-utils kernel*   ##装完重启一下 

  VM_0_15_centos上:

    [root@VM_0_15_centos ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

    [root@VM_0_15_centos ~]# rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

    [root@VM_0_15_centos ~]#yum install -y kmod-drbd84 drbd84-utils  kernel*

    [root@VM_0_15_centos ~]# vim /etc/drbd.d/global_common.conf 

global {

    usage-count no;  #是否参加DRBD使用统计,默认为yes。官方统计drbd的装机量,改为no

    # minor-count dialog-refresh disable-ip-verification

}

common {

    protocol C;      #使用DRBD的同步协议,添加这一行

    handlers {

        pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";

        pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";

        local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";

###需要把这三行的注释去掉

    }

    startup {

        # wfc-timeout degr-wfc-timeout outdated-wfc-timeout wait-after-sb

    }

    options {

        # cpu-mask on-no-data-accessible

    }

    disk {

        on-io-error detach; #配置I/O错误处理策略为分离,添加这一行

        # size max-bio-bvecs on-io-error fencing disk-barrier disk-flushes

        # disk-drain md-flushes resync-rate resync-after al-extents

        # c-plan-ahead c-delay-target c-fill-target c-max-rate

        # c-min-rate disk-timeout

    }

    net {

        # protocol timeout max-epoch-size max-buffers unplug-watermark

        # connect-int ping-int sndbuf-size rcvbuf-size ko-count

        # allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri

        # after-sb-1pri after-sb-2pri always-asbp rr-conflict

        # ping-timeout data-integrity-alg tcp-cork on-congestion

        # congestion-fill congestion-extents csums-alg verify-alg

        # use-rle

    }

    syncer {

        rate 1024M;    #设置主备节点同步时的网络速率,添加这个选项

    }

   6.  新建drbd neo4j.res配置文件

       [root@VM_0_15_centos scripts]# vim /etc/drbd.d/neo4j.res        

        resource neo4j

{ #资源名称

protocol C; #使用协议

meta-disk internal;

device /dev/drbd1; #DRBD设备名称

syncer {

verify-alg sha1;# 加密算法

}

net {

  allow-two-primaries;

}

on VM_0_10_centos {     #hostname一定要设为主机名 VM_0_10_centos,不然下一步会报错的

    disk /dev/vdb1;  #  drbd1使用的磁盘分区为"mysql"

    address 172.17.0.10:7789; #设置DRBD监听地址与端口

}

on VM_0_15_centos {

    disk /dev/vdb1;

    address 172.17.0.15:7789;

}

}

      

[root@VM_0_10_centos ~]# drbdadm create-md neo4j

[root@VM_0_10_centos ~]# drbdadm up neo4j

[root@VM_0_10_centos ~]# drbdadm -- --force primary neo4j

查看VM_0_10_centos的状态:

[root@VM_0_10_centos ~]# cat /proc/drbd 

neo4j社区版高可用搭建_第3张图片

[root@VM_0_15_centos ~]# drbdadm create-md neo4j

[root@VM_0_15_centos ~]# drbdadm up neo4j

查看VM_0_15_centos的状态:

[root@VM_0_15_centos ~]# cat /proc/drbd 

neo4j社区版高可用搭建_第4张图片

 

7.   挂载/dev/drbd 到 /data/drbd  

      [root@VM_0_10_centos scripts]# /dev/drbd1 /data/drbd

二、搭建keepalived 

     1. 分别在俩台机器下载安装keepalived 

       [root@VM_0_15_centos ~]# wget http://www.keepalived.org/software/keepalived-1.4.2.tar.gz

       [root@VM_0_15_centos ~]# tar zxvf keepalived-1.4.2.tar.gz

       [root@VM_0_15_centos ~] yum install -y gcc openssl-devel popt-devel

       [root@VM_0_15_centos ~]  cd keepalived-1.4.2 #指定安装目录

       [root@VM_0_15_centos ~]./configure --prefix=/usr/local/keepalived

       [root@VM_0_15_centos ~] make && make install

       [root@VM_0_15_centos ~] mkdir /etc/keepalived

       [root@VM_0_15_centos ~] cp /usr/local/keepalived/etc/keepalived/keepalived.conf  /etc/keepalived/

       [root@VM_0_15_centos ~] cp /usr/local/keepalived/etc/sysconfig/keepalived  /etc/sysconfig/

       [root@VM_0_15_centos ~]  cp /usr/local/keepalived/sbin/keepalived /usr/sbin/

      3.配置主机器配置文件  

         [root@VM_0_10_centos ~]  vim /etc/keepalived/keepalived.conf

! Configuration File for keepalived

global_defs {

   router_id LVS_DEVEL

   #vrrp_strict

}



vrrp_script check_neo4j {

    script "/data/scripts/check_neo4j.sh"

    interval 1

    fall 2

}

vrrp_instance VI_1 {

    state MASTER

    interface eth0

    virtual_router_id 52

    priority 100

    advert_int 1

    # 如果两节点的上联交换机禁用了组播,则采用vrrp单播通告的方式

    # 本机ip

    unicast_src_ip 172.17.0.10

    unicast_peer {

      #   其他机器ip

        172.17.0.15

    }

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        172.17.0.13

    }

    notify_stop /data/scripts/notify_stop.sh

    notify_master /data/scripts/notify_master.sh

    track_script {

        check_neo4j

    }

}

      4.配置从机器配置文件

        [root@VM_0_10_centos ~]  vim /etc/keepalived/keepalived.conf

                         

global_defs {

   router_id LVS_DEVEL

   #vrrp_strict

}

vrrp_instance VI_1 {

    state BACKUP

    interface eth0

    virtual_router_id 52

    priority 90

    advert_int 1

    # 如果两节点的上联交换机禁用了组播,则采用vrrp单播通告的方式

    # 本机ip

    unicast_src_ip 172.17.0.15

    unicast_peer {

        # 其他机器ip

        172.17.0.10

    }

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

        172.17.0.13

    }

    notify_master /data/scripts/notify_master.sh

    notify_backup /data/scripts/notify_backup.sh

}

      5.配置主机器脚本目录和数据库目录

         [root@VM_0_10_centos ~]  mkdir -p /data/scripts   /data/logs/ data/drbd 

        并在该目录存放如下脚本,脚本

      neo4j社区版高可用搭建_第5张图片

  check_neo4j.sh       

#!/bin/sh
ps_out=`ps -ef | grep neo4j-community | grep -v 'grep' | grep -v check_neo4j.sh`:
result=$(echo $ps_out | grep "neo4j-community")
if [[ "$result" != "" ]];then
    echo "Running"
else
   # /data/drbd/neo4j-community-3.5.3/bin/neo4j start >> /data/logs/keepalived/notify_master.log
   # sleep 2
    echo "干掉keepalived $result"  >/tmp/check.log
    killall keepalived
fi

  notify_master.sh       

 #!/bin/bash
time=`date "+%F  %H:%M:%S"`
echo -e "$time  ------notify_master------\n" >> /data/logs/keepalived/notify_master.log
#ssh root@inte-neo4j-02 "reboot" >> /data/logs/keepalived/notify_master.log
drbdadm primary neo4j >> /data/logs/keepalived/notify_master.log
mount /dev/drbd1 /data/drbd >> /data/logs/keepalived/notify_master.log
/data/drbd/neo4j-community-3.5.3/bin/neo4j start >> /data/logs/keepalived/notify_master.log
echo -e "end \n" >> /data/logs/keepalived/notify_master.log

notify_stop.sh

#!/bin/bash
time=`date "+%F  %H:%M:%S"`
echo -e "$time  ------notify_stop------\n" >> /data/logs/keepalived/notify_stop.log
fuser -mvk /data/drbd
/bin/umount /data/drbd >> /data/logs/keepalived/notify_stop.log
echo 'unount success'
/usr/sbin/drbdadm secondary neo4j >> /data/logs/keepalived/notify_stop.log
#/usr/bin/systemctl stop keepalived >> /data/logs/keepalived/notify_stop.log
echo -e " end \n" >> /data/logs/keepalived/notify_stop.log

 

      5.配置从机器脚本目录和数据库目录

         [root@VM_0_10_centos ~]  mkdir -p /data/scripts   /data/logs/ data/drbd 

        并在该目录存放如下脚本,脚本见附件

neo4j社区版高可用搭建_第6张图片     

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

notify_backup.sh​

#!/bin/bash
time=`date "+%F  %H:%M:%S"`
echo -e "$time  ------notify_backup------\n" >> /data/logs/keepalived/notify_backup.log
/data/drbd/neo4j-community-3.5.3/bin/neo4j stop >> /data/logs/keepalived/notify_backup.log
#fuser -mvk /data/drbd
/bin/umount /data/drbd >> /data/logs/keepalived/notify_backup.log
echo "umount success"
/usr/sbin/drbdadm secondary neo4j >> /data/logs/keepalived/notify_backup.log
echo -e "end \n" >> /data/logs/keepalived/notify_backup.log
~

notify_master.sh

▽
#!/bin/bash
time=`date "+%F  %H:%M:%S"`
echo -e "$time  ------notify_master------\n" >> /data/logs/keepalived/notify_master.log
#ssh root@inte-neo4j-01 "reboot" >> /data/logs/keepalived/notify_master.log
drbdadm primary neo4j >> /data/logs/keepalived/notify_master.log
mount /dev/drbd1 /data/drbd >> /data/logs/keepalived/notify_master.log
/data/drbd/neo4j-community-3.5.3/bin/neo4j start >> /data/logs/keepalived/notify_master.log
echo -e "end \n" >> /data/logs/keepalived/notify_master.log

6. 俩台机器启动keepalived

        [root@VM_0_10_centos scripts]# service keepalived start

        [root@VM_0_15_centos scripts]# service keepalived start

   7. keepalive 正常启动的话 VM_0_10_centos 会有一个vip 生成

   neo4j社区版高可用搭建_第7张图片

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

​        

8.   下载neo4j-community-3.5.3 解压

     [root@VM_0_10_centos neo4j-community-3.5.3]# pwd

          /data/drbd/neo4j-community-3.5.3

  9.        启动图数据库

      [root@VM_0_10_centos bin]# pwd

          /data/drbd/neo4j-community-3.5.3/bin

       [root@VM_0_10_centos bin]# ./neo4j start

 

10.  现在 hvip 172.17.0.13  7474端口 7687 端口都可以通了

   neo4j社区版高可用搭建_第8张图片

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

 

11.如果这是一个内网ip可以通过nginx 反向代理出去 给外网访问

       [root@VM_0_10_centos bin] docker  run --name nginx -d -p 8083:8083 -p 17687:17687 -v $PWD/nginx/html:/mnt/nginx/html  -v          $PWD/conf/nginx.conf:/etc/nginx/nginx.conf  -d docker.io/nginx

       nginx.conf 关键配置文件如下

     


  server {

        listen       8083;

        listen       [::]:8083;

        server_name  127.0.0.1:8083;

        root         /mnt/nginx/html/cmdb-web;

        location /browser/ {

            proxy_pass   http://172.17.0.13:7474;

        }

    }

}

  stream {

   server {

      listen 17687;

       proxy_pass 172.17.0.13:7687;

    }

  }

 

你可能感兴趣的:(neo4j)