centOS 布置jupyter notebook环境
<h1><span style="font-size: 18px; color: rgba(51, 102, 255, 1)">step1:安装</span></h1><p><span style="font-size: 16px">首先检查本地环境:</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px"># pip3 --<span style="color: rgba(0, 0, 0, 1)">version
pip </span><span style="color: rgba(128, 0, 128, 1)">19.1</span>.<span style="color: rgba(128, 0, 128, 1)">1</span> <span style="color: rgba(0, 0, 255, 1)">from</span> /usr/local/python3/lib/python3.<span style="color: rgba(128, 0, 128, 1)">6</span>/site-packages/pip (python <span style="color: rgba(128, 0, 128, 1)">3.6</span>)</span></pre>
</div>
<p><span style="font-size: 16px">升级PIP至最新版本</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px"># pip3 install --upgrade pip</span></pre>
</div>
<p><span style="font-size: 16px">使用yum -y groupinstall "Development Tools"安装多种开发者工具</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">yum -y groupinstall <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">Development Tools</span><span style="color: rgba(128, 0, 0, 1)">"</span></span></pre>
</div>
<p><span style="font-size: 16px"> 新建虚拟环境</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">mkvirtualenv pd_test</span></pre>
</div>
<p><span style="font-size: 16px">安装jupyter notebook</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">pip3 install jupyter Notebook</span></pre>
</div>
<p> </p>
<p><strong><span style="font-size: 18px; color: rgba(51, 102, 255, 1)">step2:配置 </span></strong></p>
<h1><span style="font-size: 16px">在/user/local/目录下创建一个jupyter文件夹,用来存放Jupyter notebook文件</span></h1>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">cd /usr/<span style="color: rgba(0, 0, 0, 1)">local
mkdir jupyter</span></span></pre>
</div>
<p><span style="font-size: 16px">生成配置文件</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">(pd_test) # jupyter notebook --generate-<span style="color: rgba(0, 0, 0, 1)">config
Writing </span><span style="color: rgba(0, 0, 255, 1)">default</span> config to:<strong> /root/.jupyter/jupyter_notebook_config.py</strong></span></pre>
</div>
<p><span style="font-size: 16px">以上将会在 ~/.jupyter/ 下创建默认config 文件: jupyter_notebook_config.py</span><br><span style="font-size: 16px">修改这个 py 文件</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">c.NotebookApp.port = <span style="color: rgba(128, 0, 128, 1)">8080</span><span style="color: rgba(0, 0, 0, 1)">
c.NotebookApp.ip </span>= <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">你的服务器公网IP</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">
c.NotebookApp.open_browser </span>= False</span><br><span style="font-size: 16px">c.NotebookApp.notebook_dir = <span style="color: rgba(183, 0, 0, 1)">'你的jupyter文件存放位置'</span></span></pre>
</div>
<p><span style="font-size: 16px"><img src="https://img2020.cnblogs.com/blog/1219668/202005/1219668-20200526063844945-1130790275.png"></span></p>
<p><span style="font-size: 16px"> </span></p>
<p><span style="font-size: 16px"> <img src="https://img2020.cnblogs.com/blog/1219668/202005/1219668-20200526064042016-1993744797.png"></span></p>
<p><span style="font-size: 16px"> <img src="https://img2020.cnblogs.com/blog/1219668/202005/1219668-20200526064918700-163432957.png"></span></p>
<p><span style="font-size: 16px">保存配置文件</span></p>
<h1> </h1>
<h1><span style="font-size: 16px">设置登录密码</span></h1>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">(pd_test) #<strong> jupyter notebook password</strong>
Enter password:
Verify password:
<strong>Wrote hashed password to </strong></span><strong>/root/.jupyter/jupyter_notebook_config.json</strong></span></pre>
</div>
<h1> </h1>
<h1><span style="font-size: 16px; color: rgba(51, 102, 255, 1)">step3:在服务器手动 启动 notebook</span></h1>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">jupyter notebook --ip=<span style="color: rgba(128, 0, 128, 1)">0.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.0</span> --no-browser --allow-root</span></pre>
</div>
<p><span style="font-size: 16px"> 出现如下信息说明安装成功(注意先激活 安装了jupyter的虚拟环境 再运行)</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">(pd_test) # jupyter notebook --ip=<span style="color: rgba(128, 0, 128, 1)">0.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.0</span> --no-browser --allow-<span style="color: rgba(0, 0, 0, 1)">root
把notebook 服务cookie密码写入 /root/.local/share/jupyter/runtime/<span style="color: rgba(0, 0, 0, 1)">notebook_cookie_secret
启动notebooks 在本地路径: /usr/local/<span style="color: rgba(0, 0, 0, 1)">jupyter
本程序运行在: http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">67.59.247.60.static.bjtelecom.net:8888/</span>
使用control-c停止此服务器并关闭所有内核(两次跳过确认).</span></pre>
</div>
<p><span style="font-size: 16px">打开浏览器,输入CentOS所在服务器的ip和端口号,输入密码,即可进入</span></p>
<p><span style="font-size: 16px"><img src="https://img2020.cnblogs.com/blog/1219668/202005/1219668-20200526065859915-1118256063.png"></span></p>
<p><span style="font-size: 16px"> </span></p>
<p><span style="font-size: 16px"> 输入配置的密码,就登录进来了</span></p>
<p><span style="font-size: 16px"><img src="https://img2020.cnblogs.com/blog/1219668/202005/1219668-20200526070012371-72706213.png"></span></p>
<h1><span style="font-size: 16px; color: rgba(51, 102, 255, 1)"> step4:通过supervisord管理jupyter进程</span></h1>
<p><span style="font-size: 16px">使用step3的方式虽然可以访问服务器的jupyter,但是只要一关闭启动jupyter的终端窗口,jupyter就会关掉。</span></p>
<p><span style="font-size: 16px">如果希望Jupyter长久运行,可以使用supervisord管理jupyter进程后台运行(或者nohup命令)。</span></p>
<p><span style="font-size: 16px">没有安装过supervisord需要先安装,我这里已经安装过了,所以直接查看一下supervisord.conf现在的所在目录</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px"># find / -<span style="color: rgba(0, 0, 0, 1)">name supervisord.conf
</span>/etc/supervisord.conf</span></pre>
</div>
<p><span style="font-size: 16px">查看配置文件:</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">cat /etc/supervisord.conf</span></pre>
</div>
<div>
<p><span style="font-size: 16px"> 进入 cd /etc 目录 找到supervisord.conf 配置文件 和 supervisord.d 文件夹,使用vim编辑supervisord.conf文件,拉到最底部我们可以看到</span></p>
</div>
<div><span style="font-size: 16px"><img src="https://images2017.cnblogs.com/blog/852411/201801/852411-20180104210554831-681966879.png"></span></div>
<h1><span style="font-size: 16px"><strong> </strong><strong><span class="cnblogs_code">files = supervisord.d/*.ini 这句代码说明它会加载supervisord.d文件夹中的所有.ini配置文件</span></strong></span></h1>
<p><span style="font-size: 16px">在supervisord.d文件夹下新建文件jupyter.ini:</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">nano jupyter.ini</span></pre>
</div>
<p><span style="font-size: 16px">文件内容如下:</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px"><span style="color: rgba(0, 0, 0, 1)">
command</span>=<strong>/root/.virtualenvs/pd_test/bin/jupyter</strong> notebook --ip=<span style="color: rgba(128, 0, 128, 1)">0.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.0</span> --no-browser --allow-<span style="color: rgba(0, 0, 0, 1)">root ; supervisor启动命令,注意前面加上jupyter所在的python环境
directory</span>=/usr/local/jupyter/<span style="color: rgba(0, 0, 0, 1)"> ; 项目的文件夹路径
startsecs</span>=<span style="color: rgba(128, 0, 128, 1)">10</span><span style="color: rgba(0, 0, 0, 1)"> ; 启动时间
stopwaitsecs</span>=<span style="color: rgba(128, 0, 128, 1)">60</span><span style="color: rgba(0, 0, 0, 1)"> ; 终止等待时间
autostart</span>=<span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)"> ; 是否自动启动
autorestart</span>=<span style="color: rgba(0, 0, 255, 1)">true</span><span style="color: rgba(0, 0, 0, 1)"> ; 是否自动重启
stdout_logfile</span>=/usr/local/jupyter/logs/<span style="color: rgba(0, 0, 0, 1)">log.log ; log 日志 <strong>注意先在jupyter文件夹下新建好logs目录</strong>
stderr_logfile</span>=/usr/local/jupyter/logs/log.err ; 错误日志</span></pre>
</div>
<p><span style="font-size: 16px">保存文件:</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px"># ls
gotest.ini<strong>jupyter.ini</strong></span></span></pre>
</div>
<p><span style="font-size: 16px">配置完成后,重新加载supervisor服务</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px"># supervisorctl reload
Restarted supervisord</span></span></pre>
</div>
<p><span style="font-size: 16px">启动所有服务:</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">supervisorctl start all</span></pre>
</div>
<p><span style="font-size: 16px">或者:</span></p>
<div class="cnblogs_code">
<pre><span style="font-size: 16px">supervisord -c /etc/supervisord.conf</span></pre>
</div>
<p><span style="font-size: 16px">接下来就可以访问服务器上的jupyter了</span></p>
<p><span style="font-size: 16px"><img alt="" data-src="https://img2020.cnblogs.com/blog/1219668/202005/1219668-20200526091534608-946778833.png"></span></p>
<p><span style="font-size: 16px"> </span></p>
<p><span style="font-size: 16px"> 参考文档:</span></p>
<h1 class="title-article"><span style="font-size: 16px">centos7搭建Jupyter Notebook</span></h1>
<h1 class="title-article"><span style="font-size: 16px">在 Centos7 上搭建 Jupyter Notebook 环境</span></h1>
<h1 class="kratos-entry-title text-center"><span style="font-size: 16px">利用Jupyter在linux部署个人云笔记</span></h1>
<h1 class="postTitle"><span style="font-size: 16px">【Centos7】 中使用Supervisor守护进程</span></h1><br><br>
来源:https://www.cnblogs.com/kaerxifa/p/12963049.html
頁:
[1]