ラベル RethinkDB の投稿を表示しています。 すべての投稿を表示
ラベル RethinkDB の投稿を表示しています。 すべての投稿を表示

2018年7月21日土曜日

PortainerでJupyter LabとRethinkDBのスタックを作成する

Jupyter Notebookでインタラクティブなコンピューティング環境を提供する事ができます。Portainerで簡単にwebブラウザからJupyter LabとRethinkDBのスタックを作成する事ができます。

○Jupyter Labの画面


〇構築方法
1.Portainer画面横のImagesをクリックして、Image list画面からBuild a new imageボタンをクリック


2.Build image画面nameフィールドにmyjupyter-rethinkdbを入力

3.Web editorのテキストエリアに以下を貼り付け
FROM jupyter/scipy-notebook
ENV TZ=Asia/Tokyo
USER root
RUN pip install rethinkdb
USER $NB_UID



貼り付け後、build the image ボタンをクリックします。

4.画面横のStacksをクリック後、Stacks list画面でAdd a stackボタンをクリックします


5.Create stack画面で、Nameフィールドにjupyterlab-rethinkdb-stackを入力し、Web editorに以下を張り付ける
version: "3"
services:
  myjupyter:
    image: myjupyter-rethinkdb
    container_name: "myjupyter-rethinkdb"
    volumes:
      - "myjupyter-data:/home/jovyan/work"
    ports:
      - "8888:8888"
    environment:
      JUPYTER_TOKEN: jupyter
      JUPYTER_ENABLE_LAB: 1
    depends_on:
      - db
  db:
    image: rethinkdb:2.3.6
    container_name: "rethinkdb"
    volumes:
      - "rethinkdb-data:/data"
    ports:
      - "6379:6379"
volumes:
  rethinkdb-data:
    driver: local
  myjupyter-data:
    driver: local



貼り付け後、deploy stackボタンをクリックします。

6.ブラウザから以下のURLにアクセス
http://<Dockerホスト名またはIP>:8888/?token=jupyter

〇動作検証用コード
import rethinkdb as r

r.connect('db', 28015).repl()
r.db("test").table_create("messages").run()
r.db("test").table("messages").insert({"message_id":"100", "message":"hello world!"}).run()

cursor = r.db('test').table("messages").run()

for document in cursor:
    print(document)


○関連情報
・RethinkDBに関する他の記事はこちらを参照してください。

・Portainerに関する他の記事はこちらを参照してください。

2018年3月18日日曜日

VagrantでJupyter LabとRethinkDBをインストールした仮想マシン(Ubuntu16.04)を構築する

Jupyter Labでインタラクティブなコンピューティング環境を提供する事ができます。
以下のVagrantfileで、Jupyter LabとRethinkDBをインストールした仮想マシン(Ubuntu16.04)を構築できます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.hostname = "ub1604jupyterlabrethinkdb"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1604jupyterlabrethinkdb"
     vbox.cpus = 2
     vbox.memory = 2048
     vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
config.vm.network "private_network", ip: "192.168.55.101", :netmask => "255.255.255.0"
config.vm.network "public_network", ip:"192.168.1.101", :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 rethinkdb
echo "deb http://download.rethinkdb.com/apt xenial main" >> /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
apt-get update
apt-get -y install rethinkdb

cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf

mkdir -p /opt/rethinkdb
cd /opt/rethinkdb
rethinkdb create -d "rethinkdb_data"
chown -R rethinkdb:rethinkdb /opt/rethinkdb
cat << EOF >>  /etc/rethinkdb/instances.d/instance1.conf
runuser=rethinkdb
rungroup=rethinkdb
directory=/opt/rethinkdb/rethinkdb_data
bind=all
driver-port=28015
cluster-port=29015
http-port=8888
server-name=ub1604rethinkdb
EOF
touch /var/log/rethinkdb
chown rethinkdb:rethinkdb /var/log/rethinkdb

/etc/init.d/rethinkdb restart


# install anaconda & jupyterlab
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
pip install jupyterlab

# install rethinkdb driver
pip install rethinkdb
python << EOF
import rethinkdb as r
r.connect('localhost', 28015).repl()
r.db_create('test').run()
r.db('test').table_create('messages').run()
r.table('messages').insert({ 'message': 'hello world!' }).run()
EOF

useradd py
mkdir -p /home/py
chown -R py:py /home/py
sudo -u py bash -c "mkdir /home/py/.jupyter"
sudo -u py bash -c "cat << EOF > /home/py/.jupyter/jupyter_notebook_config.py
conf = get_config()
conf.NotebookApp.ip = '*'
conf.NotebookApp.open_browser = False
conf.NotebookApp.port = 8080
conf.NotebookApp.token = 'jupyter'
EOF"

