2018年5月20日日曜日

VagrantでApache Nifi 1.6.0とmosquittoがインストールされた仮想マシン(Debian Stretch/9.4)を構築する。

Apache Nifiは様々なデータを処理・分配するためのソフトウェアです。

〇Apache Nifiの画面

ブラウザからhttp://192.168.1.105:8080/nifi/にアクセスします。

〇構築方法
1.以下のVagrantfileを使用して、Apache Nifi 1.6.0とmosquittoがインストールされた仮想マシン(Debian Stretch/9.4)を構築します。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.4"
  config.vm.hostname = "db94nifi160mosquitto"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db94nifi160mosquitto"
     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
apt-get -y install task-japanese
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

# install mosquitto
apt-get -y install mosquitto mosquitto-clients


# maximum file handles & maximum forked processes
echo '*  hard  nofile  50000' >> /etc/security/limits.conf
echo '*  soft  nofile  50000' >> /etc/security/limits.conf
echo '*  hard  nproc  10000' >> /etc/security/limits.conf
echo '*  soft  nproc  10000' >> /etc/security/limits.conf

echo '*  soft  nproc  10000' >> /etc/security/limits.d/90-nproc

# install java
apt-get -y install openjdk-8-jdk

# download and install Apache Nifi
wget http://ftp.riken.jp/net/apache/nifi/1.6.0/nifi-1.6.0-bin.tar.gz
tar xvfz nifi-1.6.0-bin.tar.gz
mv nifi-1.6.0 /opt

cat << EOF > /etc/systemd/system/nifi.service
[Unit]
Description=Apache Nifi
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/opt/nifi-1.6.0/bin/nifi.sh start
ExecStop=/opt/nifi-1.6.0/bin/nifi.sh stop
KillMode=none

[Install]
WantedBy=multi-user.target
EOF
systemctl enable nifi.service
systemctl start nifi.service

echo 'access url -> http://192.168.1.105:8080/nifi/'

echo 'execute command below for test.'
echo 'mosquitto_pub -t mytopic/test -h localhost -m "test message."'

SHELL
end

2.ConsumeMQTT Processorで、以下のようにパラメータを設定してローカルのmosquittoにアクセスします。
Broker URI : tcp://localhost:1883
Client ID : nifi
Topi Filter : mytopic/test
Quality of Service(QoS) : 0 - At most once
Max Queue Size : 100

※ローカルのmosquittoにメッセージをpublishするには、以下のようなコマンドを実行します。
mosquitto_pub -t mytopic/test -h localhost -m "test message."

VagrantでApache SupersetとMariaDBをインストールした仮想マシン(Debian Stretch/9.4)を構築する

Apache SupersetはPython製のデータ可視化ツールです。

○Apache Supersetの画面


○構築方法
以下のVagrantfileを使用して、Apache SupersetとMariaDBをインストールした仮想マシン(Debian Stretch/9.4)を構築する事ができます。
仮想マシンが構築された後、ブラウザからhttp://192.168.55.107:8088/にアクセスします。
デフォルトユーザ名はadmin、パスワードもadminです。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.4"
  config.vm.hostname = "db94supersetmariadb"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db94supersetmariadb"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.107", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.107", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
apt-get -y install task-japanese
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade


# install mariadb
echo "mariadb-server-10.3 mysql-server/root_password password root" | sudo debconf-set-selections
echo "mariadb-server-10.3 mysql-server/root_password_again password root" | sudo debconf-set-selections
apt-get -y install mariadb-server
apt-get -y install mysql-server
mysql -uroot -e "CREATE DATABASE test DEFAULT CHARACTER SET utf8;"
mysql -uroot -e "CREATE USER test@localhost IDENTIFIED BY 'test';"
mysql -uroot -e "GRANT ALL PRIVILEGES ON test.* TO 'test'@'localhost';"
mysql -uroot -e "FLUSH PRIVILEGES;"
mysql -utest -ptest test -e "create table messages (message_id integer not null, message varchar(100));"
mysql -utest -ptest test -e "insert into messages value (1, 'hello world.');"
mysql -utest -ptest test -e "insert into messages value (2, 'test message.');"

