本文共 3033 字,大约阅读时间需要 10 分钟。
1.1、安装python3.6
参考:https://blog.csdn.net/kyle0349/article/details/98474013编译安装前一定要yum 安装一些linux相关的依赖。
1.2、安装jupyter
安装完后, jupyter并没有配置到环境变量中,也就是不能直接在命令行使用jupyter,可以在python安装目录bin下面找到,然后创建一个软连接
[root@cdh01 ~]# pip3 install jupyter[root@cdh01 python36]# ln -s /usr/local/python36/bin/jupyter /usr/bin/jupyter[root@cdh01 python36]# ln -s /usr/local/python36/bin/jupyter-notebook /usr/bin/jupyter-notebook[root@cdh01 python36]# jupyterusage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir] [--paths] [--json] [subcommand]jupyter: error: one of the arguments --version subcommand --config-dir --data-dir --runtime-dir --paths is required
进入python3命令行,import jupyter 的notebook passwd方法
让你两次输入密码,自动生成秘钥, 记住密钥,后续用到
[root@cdh01 ~]# python3Python 3.6.9 (default, Aug 25 2019, 12:13:26) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> from notebook.auth import passwd>>> passwd()Enter password: Verify password: 'sha1:4q1qwefwed22asdadjhgfsdaasddadsqeaafadadadec688'>>>
如下,使用 jupyter notebook --generate-config 会在root用户目录下创建一个jupyter的配置文件【jupyter_notebook_config.py】
[root@cdh01 python36]# bin/jupyter notebook --generate-configWriting default config to: /root/.jupyter/jupyter_notebook_config.py
常见修改以下几个属性
# 设置所有ip皆可访问,默认只能本地可以访问。#c.NotebookApp.ip = 'localhost'c.NotebookApp.ip='0.0.0.0' # 这里使用上面设置的密钥#c.NotebookApp.password = ''c.NotebookApp.password = 'sha1:4q1qwefwed22asdadjhgfsdaasddadsqeaafadadadec688' # 在linux上安装,把自动打开浏览器关闭#c.NotebookApp.open_browser = Truec.NotebookApp.open_browser = False #指定一个端口 默认c.NotebookApp.port = 8888# 指定工作目录,新建的文件都会保存到这个目录下 #c.NotebookApp.notebook_dir = '' c.NotebookApp.notebook_dir = '/opt/jupyter/notebook'
正常启动
[root@cdh01 python36]# jupyter notebook --allow-root[I 13:15:05.748 NotebookApp] 把notebook 服务cookie密码写入 /root/.local/share/jupyter/runtime/notebook_cookie_secret[I 13:15:06.142 NotebookApp] 端口 8888 已经被站用, 请尝试其他端口.[I 13:15:06.142 NotebookApp] 端口 8889 已经被站用, 请尝试其他端口.[I 13:15:06.149 NotebookApp] 启动notebooks 在本地路径: /opt/jupyter/notebook[I 13:15:06.149 NotebookApp] 本程序运行在: http://cdh01:8890/[I 13:15:06.149 NotebookApp] 使用control-c停止此服务器并关闭所有内核(两次跳过确认).^C[I 13:15:31.240 NotebookApp] 中断启动notebooks 在本地路径: /opt/jupyter/notebook0 活跃的服务本程序运行在: http://cdh01:8890/关闭服务 (y/[n])y[C 13:15:32.470 NotebookApp] 关闭确定[I 13:15:32.471 NotebookApp] 关闭 0 服务
后台运行
[root@cdh01 python36]# nohup jupyter notebook --allow-root >> /opt/jupyter/logs/notebook.log &[1] 59807[root@cdh01 python36]# nohup: 忽略输入重定向错误到标准输出端[root@cdh01 python36]# [root@cdh01 python36]# [root@cdh01 python36]# ps -ef | grep jupyterroot 59807 57657 13 13:17 pts/2 00:00:01 /usr/local/python36/bin/python3.6 /usr/local/python36/bin/jupyter-notebook --allow-rootroot 59829 57657 0 13:17 pts/2 00:00:00 grep jupyter[root@cdh01 python36]#
用前面自己设置的密码登录 http://192.168.2.100:8888/login