以下のVagrantfileを使用して、Apache ZooKeeperをインストールした仮想マシンを構築する事ができます。
Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/centos-7.4"
config.vm.hostname = "co74zookeeper"
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 = "co74zookeeper"
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
# download and install zookeeper
wget http://ftp.riken.jp/net/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz
tar xvfz zookeeper-3.4.11.tar.gz
mv zookeeper-3.4.11 /opt/zookeeper
# create configuration file.
cat << EOF > /opt/zookeeper/conf/zoo.cfg
tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
EOF
# register as a service.
cat << EOF > /etc/systemd/system/zookeeper.service
[Unit]
Description=Apache Zookeeper
Requires=network.target
After=network.target
[Service]
Type=forking
ExecStart=/opt/zookeeper/bin/zkServer.sh start /opt/zookeeper/conf/zoo.cfg
ExecStop=/opt/zookeeper/bin/zkServer.sh stop
WorkingDirectory=/opt/zookeeper
[Install]
WantedBy=multi-user.target
EOF
systemctl enable zookeeper.service
systemctl start zookeeper.service
# 2181ポートでlistenするまで待つ.
while netstat -lnt | awk '$4 ~ /:2181$/ {exit 1}'; do sleep 10; done
sleep 10
# サンプル実行
/opt/zookeeper/bin/zkCli.sh -server localhost:2181 create /test mydata
/opt/zookeeper/bin/zkCli.sh -server localhost:2181 ls /
/opt/zookeeper/bin/zkCli.sh -server localhost:2181 get /test
SHELL
end
0 件のコメント:
コメントを投稿