〇コンテナの構築
LXDで以下のコマンドを実行して、CouchDBがインストールされたコンテナを構築します。
lxc init ubuntu:18.04 ub1804zookeeper
lxc config set ub1804zookeeper user.user-data - < config.yml
lxc start ub1804zookeeper
config.yml
#cloud-config
package_upgrade: true
hostname: ub1804zookeeper
manage_etc_hosts: true
write_files:
- path: /etc/systemd/system/zookeeper.service
content: |
[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
- path: /tmp/zoo.cfg
content: |
tickTime=2000
dataDir=/var/zookeeper
clientPort=2181
runcmd:
- 'apt-get update'
- 'apt-get -y install openjdk-8-jdk'
- 'apt-get -y install unzip'
- 'wget http://ftp.riken.jp/net/apache/zookeeper/zookeeper-3.4.12/zookeeper-3.4.12.tar.gz'
- 'tar xvfz zookeeper-3.4.12.tar.gz'
- 'mv zookeeper-3.4.12 /opt/zookeeper'
- 'mv /tmp/zoo.cfg /opt/zookeeper/conf'
- systemctl enable zookeeper.service
- systemctl start zookeeper.service
- "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"
final_message: "completed."
〇コンテナに入る
lxc exec ub1804zookeeper /bin/bash
〇コンテナのIPを調べる
コンテナのIPは以下のコマンドで調べることができます。
lxc list
〇コンテナの停止
lxc stop ub1804zookeeper
〇コンテナの削除
lxc delete ub1804zookeeper
0 件のコメント:
コメントを投稿