まずはじめに

LGTM 乞食なのでよろしくお願いします¥( ˘ω˘ )スヤア

この目的

だいぶつまづいてしまったので覚書として?‍

基本情報

[root@jupyter01 ~]# cat /etc/centos-release
CentOS Linux release 7.7.1908 (Core)

[root@jupyter01 ~]# jupyter --version
4.4.0

jupyter_notebook_config.pyの設定

    • ポイント

c.NotebookApp.allow_root = Trueでrootユーザーでも起動できるように

c.NotebookApp.ip = ‘0.0.0.0’でlocalhost以外からもアクセスできるように

c.IPKernelApp.pylab = ‘inline’でグラフ表示をインタラクティブコンソールで表示できるように

c = get_config()
c.NotebookApp.allow_root = True # rootでも起動できるように
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.password = u'sha1:833fdc2d2783:1c4db1bf9540710fe6a49c00ffb51829271ff89e'
c.NotebookApp.notebook_dir = '/root/jupyter_files/'
c.IPKernelApp.pylab = 'inline'

systemdの設定

    • ポイント

ExecStartで起動コマンドが置かれているPATHを設定、

–configでjupyter_notebook_config.pyの置かれているパスを指定(これがないと設定した.pyのconfigファイルが読み込まれず設定が反映されない=起動できない)

Restart=alwaysでプロセスが落ちたら自動起動するように設定

[Unit]
Description = Jupyter Notebook

[Service]
Type=simple
ExecStart= /root/anaconda3/bin/jupyter notebook --config=/root/.jupyter/jupyter_notebook_config.py
Restart=always

[Install]
WantedBy = multi-user.target

サービスとしての起動、起動確認、自動起動

# serviceを作ったのでdaemonをリロード
[root@jupyter01 ~]# systemctl daemon-reload

# 作成したservice名を起動
[root@jupyter01 ~]# systemctl start notebook

# サーバー起動とともに自動起動するように設定
[root@jupyter01 ~]# systemctl enable notebook

# ステータス確認
[root@jupyter01 ~]# systemctl status notebook
● notebook.service - Jupyter Notebook
   Loaded: loaded (/etc/systemd/system/notebook.service; enabled; vendor preset: disabled)
   Active: active (running) since 木 2020-02-06 15:54:12 CST; 1s ago
 Main PID: 1297 (jupyter-noteboo)
   CGroup: /system.slice/notebook.service
           └─1297 /root/anaconda3/bin/python /root/anaconda3/bin/jupyter-notebook --config=/root/.jupyter/jupyter_notebook_config.py

 2月 06 15:54:12 jupyter01 systemd[1]: Started Jupyter Notebook.
 2月 06 15:54:13 jupyter01 jupyter[1297]: [I 15:54:13.002 NotebookApp] JupyterLab extension loaded from /root/anaconda3/lib/python3.7/site-packages/jupyterlab
 2月 06 15:54:13 jupyter01 jupyter[1297]: [I 15:54:13.002 NotebookApp] JupyterLab application directory is /root/anaconda3/share/jupyter/lab
 2月 06 15:54:13 jupyter01 jupyter[1297]: [I 15:54:13.004 NotebookApp] Serving notebooks from local directory: /root/jupyter_files
 2月 06 15:54:13 jupyter01 jupyter[1297]: [I 15:54:13.004 NotebookApp] The Jupyter Notebook is running at:
 2月 06 15:54:13 jupyter01 jupyter[1297]: [I 15:54:13.004 NotebookApp] http://(jupyter01 or 127.0.0.1):8888/
 2月 06 15:54:13 jupyter01 jupyter[1297]: [I 15:54:13.004 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

ちゃんとプロセスが起動してました

[root@jupyter01 ~]# ps aux | grep jupyter
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      1297  0.3  0.6 210424 53808 ?        Ss   15:54   0:00 /root/anaconda3/bin/python /root/anaconda3/bin/jupyter-notebook --config=/root/.jupyter/jupyter_notebook_config.py
广告
将在 10 秒后关闭
bannerAds