kafka下载,解压,设置软链接
目录 /usr/lib/
wget http://apache.fayea.com/kafka/0.10.0.0/kafka_2.11-0.10.0.0.tgz
tar -zxf kafka_2.11-0.10.0.0.tgz
ln -s kafka_2.11-0.10.0.0 kafka
目录 /usr/lib/kafka
vim config/zookeeper.properties
修改
dataDir=/data/zookeeper/ #zookeeper元信息路径
#maxClientCnxns=0
添加
tickTime=2000
initLimit=5
syncLimit=2
server.1=host1:2888:3888
server.2=host2:2888:3888
server.3=host3:2888:3888
在dataDir目录中添加标示
echo 1 >/data/zookeeper/myid //1对应server.1
vim config/server.properties
broker.id=0(每台不一样)
port=9092
host.name=host1
advertised.host.name=host1
log.dirs=/data/kafka-logs
num.partitions=5
log.retention.hours=168 #topic默认保存一周
vim /consumer.properties
zookeeper.connect=host1:2181,host2:2181,host3:2181
vim /producer.properties
bootstrap.servers=host1:9092,host2:9092,host3:9092,host4:9092,host5:9092
先创建好所需路径
mkdir /data/zookeeper
midir /data/kafka-logs
接下来将host1中配置好的kafka复制到其它机器中,需要配置scp
ssh-keygen -t rsa
三次回车
将生成的/root/.ssh/id_rsa.pub中的内容,粘贴到其他机器的/root/.ssh/authorized_keys中
*注意复制粘贴时检查中间是否藏了回车
其他机器 vim /etc/hosts.allow 添加
sshd :host1 :allow
之后在host1中,可以进行scp文件传输
scp -r kafka_2.11-0.10.0.0 host2:/usr/lib/
登录其他机器,修改server.properties
broker.id=1
host.name=host2
advertised.host.name=host3
创建myid
echo 2 >/data/zookeeper/myid
目录:/usr/lib/kafka
bin/zookeeper-server-start.sh config/zookeeper.properties &
分别在三台机器上启动,启动前两台时因连不上其他机器,可能报错,等三台机器都启动zookeeper后错误消失
目录:/usr/lib/kafka
JMX_PORT=9991 bin/kafka-server-start.sh config/server.properties &
JMX_PORT=9992 bin/kafka-server-start.sh config/server.properties &
JMX_PORT=9993 bin/kafka-server-start.sh config/server.properties &
JMX_PORT=9994 bin/kafka-server-start.sh config/server.properties &
JMX_PORT=9995 bin/kafka-server-start.sh config/server.properties &
分别在五台机器上启动,命令前带参数JMX_PORT,五个不可重复
*下载,编译及运行 需要java8或以上
git clone https://github.com/yahoo/kafka-manager
cd kafka-manager
./sbt clean dist
cd kafka-manager/target/universal
unzip kafka-manager-1.3.0.8.zip
cd kafka-manager-1.3.0.8
bin/kafka-manager
https://github.com/quantifind/KafkaOffsetMonitor/releases/download/v0.2.1/KafkaOffsetMonitor-assembly-0.2.1.jar
java -Xms1024M -Xmx1024M -Xss1024K -XX:PermSize=512m -XX:MaxPermSize=1024m -cp KafkaOffsetMonitor-assembly-0.2.1.jar com.quantifind.kafka.offsetapp.OffsetGetterWeb --zk host1:2181,host2:2181,host3:2181 --port 8086 --refresh 10.seconds --retain 7.days > mobile-logs/stdout.log 2> mobile-logs/stderr.log &
目录:/usr/lib/kafka
在Kafka Manager中,点击Topic->create
设置Topic名称,分区数,备份数,这里设为2备份,5分区
任意一台机器上
bin/kafka-console-producer.sh --broker-list host1:9092,host2:9092,host3:9092,host4:9092,host5:9092 --topic test
任意一台机器上
bin/kafka-console-consumer.sh --zookeeper host1:2181 --from-beginning --topic test
参考文献
http://blog.csdn.net/dhtx_wzgl/article/details/46892231
http://my.oschina.net/wangjiankui/blog/653139