Centos kafka 消息队列

Posted by 小炒肉 on June 2, 2016

kafka 消息队列

安装配置

查询下载最新版本 kafka http://kafka.apache.org/downloads.html

1
2
3
4
5
wget http://mirror.bit.edu.cn/apache/kafka/0.8.2.0/kafka-0.8.2.0-src.tgz
tar zxvf kafka-0.8.2.0-src.tgz
mv kafka-0.8.2.0-src /opt/local/kafka
cd /opt/local/kafka
./gradlew jar

提示: 错误: 找不到或无法加载主类 org.gradle.wrapper.GradleWrapperMain 需要先安装 gradle

1
2
3
http://www.scala-lang.org/files/archive/scala-2.10.4.tgz
tar zxvf scala-2.10.4.tgz
mv scala-2.10.4 /usr/lib64/scala

设置环境变量

1
vi /etc/profile
1
2
3
export SACLA_HOME=/usr/lib64/scala/
export PATH=$SACLA_HOME/bin:$PATH
source /etc/profile

然后再执行 gradlew jar

1
./gradlew jarAll

如果 jarAll 会报错,java 版本不能为1.8 不然会报不兼容的错误,请使用1.7版本

./gradlew jar –stacktrace –info –debug

创建日志目录

1
mkdir -p /opt/local/kafka/logs

编辑配置文件

1
vim config/server.properties

将 log.dirs=/tmp/kafka-logs 改为

1
log.dirs=/opt/local/kafka/logs

将 zookeeper.connect=localhost:2181 改为

1
zookeeper.connect=172.24.0.100:2181

启动程序

1
2
nohup /opt/local/kafka/bin/zookeeper-server-start.sh /opt/local/kafka/config/zookeeper.properties &
nohup /opt/local/kafka/bin/kafka-server-start.sh /opt/local/kafka/config/server.properties &

创建主题

1
/opt/local/kafka/bin/kafka-topics.sh --create --zookeeper 192.168.20.200:2181 --replication-factor 1 --partitions 1 --topic LJ200

查看现有主题

1
/opt/local/kafka/bin/kafka-topics.sh --list --zookeeper 192.168.20.200:2181