LoginSignup
1
0

More than 3 years have passed since last update.

ZooKeeper(Standalone) を Vagrant で構築した

Last updated at Posted at 2019-06-10

Solr Cloud を構築するには ZooKeeper を構築する必要があります.
そこで Vagrant で ZooKeeper を構築しました.
ZooKeeper のバージョンは 3.4.14 です.
Vagrant の使い方は Vagrant 入門 をご覧ください.

ZooKeeper???

Solr Cloud を構築する上で必須なサービスです.
Solr Cloud では collection を 複数の shard に分けることでインデックスを分散し,さらに shard を replication により複製し冗長構成をとることで可用性を向上させます.
ZooKeeper は分散アプリケーションの管理をおこない,Solr Cloud において shard の replica が格納された Solr の各 node の状態を管理します.

構成

ZooKeeper の構築はシェルでやることにしました.

D:\vagrant\zk
┣Vagrantfile
┗create_zk.sh

Vagrantfile

  • OS は CentOS 7 を使用します.
  • プロビジョナでシェルを実行します.
Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
  config.vm.network "private_network", ip: "192.168.33.10"

  config.proxy.enabled  = true
  config.proxy.http     = "http://user_id:password@proxy_address:proxy_port"
  config.proxy.https    = "http://user_id:password@proxy_address:proxy_port"
  config.proxy.no_proxy = "localhost,127.0.0.1"

  config.vm.provision :shell, path: "./create_zk.sh"
end

create_zk.sh

  • Java をインストールします.
  • ZooKeeper のアーカイブを取得して展開します.
  • ZooKeeper で使用する Port を開放します.
# Java をインストールする
yum install -y java-1.8.0-openjdk

# ZooKeeper を構築する
cd /var/tmp
yum install -y wget
wget http://ftp.jaist.ac.jp/pub/apache/zookeeper/zookeeper-3.4.14/zookeeper-3.4.14.tar.gz
tar xvf zookeeper-3.4.14.tar.gz
cp -ar zookeeper-3.4.14 /opt/
ln -s /opt/zookeeper-3.4.14 /opt/zookeeper

# ZooKeeper 用のユーザを作成する
groupadd zookeeper
useradd -g zookeeper -d /opt/zookeeper -s /sbin/nologin zookeeper
chown -R zookeeper.zookeeper /opt/zookeeper/*

# ZooKeeperの設定ファイルを用意する
cd /opt/zookeeper/conf
cp zoo_sample.cfg zoo.cfg

# dataDir を tmp から var に変更する
mkdir /var/lib/zookeeper
chown zookeeper.zookeeper /var/lib/zookeeper
cd /opt/zookeeper/conf
sed -i -e 's#dataDir=.*$#dataDir=/var/lib/zookeeper#' zoo.cfg

# ZooKeeper を起動する
cd /opt/zookeeper
bin/zkServer.sh start

# Port を開放する
systemctl enable firewalld.service
systemctl start firewalld.service
firewall-cmd --zone=public --add-port=2181/tcp --permanent
firewall-cmd --reload

ZooKeeper を構築する

> pwd
D:\vagrant\zk
> vagrant up

動作確認

サービスの状態を確認します.

> vagrant ssh -c "sudo /opt/zookeeper/bin/zkServer.sh status"
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper/bin/../conf/zoo.cfg
Mode: standalone

nc(netcat) で ZooKeeper に Are you OK? と聞きます.

> vagrant ssh -c "yum install -y nc"
> vagrant ssh -c "echo ruok | nc localhost 2181"
imok

I'm OK と答えたので問題ないです.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0