Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "ub1604kafka"
config.vm.provider :virtualbox do |vbox|
vbox.name = "ub1604kafka"
vbox.cpus = 2
vbox.memory = 2048
vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
end
config.vm.network "private_network", ip: "192.168.55.105", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.105", :netmask => "255.255.255.0"
config.vm.provision "shell", inline: <<-SHELL
# update packages
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade
locale-gen ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
# install java
apt-get -y install openjdk-8-jdk
# install kafka
wget http://ftp.riken.jp/net/apache/kafka/1.0.0/kafka_2.12-1.0.0.tgz
tar xvfz kafka_2.12-1.0.0.tgz
mv kafka_2.12-1.0.0 /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.12-1.0.0/bin/zookeeper-server-start.sh /opt/kafka_2.12-1.0.0/config/zookeeper.properties
ExecStop=/opt/kafka_2.12-1.0.0/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]
ExecStart=/opt/kafka_2.12-1.0.0/bin/kafka-server-start.sh /opt/kafka_2.12-1.0.0/config/server.properties
ExecStop=/opt/kafka_2.12-1.0.0/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.12-1.0.0/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
# メッセージを送る
/opt/kafka_2.12-1.0.0/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test << EOF
Hello Kafka!
EOF
# メッセージを取得
/opt/kafka_2.12-1.0.0/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning --max-messages 1
SHELL
end
○関連情報
・Apache Kafkaに関する他の記事はこちらを参照してください。
0 件のコメント:
コメントを投稿