Zookeeper集群搭建及开机自启动

一、Zookeeper集群配置

1.将zoo_sample.cfg改名为zoo.cfg

tickTime=2000

initLimit=10

syncLimit=5

dataLogDir=/opt/zookeeper/logs

dataDir=/opt/zookeeper/data

clientPort=2181

autopurge.snapRetainCount=500

autopurge.purgeInterval=24

server.1= 192.168.10.135:2888:3888

server.2= 192.168.10.136:2888:3888 server.3= 192.168.10.137:2888:3888

2.创建文件夹

mkdir -p /opt/zookeeper/{logs,data}

3.分别写入不同的myid

echo “1” > /opt/zookeeper/data/myid

echo “2” > /opt/zookeeper/data/myid

echo “3” > /opt/zookeeper/data/myid

4.解压zk,并复制到文件夹

tar -zxvf /home/software/zookeeper-3.4.10.tar.gz

mkdir -p /home/opt/zookeeper/

mv /home/software/zookeeper-3.4.10 /home/opt/zookeeper/

到此即配置完成

二、配置zk开机自启

1.进入/etc/rc.d/init.d目录

cd /etc/rc.d/init.d

2.新建文件zookeeper

touch zookeeper

3.添加以下内容,所有机器配置一致

#!/bin/bash

#chkconfig:2345 20 90

#description:zookeeper

#processname:zookeeper

export JAVA_HOME=/home/opt/java/jdk1.8.0_151

case $1 in

    start) su root /home/opt/zookeeper/zookeeper-3.4.10/bin/zkServer.sh start;;

    stop) su root /home/opt/zookeeper/zookeeper-3.4.10/bin/zkServer.sh stop;;

    status) su root /home/opt/zookeeper/zookeeper-3.4.10/bin/zkServer.sh status;;

    restart) su /home/opt/zookeeper/zookeeper-3.4.10/bin/zkServer.sh restart;;

    *) echo “require start|stop|status|restart” ;;

esac

4.给文件设置权限

chmod +x zookeeper

5.加入开机自启列表

chkconfig –add zookeeper

6.查看列表

chkconfig –list

    原文作者:一只努力的微服务
    原文地址: https://www.jianshu.com/p/25fad60ec4db
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