1.部署环境
a. 3台 Linux Server Redhat 7.2
[root@kafka-pr opt]# more /etc/hosts
10.170.195.12 kafka-con2
10.170.194.98 kafka-con1
10.170.197.16 kaka-pr
b. JDK1.7(http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.tar.gz)
c.zookeeper 3.5.2(http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.5.2-alpha/zookeeper-3.5.2-alpha.tar.gz)
2.安装与配置
在kaka-pr机器上进行操作:
a.解压JDK配置环境变量:
[root@kafka-pr opt]# tar -zvxf jdk-7u79-linux-x64.tar.gz
[root@kafka-pr ~]# pwd
/root
[root@kafka-pr ~]# more .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
export JAVA_HOME=/opt/jdk1.7.0_79
PATH=$JAVA_HOME/bin:$PATH:$HOME/bin
export PATH
[root@kafka-pr ~]# source .bash_profile
[root@kafka-pr ~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
b.解压zookeeper 到/opt
[root@kafka-pr opt]# tar -zvxf zookeeper-3.5.2-alpha.tar.gz
[root@kafka-pr opt]# cd zookeeper-3.5.2-alpha/
c.创建快照与事务日志目录:
[root@kafka-pr zookeeper-3.5.2-alpha]# mkdir zkdata
[root@kafka-pr zookeeper-3.5.2-alpha]# mkdir zkdatalog
d.配置zoo.cfg文件
[root@kafka-pr conf]# pwd
/opt/zookeeper-3.5.2-alpha/conf
[root@kafka-pr conf]# [root@kafka-pr conf]# cp zoo_sample.cfg zoo.cfg
e.修改zoo.cfg
将如下内容添加到zoo.cfg:
server.1=10.170.197.16:2888:3888
server.2=10.170.194.98:2888:3888
server.3=10.170.195.12:2888:3888
dataDir=/opt/zookeeper-3.5.2-alpha/zkdata
dataLogDir=/opt/zookeeper-3.5.2-alpha/zkdatalog
注意:2888为master 和slave的通讯端口;3888为Leader选举通讯端口
f.创建myid文件
[root@kafka-pr zookeeper-3.5.2-alpha]# cd zkdata
[root@kafka-pr zkdata]# echo "1" > myid
完成kafka-pr 上 zookeeper的所有配置.
e.在 kafka-con1,kafka-con2上依次执行 a-f 步骤,其中f步骤myid内容不能重复:
kafka-con1 myid 值为2:
[root@kafka-con1 zkdata]# pwd
/opt/zookeeper-3.5.2-alpha/zkdata
[root@kafka-con1 zkdata]# more myid
2
kafka-con2 myid 值为3:
[root@kafka-con2 zkdata]# pwd
/opt/zookeeper-3.5.2-alpha/zkdata
[root@kafka-con2 zkdata]# more myid
3
完成安装与配置。
3.启动与验证
在所有服务器上运行zkServer.sh命令:
[root@kafka-con2 bin]# pwd
/opt/zookeeper-3.5.2-alpha/bin
[root@kafka-con2 bin]# ./zkServer.sh start
验证:
kafka-pr 能看到是以follower模式运行:
[root@kafka-pr bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
kafka-con1是以leader角色运行:
[root@kafka-con1 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: leader
kafka-con2 以follower角色运行:
[root@kafka-con2 bin]# ./zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.5.2-alpha/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost.
Mode: follower
部署运行成功!
几个经验分享:
1.运行jps可查看进程情况:
[root@kafka-pr bin]# jps
4523 QuorumPeerMain
2.重要的文件
a. myid文件:本机在集群中的标示
b. zoo.cfg 文件:集群配置文件(超时,日志路径,链接和选举端口,Server ip 等诸多参数配置)
c. log4j.properties :日志文件(定义日志级别,路径等)