cat << EOF > /etc/systemd/system/jupyter.service
[Unit]
Description=Jupyter notebook
[Service]
Type=simple
ExecStartPre=source /opt/anaconda/bin/activate
ExecStart=/opt/anaconda/bin/jupyter lab
User=py
Group=py
WorkingDirectory=/home/py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl enable jupyter
sudo systemctl start jupyter

echo 'access -> http://192.168.55.101:8080/?token=jupyter'

SHELL
end

〇動作確認用コード
import rethinkdb as r
r.connect('localhost', 28015).repl()

cursor = r.db('test').table("messages").run()
for document in cursor:
    print(document)

〇Jupyter Labの画面


○関連情報
・RethinkDBに関する他の記事はこちらを参照してください。

2018年2月16日金曜日

VagrantでRethinkDBをインストールした仮想マシン(ubuntu16.04)を構築する

RethinkDBはオープンソースのドキュメント指向データベースです。
以下のVagrantfileを使用して、RethinkDBがインストールされた仮想マシン(Ubuntu16.04)を構築する事ができます。

Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.hostname = "ub1604rethinkdb"
  config.vm.provider :virtualbox do |vbox|
     vbox.name = "ub1604rethinkdb"
     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
sed -i.bak -e "s#http://archive.ubuntu.com/ubuntu/#http://ftp.riken.jp/pub/Linux/ubuntu/#g" /etc/apt/sources.list
apt-get update
apt-get -y install language-pack-ja
localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP:ja"
localectl set-keymap jp106
#DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade

# install rethinkdb
echo "deb http://download.rethinkdb.com/apt xenial main" >> /etc/apt/sources.list.d/rethinkdb.list
wget -qO- https://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add -
apt-get update
apt-get -y install rethinkdb

cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf

mkdir -p /opt/rethinkdb
cd /opt/rethinkdb
rethinkdb create -d "rethinkdb_data"
chown -R rethinkdb:rethinkdb /opt/rethinkdb
cat << EOF >>  /etc/rethinkdb/instances.d/instance1.conf
runuser=rethinkdb
rungroup=rethinkdb
directory=/opt/rethinkdb/rethinkdb_data
bind=all
driver-port=28015
cluster-port=29015
http-port=8080
server-name=ub1604rethinkdb
EOF
touch /var/log/rethinkdb
chown rethinkdb:rethinkdb /var/log/rethinkdb

/etc/init.d/rethinkdb restart

echo 'access http://192.168.55.107:8080/'
SHELL
end

〇管理コンソールの画面


○関連情報
・RethinkDBに関する他の記事はこちらを参照してください。

2017年10月20日金曜日

VagrantでRethinkDBをインストールした仮想マシン(CentOS7.4)を構築する

以下のVagrantfileを使用して、RethinkDBをインストールした仮想マシンを構築することができます。
仮想マシンを構築後、http://192.168.55.116:8080/でダッシュボードにアクセスできます。

Vagratfile
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "bento/centos-7.4"
  config.vm.hostname = "co74rethinkdb"
  config.vm.network :public_network, ip:"192.168.1.116"
  config.vm.network "private_network", ip: "192.168.55.116", :netmask => "255.255.255.0"
  config.vm.provider :virtualbox do |vbox|
    vbox.name = "co74rethinkdb"
    vbox.cpus = 4
    vbox.memory = 4096
    vbox.customize ["modifyvm", :id, "--nicpromisc2","allow-all"]
  end
  config.vm.provision "shell", inline: <<-SHELL
wget http://download.rethinkdb.com/centos/7/`uname -m`/rethinkdb.repo -O /etc/yum.repos.d/rethinkdb.repo
yum update
yum -y install rethinkdb

cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf

mkdir -p /opt/rethinkdb
cd /opt/rethinkdb
rethinkdb create -d "rethinkdb_data"
chown -R rethinkdb:rethinkdb /opt/rethinkdb

cat << EOF > /etc/systemd/system/rethinkdb.service
[Unit]
Description=RethinkDB database server'

[Service]
User=rethinkdb
Group=rethinkdb
ExecStart=/usr/bin/rethinkdb serve --config-file /etc/rethinkdb/instances.d/instance1.conf --bind all
WorkingDirectory=/opt/rethinkdb
KillMode=process
PrivateTmp=true

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

SHELL
end

RethinkDBのダッシュボード画面


○関連情報
・RethinkDBに関する他の記事はこちらを参照してください。