To content | To menu | To search

IPython Notebook

面白そうだったのでセットアップしてみた。

FreeBSD なら

# pkg install devel/ipython

で一発。
ローカルで動かすなら

$ ipython notebook

でいいけれど、サーバーで動かしたいとき。

# ipython notebook --no-browser --port=80 --ip=xxx.xxx.xxx.xxx

ポート 80 はルート権限でないと使わせてくれない?あと Listen するアドレスの指定が必要だった。
さすがにこのまま外には公開できないのでもう少しセットアップ。

必要なことは全て

$ ipython help notebook --help-all

ここから。

とりあえず TLS 対応してみたい。ひとまず勝手証明書で。ディレクトリは適当。

# mkdir /usr/local/etc/cert
# cd /usr/local/etc/cert/
root@freebsd:/usr/local/etc/cert # openssl genrsa -des3 -out server.key 1024
Generating RSA private key, 1024 bit long modulus
......++++++
...........................................................++++++
e is 65537 (0x10001)
Enter pass phrase for server.key:
Verifying - Enter pass phrase for server.key:
root@freebsd:/usr/local/etc/cert # openssl req -new -days 365 -key server.key -out server.csr
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]: **
State or Province Name (full name) [Some-State]: *****
Locality Name (eg, city) []:*****
Organization Name (eg, company) [Internet Widgits Pty Ltd]:*****
Organizational Unit Name (eg, section) []:*****
Common Name (e.g. server FQDN or YOUR name) []:*****.example.jp
Email Address []:*****@example.jp

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
root@freebsd:/usr/local/etc/cert #
root@freebsd:/usr/local/etc/cert # openssl x509 -req -signkey server.key -days 365 -in server.csr -out server.crt
Signature ok
subject=/C=**/ST=*****/L=*****/O=*****/OU=*****/CN=*****.example.jp/emailAddress=*****@example.jp
Getting Private key
Enter pass phrase for server.key:
root@freebsd:/usr/local/etc/cert # mv server.key server.key.bak
root@freebsd:/usr/local/etc/cert # openssl rsa -in server.key.bak -out server.key
Enter pass phrase for server.key.bak:
writing RSA key
root@freebsd:/usr/local/etc/cert # ls
server.crt      server.csr      server.key      server.key.bak

(この鍵の作り方は古いかもしれない)
として関連ファイルを作ったあとで、

# ipython notebook --no-browser --port=443 --ip=***.example.jp --NotebookApp.certfile=/usr/local/etc/cert/server.crt --NotebookApp.keyfile=/usr/local/etc/cert/server.key

とすると https://***.example.jp/ で TLS 接続。

IPython のためのディレクトリも作っておこう。

# mkdir /home/ipython
# mkdir /home/ipython/.ipython
# mkdir /home/ipython/notebook

あとは、開きっぱなしっていうのもいやなので、パスワードを設定したい。

$ ipython
Python 2.7.9 (default, Jun 12 2015, 19:23:08)
Type "copyright", "credits" or "license" for more information.

IPython 3.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from IPython.lib import passwd; passwd()
Enter password:
Verify password:
Out[1]: 'sha1:****************************************************************'

In [2]: exit

というわけで全部設定。ロギングも入れた。

# ipython notebook --no-browser --port=443 --ip=*****.example.jp --NotebookApp.certfile=/usr/local/etc/cert/server.crt --NotebookApp.keyfile=/usr/local/etc/cert/server.key --NotebookApp.password='sha1:****************************************************************' --ipython-dir=/home/ipython/.ipython --notebook-dir=/home/ipython/notebook --log-level=WARN

ログインのときユーザー名は無いので、共用には向かないみたい。

あとこのままではルート権限で動いているので、起動しっぱなし、というのは怖い。

Add a comment

HTML code is displayed as text and web addresses are automatically converted.

They posted on the same topic

Trackback URL : https://www.pseudomoon.jp/dotclear/index.php?trackback/43

This post's comments feed