在Linux下集群化部署zookeeper(3.7.0版本)

Posted 顧棟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Linux下集群化部署zookeeper(3.7.0版本)相关的知识,希望对你有一定的参考价值。

Linux下zookeeper集群化安装

文章目录

安装前提

检查服务器

  1. 机器域名要可以正常使用(非必要)

  2. 机器列表/etc/hosts文件要完整(生产规范)

  3. 空闲端口(满足安装zookeeper前不被其他进程占用,必要):

    1. 2181 :对cline端提供服务

    2. 2888 :选举leader使用、

    3. 3888 :集群内机器通讯使用(Leader监听此端口)

      netstat -lntp 2>/dev/null|grep LISTEN|awk 'print $4'|awk -F':' 'print $NF'|sort|uniq
      

创建ZK用户

groupadd zookeeper && useradd -g zookeeper zookeeper

创建对应的目录

# root登录
#软件存放目录
mkdir -p /opt/zookeeper
mkdir -p /opt/zookeeper/software
#日志与数据目录
mkdir -p /opt/zookeeper/logs
mkdir -p /opt/zookeeper/zkdata
#软连接目录
mkdir -p /home/zookeeper/software

上传安装包,确认权限

将jdk,zk的安装文件jdk1.8.0_131.tgzapache-zookeeper-3.7.0-bin.tar.gz分发到三台机器上(192.168.1.1,192.168.1.2,192.168.1.3),对应的目录/opt/zookeeper/software上。

scp apache-zookeeper-3.7.0-bin.tar.gz root@192.168.1.1:/opt/zookeeper/software/apache-zookeeper-3.7.0-bin.tar.gz
scp apache-zookeeper-3.7.0-bin.tar.gz root@192.168.1.2:/opt/zookeeper/software/apache-zookeeper-3.7.0-bin.tar.gz
scp apache-zookeeper-3.7.0-bin.tar.gz root@192.168.1.3:/opt/zookeeper/software/apache-zookeeper-3.7.0-bin.tar.gz
scp jdk1.8.0_131.tgz root@192.168.1.1:/opt/zookeeper/software/jdk1.8.0_131.tgz
scp jdk1.8.0_131.tgz root@192.168.1.2:/opt/zookeeper/software/jdk1.8.0_131.tgz
scp jdk1.8.0_131.tgz root@192.168.1.3:/opt/zookeeper/software/jdk1.8.0_131.tgz

###修改权限目录权限
chown -R zookeeper:zookeeper /opt/zookeeper

安装配置

# 切换用户后进行
su - zookeeper

安装jdk

tar -zxf /opt/zookeeper/software/jdk1.8.0_131.tgz -C /opt/zookeeper/software/
ln -nsf /opt/zookeeper/software/jdk1.8.0_131 /home/zookeeper/software/java

安装ZK

tar -zxf /opt/zookeeper/software/apache-zookeeper-3.7.0-bin.tar.gz -C /opt/zookeeper/software/
ln -nsf /opt/zookeeper/software/apache-zookeeper-3.7.0-bin /home/zookeeper/software/zookeeper

环境配置

vim ~/.bashrc

# 追加以下内容
export userEnv=/opt/zookeeper/software
export JAVA_HOME=$userEnv/java
export ZOOKEEPER_HOME=$userEnv/zookeeper
export PATH=$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$ZOOKEEPER_HOME/tools:$PATH

ZK配置

  1. 新增zoo.cfg
vim ~/software/zookeeper/conf/zoo.cfg

# 追加以下内容
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/home/zookeeper/zkdata/
dataLogDir=/home/zookeeper/logs/
clientPort=2181
autopurge.snapRetainCount=3
autopurge.purgeInterval=1
zookeeper.leaderServes=no
server.1=192.168.1.2:2888:3888
server.2=192.168.1.3:2888:3888
server.3=192.168.1.1:2888:3888
  1. 新增myid,在三台机器上各自添加myid文件(值为在zoo.cfg对应的ServerID),文件路径采用zoo.cfgdataDir配置项中的地址。
# 192.168.1.2上执行
touch -p /home/zookeeper/zkdata/myid;echo 1 >> /home/zookeeper/zkdata/myid;
# 192.168.1.3上执行
touch -p /home/zookeeper/zkdata/myid;echo 2 >> /home/zookeeper/zkdata/myid;
# 192.168.1.1上执行
touch -p /home/zookeeper/zkdata/myid;echo 3 >> /home/zookeeper/zkdata/myid;
  1. 使用ROLLINGFILE方式记录ZK日志。在zookeeper/bin下配置zkEnv.sh文件
f [ "x$ZOO_LOG_DIR" = "x" ]
then
    ZOO_LOG_DIR="/home/zookeeper/logs"         
fi
 
if [ "x$ZOO_LOG4J_PROP" = "x" ]
then
    ZOO_LOG4J_PROP="INFO,ROLLINGFILE"        
fi

启动

启动步骤

cd /home/zookeeper/software/zookeeper;zkServer.sh start

启动后检查

cd /home/zookeeper/software/zookeeper;zkServer.sh status
[zookeeper@node1 bin]$ zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/zookeeper/software/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

集群内只有一台为leader,其他均为follower

以上是关于在Linux下集群化部署zookeeper(3.7.0版本)的主要内容,如果未能解决你的问题,请参考以下文章

Linux环境快速部署Zookeeper集群

zookeeper部署到linux操作步骤

Linux安装部署集群化软件Zookeeper

3. linux centos6.8环境下部署zookeeper集群

Zookeeper linux下集群部署

Linux实战——Zookeeper集群安装部署