Linux下ZooKeeper集群安装

一、简介

  ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,

提供的功能包括:配置维护、域名服务、分布式同步、组服务等。

二、安装

  1、个人三台Linux机器地址为:

主机名    ip地址
node3    192.168.182.xxx
node4    192.168.182.xxx
node5    192.168.182.xxx

  2、登陆其中一台主机后,下载

# 切换目录
cd /root
# 下载
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz
# 创建apps目录
mkdir apps
# 创建zookeeper存储目录
mkdir zkdata
# 解压
tar -zxvf zookeeper-3.4.5.tar.gz -C /root/apps

  3、修改配置

cd  /root/apps/zookeeper-3.4.5/conf/
cp  zoo_sample.cfg  zoo.cfg
vi  zoo.cfg

  其中zoo.cfg内容为,个人需要安装自己安装的环境修改

# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# 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=/root/zkdata
# the port at which the clients will connect
clientPort=2181
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://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=node3:2888:3888
server.2=node4:2888:3888
server.3=node5:2888:3888

  其中修改dataDir为/root/zkdata,再该目录下新建myid文件,内容为server点后的数字,例如:现在安装的是node3机器,则配置集群信息为server.1=node3:2888:3888,myid内容为1

  4、重复2安装node4,node5上的zookeeper,或者使用远程拷贝,修改相应配置

scp -r /home/apps root@node4:/home/apps/
scp -r /home/zkdata root@node4:/home/zkdata/

  5、启动测试,依次启动

# 启动
/root/apps/zookeeper-3.4.5/bin/zkServer.sh start
# 查看状态
/root/apps/zookeeper-3.4.5/bin/zkServer.sh status
# 停止
/root/apps/zookeeper-3.4.5/bin/zkServer.sh stop

  6、也可以写个集群自启动脚本

#!/bin/bash
SERVERS="node3 node4 node5"
echo "start zkServers ..."
for server in $SERVERS
do
    ssh $server "source /etc/profile;/root/apps/zookeeper-3.4.5/bin/zkServer.sh start"
done

 

yexiangyang

moyyexy@gmail.com


 

posted @ 2018-04-02 23:38  墨阳  阅读(282)  评论(0编辑  收藏  举报