仮想マシンの構築方法
以下のVagrantfileで、Jupyter Labとmonetdbをインストールした仮想マシン(Ubuntu16.04)を構築できます。Vagrantfile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "bento/ubuntu-16.04"
config.vm.hostname = "ub1604jupyterlabmonetdb"
config.vm.provider :virtualbox do |vbox|
vbox.name = "ub1604jupyterlabmonetdb"
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 monetdb
cat << EOF >> /etc/apt/sources.list.d/monetdb.list
deb https://dev.monetdb.org/downloads/deb/ xenial monetdb
deb-src https://dev.monetdb.org/downloads/deb/ xenial monetdb
EOF
wget --output-document=- https://www.monetdb.org/downloads/MonetDB-GPG-KEY | apt-key add -
apt-get update
apt-get -y install monetdb5-sql monetdb-client
chown monetdb:monetdb /var/lib/monetdb
systemctl enable monetdbd
systemctl start monetdbd
/usr/bin/monetdb create testdb
/usr/bin/monetdb start testdb
/usr/bin/monetdb release testdb
cat << EOF > /home/vagrant/.monetdb
user=monetdb
password=monetdb
language=sql
save_history=true
EOF
sudo -u vagrant /usr/bin/mclient -d testdb -s 'create table test1 (message_id integer, message varchar(100))'
sudo -u vagrant /usr/bin/mclient -d testdb -s "insert into test1 values (100, 'hello world\\!')"
sudo -u vagrant /usr/bin/mclient -d testdb -s "select * from test1"
# 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 pymonetdb driver
pip install pymonetdb
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 pymonetdb
con = pymonetdb.connect(username="monetdb", password="monetdb", hostname="localhost", database="testdb")
try:
cur= con.cursor()
sql = "select message_id, message from test1"
cur.execute(sql)
for row in cur.fetchall():
print(row)
except pymonetdb.Error as er:
print('pymonetdb.Error:', er)
cur.close
con.close
〇Jupyter Labの画面
関連情報
・monetdbに関する他の記事はこちらを参照してください。・プロジェクトgithubリポジトリ
https://github.com/MonetDB/MonetDB
0 件のコメント:
コメントを投稿