博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
如何在服务器上使用 Tensorflow, Notebook
阅读量:6956 次
发布时间:2019-06-27

本文共 2487 字,大约阅读时间需要 8 分钟。

多数情况下我们都是在本地使用 Anaconda 来安装 tensorflow, notebook 做深度学习, 数据分析.

但有时还是有需要在服务器上处理这些事, 比如 macbook 空间又双叕不够啦, 公司的数据不方便走外网啦, 数据导来导去非常麻烦啦, 还不如直接在服务器上跑 notebook 分析数据.

好, 不废话了, 直接上

1. 安装 conda

Anaconda 其实也是用的 conda 来安装 package, 所以我们直接用conda 就行了. 下面就以 Ubuntu 环境下安装 conda:

# Install our public gpg key to trusted storecurl https://repo.anaconda.com/pkgs/misc/gpgkeys/anaconda.asc | gpg --dearmor > /tmp/conda.gpginstall -o root -g root -m 644 /tmp/conda.gpg /etc/apt/trusted.gpg.d/# Add our debian repoecho "deb [arch=amd64] https://repo.anaconda.com/pkgs/misc/debrepo/conda stable main" > /etc/apt/sources.list.d/conda.listapt-get updateapt-get install conda复制代码

2. 常用的 conda 命令

# 把 conda 加入环境变量, 你也可以在 ~/.bash_profile 里加入一行 export PATH> source /opt/conda/etc/profile.d/conda.sh# 验证 conda 命令是否正常> conda -Vconda 4.5.11# 更新一下 conda> conda update conda# 创建一个 conda 环境conda create --name 
# 查看当前有哪些环境conda info --envs# 激活环境conda activate
# 在这个环境下安装库conda install
# 列出当前环境下安装的库conda list# 删除环境下的库conda remove
# 退出环境conda deactivate复制代码

3. conda 安装 tf, notebook

下面的例子创建了一个叫 tf 的 conda 环境, 然后安装 tf, notebook.

conda create --name tfconda activate tfconda install tensorflow jupyter notebook复制代码

4. 启动 notebook

在这个环境下启动 notebook, 指定ip, port. 端口避开了常用的 8080.

jupyter notebook --ip=127.0.0.1 --port=10082 --allow-root复制代码

启动时留意一下 token, 一会访问 notebook 时要用到.

5. 配置 nginx

通过 nginx 把 test.notebook.domain.com 的请求打到第4步的 notebook 的端口.

因为 notebook 还用了 websocket, nginx需要支持.

map $http_upgrade $connection_upgrade {    default upgrade;    ''      close;}server {  server_name test.notebook.domain.com;  listen 80;  location / {    proxy_pass            http://127.0.0.1:10082;    proxy_set_header      Host $host;    proxy_http_version    1.1;    proxy_set_header      Upgrade $http_upgrade;    proxy_set_header      Connection $connection_upgrade;  }}复制代码

6. 热启动 nginx

nginx -s reload复制代码

7. 修改本地 hosts

nginx 里配置的域名 test.notebook.domain.com 不需要做域名解析, 我们修改一下本地hosts 就好.

[云服务器ip] test.notebook.domain.com复制代码

8. 访问 notebook

打开浏览器, 访问 test.notebook.domain.com 这时熟悉的 notebook 界面出来了.

9. 添加 notebook 配置

这时虽然能访问了, 但创建新的 notebook 脚本时会报错, 原因是请求跨域了. 要解决这个问题虽然可以按跨域请求思路找办法, 但 jupyter 已经可以通过配置来解决, 还能去掉token.

touch ~/.jupyter/jupyter_notebook_config.py复制代码

添加4行

c.NotebookApp.ip = '0.0.0.0'c.NotebookApp.token = ''c.NotebookApp.allow_origin = '*'c.NotebookApp.disable_check_xsrf = True复制代码

这里再重新启动 notebook 就可以正常创建了.

有兴趣的同学可以把这些步骤做成 ansible playbook, 就不用每次都弄一遍了.

转载地址:http://wzxil.baihongyu.com/

你可能感兴趣的文章
XenApp_XenDesktop_7.6实战篇之十五:StoreFront的配置
查看>>
Tablespace Report
查看>>
hibernate映射插件
查看>>
Syngress.Nmap.in.the.Enterprise.Your.Guide.to.Network.Scanning
查看>>
小学生都能看懂的表达式计算(图解)
查看>>
物联网有没有创新的思维模式?如果有,会是什么?
查看>>
微会动微信现场互动:年会策划之用产品思维搞定年会
查看>>
利用STP生成树协议实现负载均衡
查看>>
三层交换
查看>>
学习——精通软件性能测试笔记
查看>>
定制多系统启动菜单
查看>>
给定一个串,去掉连续的重复字母,
查看>>
我的友情链接
查看>>
jenkins+docker的简单项目部署
查看>>
MSR2010配置小记
查看>>
URL参数解析为一个对象
查看>>
微信video标签全屏无法退出bug
查看>>
[转]PostgreSQL 中文资料汇总
查看>>
那些被疯狂追求的女孩,后来怎么样了?
查看>>
(转载)Windows 7 Ultimate(旗舰版)SP1 32/64位官方原版下载(2011年5月12日更新版)...
查看>>