首页 > 网络 > 云计算 >

Zookeeper集群搭建之yellowcong

2017-11-03

Zookeeper集群搭建之yellowcong。之前讲的都是单机的一个zookeeper的安装,这次我们玩集群的操作,通过脚本完成数据的启动,通过脚本来管理zookeeper的集群

之前讲的都是单机的一个zookeeper的安装,这次我们玩集群的操作,通过脚本完成数据的启动,通过脚本来管理zookeeper的集群

架构设计

ip 安装目录 存储目录 日志目录
192.168.66.100:2181 /usr/local/zookeeper/zookeeper1 /tmp/zookeeper1/data/ /tmp/zookeeper1/logs
192.168.66.100:2182 /usr/local/zookeeper/zookeeper2 /tmp/zookeeper2/data/ /tmp/zookeeper2/logs
192.168.66.100:2183 /usr/local/zookeeper/zookeeper3 /tmp/zookeeper3/data/ /tmp/zookeeper3/logs

zookeeper安装

1 zoo.cfg配置

#官方的包
wget https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz

#我七牛的安装包
wget https://yellowcong.qiniudn.com/zookeeper-3.4.10.tar.gz 

#解压
tar -zxvf zookeeper-3.4.10.tar.gz

#修改配置文件
cp zoo_sample.cfg zoo.cfg

#修改配置文件
vim zoo.cfg

以下是配置文件,自己做的时候,需要注意修改dataDir和dataLogDir还有端口配置

# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.

#数据存储目录
dataDir=/tmp/zookeeper1/data

#日志地址
dataLogDir=/tmp/zookeeper1/logs

# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# https://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1

#配置集群,
#server.1 前面这个1 需要在$dataDir 目录建立myid文件写上这个id
#127.0.0.1 这个ip 如果你是多个机器,那就注意点,写自己机器的ip
#2222 第一个2222是各个子节点的数据交流端口
#2225 第二个端口是用于竞选,当某个节点挂掉了,选择主节点
server.1=127.0.0.1:2222:2225
server.2=127.0.0.1:3333:3335
server.3=127.0.0.1:4444:4445

这里写图片描述

2 目录建立

建立目录的节点,同时需要添加myid的号 ,注意每个节点的id和节点的myid文件不能搞错了,刚刚我就搞错了,我说咋一个节点咋都起不来啊。

---------------------节点一------------------------
#创建日志和存储目录
mkdir -p /tmp/zookeeper1/data /tmp/zookeeper1/logs
#添加pid
echo 1 > /tmp/zookeeper1/data/myid 

---------------------节点二------------------------
mkdir -p /tmp/zookeeper2/data /tmp/zookeeper2/logs
echo 2 > /tmp/zookeeper2/data/myid 

---------------------节点三------------------------
mkdir -p /tmp/zookeeper3/data /tmp/zookeeper3/logs
echo 3 > /tmp/zookeeper3/data/myid 

#查看myid文件信息,一定要和当前节点对应上
cat /tmp/zookeeper1/data/myid 
cat /tmp/zookeeper2/data/myid 
cat /tmp/zookeeper3/data/myid 

目录结构
这里写图片描述

3 启动服务

#建立脚本启动,这样省事
vim zookeeper.sh

#给执行权限
chmod +x zookeeper.sh

zookeeper.sh脚本

#!/bin/bash

SERVER1="/usr/local/zookeeper/zookeeper1/zookeeper-3.4.10/bin/zkServer.sh"
SERVER2="/usr/local/zookeeper/zookeeper2/zookeeper-3.4.10/bin/zkServer.sh"
SERVER3="/usr/local/zookeeper/zookeeper3/zookeeper-3.4.10/bin/zkServer.sh"

case $1 in
start)
        echo "start zookeeper"
        sh $SERVER1 start
        sh $SERVER2 start
        sh $SERVER3 start
        ;;
stop)
        echo "stop zookeeper"
        sh $SERVER1 stop
        sh $SERVER2 stop
        sh $SERVER3 stop
        ;;
restart)
        echo "restart zookeeper"
        sh $SERVER1 restart
        sh $SERVER2 restart
        sh $SERVER3 restart
        ;;
status)
        echo "zookeeper info"
        sh $SERVER1 status
        sh $SERVER2 status
        sh $SERVER3 status
        ;;

*)
        echo "./zookeeper.sh start|stop|restart"
        exit 1
        ;;
esac
exit 0

脚本截图,这个地方有简单的启动信息
这里写图片描述

4 设定开机启动

vim /etc/rc.local


su - root -c '/usr/local/zookeeper/zookeeper.sh start'
相关文章
最新文章
热点推荐