CentOS7搭建Python3+JupyterNotebook远程访问环境

2019-03-1710:24:26服务器及运维Comments3,237 views字数 2610阅读模式

一.  配置准备:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

  • Oracle 云服务账号
  • 云主机一台:操作系统 CentOS7
  • Xshell 连接
  • Chrome 浏览器

二.  安装步骤文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

  1.  创建云主机
    • 创建OCI虚拟网络VCN
      新建VCN网络:
      CentOS7搭建Python3+JupyterNotebook远程访问环境配置Security List(打开访问端口即可):
      CentOS7搭建Python3+JupyterNotebook远程访问环境
    • 创建计算实例
      CentOS7搭建Python3+JupyterNotebook远程访问环境CentOS7搭建Python3+JupyterNotebook远程访问环境
    • 通过Xshell连接到此实例
      CentOS7搭建Python3+JupyterNotebook远程访问环境并通过修改配置文件,允许root用户的登录。
  2.  安装Python3
    创建安装目录,下载 Python3.6.5 安装包,并将压缩包解压到对应目录中文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html
    1 mkdir /opt/Python3
    2 cd /opt/Python3/
    3 wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
    4 tar -xvf Python-3.6.5.tgz
    5 ls -l

    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    安装 Python3 依赖包文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    CentOS7搭建Python3+JupyterNotebook远程访问环境
     1 yum -y install zlib zlib-devel
     2 yum -y install bzip2 bzip2-devel
     3 yum -y install ncurses ncurses-devel
     4 yum -y install readline readline-devel
     5 yum -y install openssl openssl-devel
     6 yum -y install openssl-static
     7 yum -y install xz lzma xz-devel
     8 yum -y install sqlite sqlite-devel
     9 yum -y install gdbm gdbm-devel
    10 yum -y install tk tk-devel
    11 yum -y install gcc
    CentOS7搭建Python3+JupyterNotebook远程访问环境

    配置Python安装环境,并编译、安装Python3文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    1 cd Python-3.6.5/
    2 ./configure --with-ssl --prefix=/opt/Python3
    3 make
    4 make install

    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    配置Python3环境变量文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    CentOS7搭建Python3+JupyterNotebook远程访问环境
    1 [root@demo-instance ~]# vim ~/.bash_profile

    # .bash_profile文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    . ~/.bashrc
    fi文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    # User specific environment and startup programs文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    export python=/opt/Python3/bin文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    PATH=$PATH:$HOME/bin:/opt/Python3/bin文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    export PATH文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    CentOS7搭建Python3+JupyterNotebook远程访问环境

    编辑关联文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    1 mv /usr/bin/python /usr/bin/python_bak
    2 ln -s /opt/Python3/bin/python3 /usr/bin/python
    3 ln -s /opt/Python3/bin/python3 /usr/bin/python3

    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    升级pip文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    1 python -m pip install --upgrade pip

    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

     

  3.  安装Jupyter Notebook
    通过pip安装Jupyter Notebook文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html
    1 python3 -m pip install jupyter
    2 ln -s /opt/Python3/bin/jupyter /usr/bin/jupyter

    通过jupyter notebook命令启动Jupyter服务器,查看是否安装成功文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    CentOS7搭建Python3+JupyterNotebook远程访问环境
     1 [root@demo-instance Python-3.6.5]# jupyter notebook --allow-root
     2 [I 09:03:32.473 NotebookApp] Serving notebooks from local directory: /opt/Python3/Python-3.6.5
     3 [I 09:03:32.473 NotebookApp] The Jupyter Notebook is running at:
     4 [I 09:03:32.473 NotebookApp] http://localhost:8888/?token=9fb8cc50c87a1f5a35c2d57d0722dc1c0f58f5be892a6532
     5 [I 09:03:32.473 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
     6 [W 09:03:32.479 NotebookApp] No web browser found: could not locate runnable browser.
     7 [C 09:03:32.479 NotebookApp] 
     8     
     9     To access the notebook, open this file in a browser:
    10         file:///root/.local/share/jupyter/runtime/nbserver-24125-open.html
    11     Or copy and paste one of these URLs:
    12         http://localhost:8888/?token=9fb8cc50c87a1f5a35c2d57d0722dc1c0f58f5be892a6532
    CentOS7搭建Python3+JupyterNotebook远程访问环境

    至此,Jupyter Notebook安装成功。

  4.  配置外部访问
    关闭防火墙(CentOS7)文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html
    1 systemctl stop firewalld.service
    2 systemctl disable firewalld.service

    生成Jupyter Notebook配置文件文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    1 jupyter notebook --generate-config

    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    通过 ipython 创建登录密码:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    编辑生成的配置文件 /root/.jupyter/jupyter_notebook_config.py,并在文件头添加如下配置信息:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    c.NotebookApp.ip='0.0.0.0'  # 就是设置所有ip皆可访问
    c.NotebookApp.password = u'sha1:7b115a66b162:e6bc039abf83eab1947dd9445d9fe408c659e3d2' #前边保存的密码信息
    c.NotebookApp.open_browser = False #禁止自动打开浏览器
    c.NotebookApp.port =8888 #随便指定一个端口,默认为8888

    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    先 reboot 机器,然后使用命令 jupyter nodebook 启动服务器文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    通过浏览器访问地址:http://ipaddress:8888/
    CentOS7搭建Python3+JupyterNotebook远程访问环境文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html

    输入创建的密码,即可登录Jupyter Notebook的工作区:
    CentOS7搭建Python3+JupyterNotebook远程访问环境

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/10063.html
  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/10063.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定