在Centos上搭建jupyter服務

  • 初衷

          方便在服務器上跑一些python爬蟲腳本

  • 環境準備

          Centos × 64 服務器

  • 開始

          由於Centos預裝的是2.×版本的python,而jupyter需要3.4以上的python版本,所以需要再安裝python3.4或以上的版本。(注意不要將之前2.×版本的python刪掉,否則會出現系統異常)

要安裝python3,首先要安裝一系列安裝包。

yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel 

然後去python官網上下載python3的安裝包,具體版本按自己的需求來

wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz

然後在下創建一個空的文件夾用來當做安裝目錄

mkdir /usr/local/python3 

之後解壓下載的安裝包,進入該文件夾進行安裝

tar -xvJf  Python-3.6.2.tar.xz
cd Python-3.6.2
./configure --prefix=/usr/local/python3
make && make install

最後創建軟連接用來在任意目錄下使用python3 命令

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

至此,python3安裝完畢。

接下來進行jupyter安裝:

  1.  安裝jupyter
pip3 install  jupyter  

     2.  生成配置文件

jupyter notebook --generate-config --allow-root

配置文件生成在:~/.jupyter/jupyter_notebook_config.py

    3.  生成密碼

jupyter notebook password

    4.  修改配置文件

# 設置監聽地址,一般改爲當前主機的ip
sed -ie "s/#c.NotebookApp.ip = 'localhost'/c.NotebookApp.ip = '0.0.0.0'/g" ~/.jupyter/jupyter_notebook_config.py
# 設置監聽端口
sed -ie 's/#c.NotebookApp.port = 8888/c.NotebookApp.port = 8000/g' ~/.jupyter/jupyter_notebook_config.py
# 禁用自動打開瀏覽器
sed -ie 's/#c.NotebookApp.open_browser = True/c.NotebookApp.open_browser = False/g' ~/.jupyter/jupyter_notebook_config.py

    5.  啓動jupyter

jupyter notebook --allow-root

6.  訪問

        在訪問前,檢查防火牆規則是否允許8000(自己設置的jupyter端口)是否允許被訪問。

        在瀏覽器地址欄輸入服務器的地址和端口。

        進入登錄頁面後,用剛剛設置的密碼登錄。

 

配置完成。開心的玩耍吧!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章