# install anaconda
wget https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh
chmod +x Anaconda3-5.1.0-Linux-x86_64.sh
./Anaconda3-5.1.0-Linux-x86_64.sh -b -p /opt/anaconda
source /opt/anaconda/bin/activate
pip install --upgrade pip

# install dependencies
apt-get -y install build-essential libssl-dev libffi-dev python-dev python-pip libsasl2-dev libldap2-dev

# install mysqlclient
apt-get -y install libmariadbclient-dev
pip install mysqlclient

pip install --upgrade setuptools
pip install superset
pip install cryptography --upgrade
mkdir -p /opt/superset
cd /opt/superset
fabmanager create-admin --app superset --username admin --firstname admin --lastname user --email admin@localhost.localdomain --password admin
superset db upgrade
superset load_examples
superset init
superset runserver -a 0.0.0.0 &
echo 'access http://192.168.55.107:8088/'
echo 'user:admin, password: admin'

SHELL
end

○データソースの追加
同じ仮想マシンにインストールされたMariaDBに接続するには、以下の画面のようにSQLAlchemy URIにmysql://test:test@localhost/testを指定します。


LXDでApache Zookeeper3.4.12がインストールされたコンテナ(Ubuntu18.04)を構築する

Apache Zookeeperは設定情報や構成情報を管理する分散システムです。

〇コンテナの構築
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

VagrantでAmbari(HDP2.6)/HDFS/Hiveをインストールした仮想マシン(CentOS7.4)を構築する

HiveでHadoop上のデータにクエリーを実行する事ができます。

〇Ambariの画面

ブラウザでhttp://192.168.1.117:8080/にアクセスします。ユーザ/パスワードはadmin/adminです。

〇構築方法
以下のVagrantfileを使用して、Ambari/HDFS/Hiveをインストールした仮想マシン(CentOS7.4)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/centos-7.4"
  config.vm.hostname = "co74hive.vm.internal"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "co74hive.vm.internal"
     vbox.cpus = 4
     vbox.memory = 10240 
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
  # private network
  config.vm.network "private_network", ip: "192.168.55.117", :netmask => "255.255.255.0"
  # bridge netwrok
  config.vm.network "public_network", ip: "192.168.1.117", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
localectl set-locale LANG=ja_JP.UTF-8
echo "192.168.55.117 co74hive" >> /etc/hosts

cd /root
mkdir ./.ssh
ssh-keygen -f ./.ssh/id_rsa -t rsa -N ''

# copy private key
cp -f ./.ssh/id_rsa /vagrant
cat ./.ssh/id_rsa.pub >> ./.ssh/authorized_keys
chmod 600 ./.ssh/authorized_keys

# install and configure ambari server
cd /etc/yum.repos.d/
wget http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.6.2.0/ambari.repo
yum -y install ambari-server ambari-agent
ambari-server setup --silent
ambari-server start

# create hive database and hive user
echo "host    all         all         127.0.0.1/32          password" >> /var/lib/pgsql/data/pg_hba.conf
echo "host    all         all         192.168.1.0/24          password" >> /var/lib/pgsql/data/pg_hba.conf
echo "host    all         all         192.168.55.0/24          password" >> /var/lib/pgsql/data/pg_hba.conf
sudo su - postgres << EOF
createdb hive
createdb oozie
psql -c "
create user hive with password 'hive';
grant all privileges on database hive to hive;
create user oozie with password 'oozie';
grant all privileges on database oozie to oozie;
"
EOF
service postgresql restart

yum -y install postgresql-jdbc*
chmod 644 /usr/share/java/postgresql-jdbc.jar

ambari-server setup -s --database=postgres --databasehost=localhost --databaseport=5432 --databasename=hive --databaseusername=hive --databasepassword=hive --jdbc-db=postgres --jdbc-driver=/usr/share/java/postgresql-jdbc.jar
ambari-agent start


