Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/centos-7.4"
config.vm.hostname = "co74kafka"
config.vm.network :public_network, ip:"192.168.1.117"
config.vm.network "private_network", ip: "192.168.55.117", :netmask => "255.255.255.0"
config.vm.provider :virtualbox do |vbox|
vbox.name = "co74kafka"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
config.vm.provision "shell", inline: <<-SHELL
# install OpenJDK8
yum -y install java-1.8.0-openjdk
# install kafka
wget http://ftp.riken.jp/net/apache/kafka/0.11.0.1/kafka_2.11-0.11.0.1.tgz
tar xvfz kafka_2.11-0.11.0.1.tgz
mv kafka_2.11-0.11.0.1 /opt
cat << EOF > /etc/systemd/system/zookeeper.service
[Unit]
Description=Apache Zookeeper
Requires=network.target
After=network.target
[Service]
Type=simple
ExecStart=/opt/kafka_2.11-0.11.0.1/bin/zookeeper-server-start.sh /opt/kafka_2.11-0.11.0.1/config/zookeeper.properties
ExecStop=/opt/kafka_2.11-0.11.0.1/bin/zookeeper-server-stop.sh
[Install]
WantedBy=multi-user.target
EOF
systemctl enable zookeeper.service
systemctl start zookeeper.service
cat << EOF > /etc/systemd/system/kafka.service
[Unit]
Description=Apache Kafka
Requires=network.target
After=zookeepepr.service
[Service]
Type=simple
ExecStart=/opt/kafka_2.11-0.11.0.1/bin/kafka-server-start.sh /opt/kafka_2.11-0.11.0.1/config/server.properties
ExecStop=/opt/kafka_2.11-0.11.0.1/bin/kafka-server-stop.sh
[Install]
WantedBy=multi-user.target
EOF
systemctl enable kafka.service
systemctl start kafka.service
# 2181ポートでlistenするまで待つ.
while netstat -lnt | awk '$4 ~ /:2181$/ {exit 1}'; do sleep 10; done
sleep 10
# テスト用トピックを作成
/opt/kafka_2.11-0.11.0.1/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
# メッセージを送る
/opt/kafka_2.11-0.11.0.1/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test << EOF
Hello Kafka!
EOF
# メッセージを取得
/opt/kafka_2.11-0.11.0.1/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --max-messages 1
SHELL
end
○関連情報
・Apache Kafkaに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