一台机器上安装zookeeper+kafka集群

版本:

Ubuntu 14.04.1

zookeeper-3.4.6

kafka_2.10-0.10.1.0




1.zookeeper配置
$  sudo mkdir -p  /opt/server/zookeeper/server1/data
$  sudo mkdir -p  /opt/server/zookeeper/server1/dataLog
$  sudo mkdir -p  /opt/server/zookeeper/server2/data
$  sudo mkdir -p  /opt/server/zookeeper/server2/dataLog
$  sudo mkdir -p  /opt/server/zookeeper/server3/data
$  sudo mkdir -p  /opt/server/zookeeper/server3/dataLog


$ sudo chown -R mpr:mpr  /opt/server/*


###server1/server2/server3###
#server1
$  cd /opt/server/zookeeper/server1
#下载
$ wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
#解压
$  tar -zxvf  zookeeper-3.4.6.tar.gz


#server2
$  cd /opt/server/zookeeper/server2
#下载
$  wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
#解压
$  tar -zxvf  zookeeper-3.4.6.tar.gz


#server3
$  cd /opt/server/zookeeper/server3
#下载
$  wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
#解压
$  tar -zxvf  zookeeper-3.4.6.tar.gz
##################################




###server1/server2/server3###
#server1
$  cd /opt/server/zookeeper/server1/zookeeper-3.4.6/conf
$  cp -rf  zoo_sample.cfg   zoo.cfg
$  vim  zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
clientPort=2181
dataDir=/opt/server/zookeeper/server1/data
dataLogDir=/opt/server/zookeeper/server1/dataLog
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890


$  echo "1" > /opt/server/zookeeper/server1/data/myid




#server2
$  cd /opt/server/zookeeper/server2/zookeeper-3.4.6/conf
$  cp -rf  zoo_sample.cfg   zoo.cfg
$  vim  zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
clientPort=2182
dataDir=/opt/server/zookeeper/server2/data
dataLogDir=/opt/server/zookeeper/server2/dataLog
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890


$ echo "2" > /opt/server/zookeeper/server2/data/myid


#server3
$  cd /opt/server/zookeeper/server3/zookeeper-3.4.6/conf
$  cp -rf  zoo_sample.cfg   zoo.cfg
$  vim  zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
clientPort=2183
dataDir=/opt/server/zookeeper/server3/data
dataLogDir=/opt/server/zookeeper/server3/dataLog
server.1=127.0.0.1:2888:3888
server.2=127.0.0.1:2889:3889
server.3=127.0.0.1:2890:3890


$  echo "3" > /opt/server/zookeeper/server3/data/myid
################################################


$  cd  /opt/server/zookeeper/server1/zookeeper-3.4.6/bin
$  sh zkServer.sh start
$  cd  /opt/server/zookeeper/server2/zookeeper-3.4.6/bin
$  sh zkServer.sh start
$  cd  /opt/server/zookeeper/server3/zookeeper-3.4.6/bin
$  sh zkServer.sh start


#若出现错误:bin/zkEnv.sh: Syntax error: "(" unexpected (expecting "fi")
#修改Ubuntu的/bin/sh的默认连接,#!/bin/dash改为 #!/bin/bash 就OK
$  cd /bin/
$  ls -l /bin/sh
$  ln -sf bash /bin/sh
$  ls -l /bin/sh



$  sh zkServer.sh status

#若出现表示成功,不然就是启动出问题

Mode: standalone/Mode: follower







2.kafka配置
$  sudo mkdir -p  /opt/server/kafka/kafka1/kafkaLog
$  sudo mkdir -p  /opt/server/kafka/kafka2/kafkaLog
$  sudo mkdir -p  /opt/server/kafka/kafka3/kafkaLog


$  sudo chown -R mpr:mpr  /opt/server/*


###server1/server2/server3###
#server1
$  cd /opt/server/kafka/kafka1
$  wget  http://apache.fayea.com/kafka/0.10.0.1/kafka_2.10-0.10.0.1.tgz
$  tar -zxvf kafka_2.10-0.10.1.0.tgz
$  cd  /opt/server/kafka/kafka1/kafka_2.10-0.10.1.0/config
$  vi  server.properties
broker.id=0
log.dirs =/opt/server/kafka/kafka1/kafkaLog
listeners=PLAINTEXT://172.16.2.15:9092
port=9092
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880


$  vi  consumer.properties
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
group.id=logGroup


#server2
$  cd /opt/server/kafka/kafka2
$  wget  http://apache.fayea.com/kafka/0.10.0.1/kafka_2.10-0.10.0.1.tgz
$  tar -zxvf kafka_2.10-0.10.1.0.tgz
$  cd  /opt/server/kafka/kafka2/kafka_2.10-0.10.1.0/config
$  vi  server.properties
broker.id=1
log.dirs =/opt/server/kafka/kafka2/kafkaLog
listeners=PLAINTEXT://172.16.2.15:9093
port=9093
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880


$  vi  consumer.properties
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
group.id=logGroup


#server3
$  cd /opt/server/kafka/kafka3
$  wget  http://apache.fayea.com/kafka/0.10.0.1/kafka_2.10-0.10.0.1.tgz
$  tar -zxvf kafka_2.10-0.10.1.0.tgz
$  cd  /opt/server/kafka/kafka3/kafka_2.10-0.10.1.0/config
$  vi  server.properties
broker.id=2
log.dirs =/opt/server/kafka/kafka3/kafkaLog
listeners=PLAINTEXT://172.16.2.15:9094
port=9094
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
message.max.byte=5242880
default.replication.factor=2
replica.fetch.max.bytes=5242880


$  vi  consumer.properties
zookeeper.connect=127.0.0.1:2181,127.0.0.1:2182,127.0.0.1:2183
group.id=logGroup
################################################










$  cd /opt/server/kafka/kafka1/kafka_2.10-0.10.1.0/bin
--启动
$  ./kafka-server-start.sh  ../config/server.properties  &


$  cd /opt/server/kafka/kafka2/kafka_2.10-0.10.1.0/bin
--启动
$  ./kafka-server-start.sh  ../config/server.properties  &


$  cd /opt/server/kafka/kafka3/kafka_2.10-0.10.1.0/bin
--启动
$  ./kafka-server-start.sh  ../config/server.properties  &

你可能感兴趣的:(kafka)