cat << EOF > /home/vagrant/cluster_configuration.json
{
  "configurations" : [
    {
      "hive-site": {
        "hive.support.concurrency": "true",
        "hive.txn.manager": "org.apache.hadoop.hive.ql.lockmgr.DbTxnManager",
        "hive.compactor.initiator.on": "true",
        "hive.compactor.worker.threads": "5",
        "javax.jdo.option.ConnectionDriverName": "org.postgresql.Driver",
        "javax.jdo.option.ConnectionPassword": "hive",
        "javax.jdo.option.ConnectionURL": "jdbc:postgresql://localhost/hive",
        "javax.jdo.option.ConnectionUserName": "hive"
      }
    },
    {
      "hive-env": {
        "hive_ambari_database": "PostgreSQL",
        "hive_database": "Existing PostgreSQL Database",
        "hive_database_type": "postgres",
        "hive_database_name": "hive"
      }
    },
    {
      "core-site": {
        "properties" : {
          "hadoop.proxyuser.root.groups" : "*",
          "hadoop.proxyuser.root.hosts" : "*"
        }
      }
    }
  ],
  "host_groups" : [
    {
      "name" : "host_group_1",
      "components" : [
        {
          "name" : "NAMENODE"
        },
        {
          "name" : "SECONDARY_NAMENODE"
        },
        {
          "name" : "DATANODE"
        },
        {
          "name" : "HDFS_CLIENT"
        },
        {
          "name" : "RESOURCEMANAGER"
        },
        {
          "name" : "NODEMANAGER"
        },
        {
          "name" : "YARN_CLIENT"
        },
        {
          "name" : "HISTORYSERVER"
        },
        {
          "name" : "APP_TIMELINE_SERVER"
        },
        {
          "name" : "ZOOKEEPER_SERVER"
        },
        {
          "name" : "ZOOKEEPER_CLIENT"
        },
        {
          "name" : "METRICS_MONITOR"
        },
        {
          "name" : "TEZ_CLIENT"
        },
        {
          "name" : "HIVE_SERVER"
        },
        {
          "name" : "HIVE_METASTORE"
        },
        {
          "name" : "METRICS_COLLECTOR"
        },
        {
          "name" : "WEBHCAT_SERVER"
        }
      ],
      "cardinality" : "1"
    }
  ],
  "settings" : [{
     "recovery_settings" : [{
       "recovery_enabled" : "true"
    }]
  }],
  "Blueprints" : {
    "blueprint_name" : "hdp26-minimal-hive",
    "stack_name" : "HDP",
    "stack_version" : "2.6"
  }
}
EOF

curl -H "X-Requested-By: ambari" -X POST -u admin:admin http://localhost:8080/api/v1/blueprints/hdp26-minimal-hive -d @/home/vagrant/cluster_configuration.json

cat << EOF > /home/vagrant/hostmapping.json
{
  "blueprint" : "hdp26-minimal-hive",
  "default_password" : "admin",
  "provision_action" : "INSTALL_AND_START",
  "host_groups" :[
    {
      "name" : "host_group_1",
      "hosts" : [
        {
          "fqdn" : "co74hive.vm.internal"
        }
      ]
    }
  ]
}
EOF

curl -H "X-Requested-By: ambari" -X POST -u admin:admin http://localhost:8080/api/v1/clusters/hdp26-minimal-hive -d @/home/vagrant/hostmapping.json
sleep 30


# wait until the cluster is ready.
ProgressPercent=`curl -s --user admin:admin -X GET http://localhost:8080/api/v1/clusters/hdp26-minimal-hive/requests/1 | grep progress_percent | awk '{print $3}' | cut -d . -f 1`
while [[ `echo $ProgressPercent | grep -v 100` ]]; do
  ProgressPercent=`curl -s --user admin:admin -X GET http://localhost:8080/api/v1/clusters/hdp26-minimal-hive/requests/1 | grep progress_percent | awk '{print $3}' | cut -d . -f 1`
  echo " Progress: $ProgressPercent %"
  sleep 10
done


cat << EOF > /home/vagrant/shutdown_components.sh
#!/bin/bash
#stop all services
curl -u admin:admin -i -H 'X-Requested-By: ambari' -X PUT \
   -d '{"RequestInfo":{"context":"_PARSE_.STOP.ALL_SERVICES","operation_level":{"level":"CLUSTER","cluster_name":"hdp26-minnimal-hive"}},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' \
   http://localhost:8080/api/v1/clusters/hdp26-minimal-hive/services
EOF
chmod +x /home/vagrant/shutdown_components.sh


