Zookeeper
三台虚拟机:zookeeper1(节点1)、zookeeper2(节点2)、zookeeper3(节点3)
基础环境部署
3个节点均修改/etc/hosts文件
#vi /etc/hosts
172.16.51.23 zookeeper1
172.16.51.32 zookeeper2
172.16.51.41 zookeeper3
配置yum源
将gpmlall-repo上传至3个节点的/opt目录下,并将3个节点/etc/yum.repos.d目录下的文件移动到/media目录下,同时创建/etc/yum.repos.d/local.repo,写入以下内容
#mv /etc/yum.repos.d/* /media/
#vi /etc/yum.repos.d/local.repo
[gpmall]
name=gpmall
baseurl=file:///opt/gpmall-repo
gpgcheck=0
enabled=1
#yum clean all
#yum list
搭建zookeeper集群
3个节点均安装JDK环境
#yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel
#yum -version
将zookeeper软件包上传至3个节点的/root目录下,并进行解压
#tar -zxvf zookeeper-3.4.14.tar.gz
修改3个节点的配置文件
Zookeeper1节点:进入zookeeper-3.4.14/conf目录下,修改zoo_sample.cfg文件为zoo.cfg,并边检文件内容如下:
#vi zoo.cfg
#grep -n '^'[a-Z] zoo.cfg
2:tickTime=2000
5:initLimit=10
8:syncLimit=5
12:dataDir=/tmp/zookeeper
14:clientPort=2181
29:server.1=172.16.51.23:2888:3888
30:server.2=172.16.51.32:2888:3888
31:server.3=172.16.51.41:2888:3888
创建myid文件
3个节点:
#mkdir /tmp/zookeeper
#vi /tmp/zookeeper/myid
//三个节点写入文件分别对应为1、2、3
启动zookeeper服务
3个节点:
#cd /zookeeper/bin
#./zkserver.sh start
#./zkServer.sh status
配置完成后zookeeper2为leader,其他都是follower
kafka
将kafka软件版上传至3个节点的/root目录下,并解压
#tar -zxvf kafka_2.11-1.1.1.tgz
修改3个节点的配置文件
Zookeeper1:
#cd /kafka_2.11-1.1.1/config
#vi server.properties (注释掉下面这两行)
#broker.id=0
#zookeeper.connect=localhost:2181
在配置文件底部添加以下3个配置
broker.id=1
zookeeper.connect=172.16.51.23:2181,172.16.51.32:2181,172.16.51.41:2181
listeners = PLAINTEXT://172.16.51.23:9092
//broker.id三台机器分别对应为1、2、3
//zookeeper.connect 三台机器对应ip地址
//listeners 三台机器对应ip地址
3台机器启动服务
#./kafka-server-start.sh -daemon ../config/server.properties
#jps
11416 Kafka
11464 Jps
10479 QuorumPeerMain
测试服务
Zookeeper1:
#cd /kafka_2.11.1.1/bin
#./kafka-topics.sh --create --zookeeper 172.16.51.23:2181 --replication-factor 1 --partitions 1 --topic test
//如果成功的话,会输出“Created topic "test".”
Zookeeper2:
#cd /kafka_2.11.1.1/bin
# ./kafka-topics.sh --list --zookeeper 172.16.51.32:2181
test
Zookeeper3:
#cd /kafka_2.11.1.1/bin
#./kafka-topics.sh --list --zookeeper 172.16.51.41:2181
test