Linux下Jupyter安装和配置

#一、先决条件
-------------------
1.Jupyter运行需要基于Python环境,此处使用Anaconda管理Python环境

2.Jupyter为了避免遭受攻击,需要使用jupyter用户启动
    useradd jupyter
    passwd jupyter 123456

3.安装anaconda
    3.1 su jupyter

    3.2 wget  https://repo.anaconda.com/archive/Anaconda3-5.1.0-Linux-x86_64.sh

    3.3 bash Anaconda3-5.1.0-Linux-x86_64.sh (按提示安装即可)

    3.4 Please, press ENTER to continue
        >>> ENTER
    
    3.5 Do you accept the license terms? [yes|no]
        [no] >>> yes
    
    3.6 Anaconda3 will now be installed into this location:
        /home/jupyter/anaconda3
        选择当前用户目录下安装,回车
    
    3.7 to PATH in your /home/jupyter/.bashrc ? [yes|no]
        [no] >>> yes
        添加环境变量
    
    3.8 Do you wish to proceed with the installation of Microsoft VSCode? [yes|no]
        >>> no
        不安装VSCODE


4.验证
    4.1 修改/home/${user}/.bashrc,添加如下内容
    # added by Anaconda3 installer
    export PATH="/home/jupyter/anaconda3/bin:$PATH"
    # added by Anaconda3 installer
    export PATH="/home/jupyter/anaconda3/bin:$PATH"

    4.2 Source 当前用户的.bashrc文件

    4.3 执行conda –V,如下表示安装Anaconda成功

    4.4 输入python –V,如下表示python环境完成(使用python3)


#二、安装Jupyter
-------------------
1.安装Jupyter Notebook
conda install jupyter

2.检查是否安装成功

2.检查是否安装成功
conda list | grep jupyter
*********************************************************
[jupyter@master02 ~]$ conda list | grep jupyter
# packages in environment at /home/jupyter/anaconda3:
jupyter                   1.0.0                    py36_4  
jupyter_client            5.2.2                    py36_0  
jupyter_console           5.2.0            py36he59e554_1  
jupyter_core              4.4.0            py36h7c827e3_0  
jupyterlab                0.31.5                   py36_0  
jupyterlab_launcher       0.10.2                   py36_0

3.安装Jupyter Kernel Gateway
conda install -c conda-forge jupyter_kernel_gateway

3.安装Jupyter Kernel Gateway
conda install -c conda-forge jupyter_kernel_gateway

4.检查是否安装成功
conda list | grep jupyter_kernel_gateway
*********************************************************
[jupyter@master02 ~]$ conda list | grep jupyter_kernel_gateway
jupyter_kernel_gateway    2.2.0                      py_0    conda-forge

三、配置Jupyter
-------------------
1.将.Jupyter文件夹放到当前用户下即可完成安装(最新版,从生产上拉下来)

2.包目录介绍
.jupyter/
|--bin (启动、停止脚本)
    |--start-gateway.sh
   |--start-notebook.sh
   |--stop-gateway.sh
|--stop-notebook.sh
|--logs(日志)
|--model(模板)
   |--ml(machine-learning使用模板)
   |--notebook(notebook使用模板)
   |--api_http_mode.ipynb(http_api模板)
|--work(作业目录)
   |ml(machine-learning使用模板)
   |notebook(notebook使用模板)
|--jupyter_kernel_gateway_config.py(kernel_gateway配置)
|--jupyter_notebook_config.py(notebook配置)

3.修改目录权限
#sudo chown -R jupyter:jupyter /run/


4.生成配置文件
jupyter notebook --generate-config

4.修改配置文件jupyter_notebook_config.py
c.NotebookApp.base_project_url = '/'
c.NotebookApp.ip = '*'
c.NotebookApp.notebook_dir = '/home/jupyter/.jupyter/work'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.token = ""
c.NotebookApp.tornado_settings = { 'headers': { 'Content-Security-Policy': "frame-ancestors 'self' *" } }
c.NotebookApp.terminals_enabled = False

5.修改jupyter_kernel_gateway_config.py
c.KernelGatewayApp.allow_methods = '*'
c.KernelGatewayApp.allow_origin = '*'
c.KernelGatewayApp.api = 'kernel_gateway.notebook_http'
c.KernelGatewayApp.ip = '*'
c.KernelGatewayApp.port = 8889


四、启动Jupyter
-------------------
1.Notebook服务
执行bin/ start-notebook.sh

2.Kernel_Gateway服务
执行bin/start-gateway.sh

3.验证
Notebook: http://ip:8888
Gateway: http://ip:8889(此服务是提供Restfull接口服务,无web页面)
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值