cat << EOF > /tmp/test.csv
store_id,sales
100,15000000
200,20000000
300,18000000
EOF


cat << EOF > /tmp/sample.sql
CREATE EXTERNAL TABLE sample (
  store_id INT,
  sales INT
)
ROW FORMAT SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde'
WITH SERDEPROPERTIES (
   "separatorChar" = ",",
   "quoteChar"     = '"'
)
stored as textfile
LOCATION '/user/hive'
tblproperties ("skip.header.line.count"="1");

LOAD DATA LOCAL INPATH '/tmp/test.csv' OVERWRITE INTO TABLE sample;

select * from sample;
EOF


# upload sample content
sudo -u hive hdfs dfs -put /tmp/sample.sql /user/hive
sudo -u hive hdfs dfs -ls /user/hive

# create table and select
beeline -u 'jdbc:hive2://localhost:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2' -n hive -f /tmp/sample.sql

echo 'access -> http://192.168.1.117:8080'
echo 'user/password -> admin/admin'
SHELL
end

2018年5月19日土曜日

VagrantでPercona ToolkitとMySQLがインストールされた仮想マシン(Debian Stretch/9.3)を構築する

Percona ToolkitはMySQLを管理・メンテナンスするのに役立つコマンド群です。

○構築方法
以下のVagrantfileを使用して、Percona ToolkitとMySQLをインストールした仮想マシン(Debian Stretch/9.3)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.3"
  config.vm.hostname = "db93mysqlperconatoolkit"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db93mysqlperconatoolkit"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.103", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.103", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
apt-get -y install task-japanese
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade


# install mysql
wget https://dev.mysql.com/get/mysql-apt-config_0.8.9-1_all.deb
export DEBIAN_FRONTEND=noninteractive
echo mysql-apt-config mysql-apt-config/enable-repo select mysql-5.7-dmr | sudo debconf-set-selections
dpkg -i mysql-apt-config_0.8.9-1_all.deb
apt-get update
apt-get -y install mysql-server
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' identified by 'root';"
mysql -uroot -e "CREATE DATABASE test DEFAULT CHARACTER SET utf8mb4;"
mysql -uroot -e "CREATE USER test@localhost IDENTIFIED BY 'test';"
mysql -uroot -e "GRANT ALL PRIVILEGES ON test.* TO 'test'@'localhost';"
mysql -uroot -e "FLUSH PRIVILEGES;"

mysql -uroot -proot -e "select * from information_schema.tables;"

# install percona toolkit
wget https://repo.percona.com/apt/percona-release_0.1-4.$(lsb_release -sc)_all.deb
dpkg -i percona-release_0.1-4.$(lsb_release -sc)_all.deb
apt-get update
apt-get -y install percona-toolkit

# display summary information
pt-mysql-summary --user root --password root

SHELL
end

DockerでMezzanine、MariaDBがインストールされたコンテナ(Alpine3.7)を構築する

MezzanineはPython製のCMSです。

○Mezzanineの画面


○構築方法
以下の手順で、Mezzanineのコンテナを構築・実行します。

1. Mezzanineイメージの作成(Dockerfileがあるフォルダで実行)
docker build -t mezzanine .

Dockerfile
FROM python:3.6-alpine3.7

RUN mkdir -p /opt/mezzanine
WORKDIR /opt/mezzanine
RUN apk update \
  && apk add --no-cache --virtual=build-deps jpeg jpeg-dev zlib-dev musl-dev gcc mariadb-dev build-base \
  && pip install mezzanine \
  && pip install mysqlclient \
  && apk del mariadb-dev build-base build-deps gcc \
  && apk add mariadb-client mariadb-client-libs \
  && rm -rf /var/cache/apk/* \
  && mezzanine-project mysite \
  && echo $'#!/bin/sh \n\
until mysql -h db -u root -pmezzanine mezzanine\n\
do \n\
  echo -n "." \n\
  sleep 1 \n\
done \n\
cd /opt/mezzanine/mysite \n\
sed -i -e \'s/"ENGINE": "django.db.backends.sqlite3",/"ENGINE": "django.db.backends.mysql",/\' /opt/mezzanine/mysite/mysite/local_settings.py \n\
sed -i -e \'s/"NAME": "dev.db",/"NAME": "mezzanine",/\' /opt/mezzanine/mysite/mysite/local_settings.py \n\
sed -i -e \'s/"USER": "",/"USER": "root",/\' /opt/mezzanine/mysite/mysite/local_settings.py \n\
sed -i -e \'s/"PASSWORD": "",/"PASSWORD": "mezzanine",/\' /opt/mezzanine/mysite/mysite/local_settings.py \n\
sed -i -e \'s/"HOST": "",/"HOST": "db",/\' /opt/mezzanine/mysite/mysite/local_settings.py \n\
sed -i -e \'s/"PORT": "",/"PORT": "3306",/\' /opt/mezzanine/mysite/mysite/local_settings.py \n\
sed -i -e \'s/# ALLOWED_HOSTS = \[""\]/ALLOWED_HOSTS  = ["*"]/\' /opt/mezzanine/mysite/mysite/local_settings.py \n\
python manage.py createdb --noinput \n\
python manage.py migrate --noinput \n\
python manage.py runserver 0.0.0.0:80' > /opt/mezzanine/mysite/start.sh \
  && chmod +x /opt/mezzanine/mysite/start.sh
EXPOSE 80
VOLUME /opt/mezzanine/mysite
CMD ["/opt/mezzanine/mysite/start.sh"]

2. MezzanineとMariaDBコンテナの構築・実行(docker-compose.ymlがあるフォルダで実行)
docker-compose up -d

docker-compose.yml
version: "2"
services:
  db:
    image: mariadb:10.3
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    container_name: "mezzanine-db"
    volumes:
      - "db-data:/var/lib/mysql"
    ports:
      - "3306:3306"
    environment:
        MYSQL_DATABASE: mezzanine
        MYSQL_ROOT_PASSWORD: mezzanine
  mezzanine:
    image: mezzanine
    container_name: "mezzanine"
    volumes:
      - "mezzanine-data:/opt/mezzanine/mysite"
    ports:
      - "80:80"
    depends_on:
      - db
volumes:
  db-data:
    driver: local
  mezzanine-data:
    driver: local

3.ブラウザから以下のURLにアクセス
http://<Dockerホスト名またはIP>/
※デフォルトユーザとパスワードはadmin/defaultです。

2018年5月18日金曜日

VagrantでJBake2.6.0がインストールされた仮想マシン(Debian Stretch/9.3)を構築する

JBakeはJava製の静的サイトジェネレータです。

〇JBakeの画面


〇構築方法
以下のVagrantfileを使用してJBakeがインストールされた仮想マシンを構築する事ができます。
仮想マシン構築後、sshで仮想マシンにログインし、以下のコマンドを実行します。
cd project/output
python -m SimpleHTTPServer

Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/debian-9.3"
  config.vm.hostname = "db93jbake"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "db93jbake"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.104", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.104", :netmask => "255.255.255.0"
  config.vm.provision "shell", inline: <<-SHELL
apt-get -y install task-japanese
sed -i -e 's/# ja_JP.UTF-8 UTF-8/ja_JP.UTF-8 UTF-8/' /etc/locale.gen
locale-gen
update-locale LANG=ja_JP.UTF-8
localectl set-locale LANG=ja_JP.UTF-8
localectl set-keymap jp106
apt-get update
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

# install java
apt-get -y install openjdk-8-jdk

# install jbake
apt-get -y install unzip
wget https://dl.bintray.com/jbake/binary/jbake-2.6.0-bin.zip
unzip jbake-*.zip
mv jbake-2.6.0-bin /opt/jbake

chmod +x /opt/jbake/bin/jbake
ln -s /opt/jbake/bin/jbake /usr/local/bin

# create sample project
mkdir project
cd project
jbake -i
mkdir -p /home/vagrant/project/content/blog/2017

cat << EOF > /home/vagrant/project/content/blog/2017/test.md
title=テスト記事
date=2017-11-23
type=post
tags=test,jbake
status=published
~~~~~~

* example1
テストです。
EOF
jbake -b
chown -R vagrant:vagrant /home/vagrant/project

echo 'execute command below and and access http://192.168.55.104:8000/'
echo 'cd project/output'
#echo 'jbake -s'
echo 'python -m SimpleHTTPServer'

SHELL
end