服务器完整搭建jupyter 科学环境服务

目标:

  1. 整个公司同事可以访问到centos 7 服务器上【存在跳板机,需要做内网转发域名】的jupyter,提供对内网的所有机器的http 访问支持
    2.在jupyter 可以使用服务器环境下的python环境【可以是 conda 或者pyenv 环境或者真实python】
    3.jupyter 提供 python R scala spark golang 运行环境

建议参考 :
http://www.qiuqingyu.cn/2017/05/15/%E5%9C%A8%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%AB%AF%E5%8D%87%E7%BA%A7python%E5%B9%B6%E5%AE%89%E8%A3%85Jupyter/

步骤:
1.设置python 环境 ,建议 python 3.6.* ,建议使用conda 的虚拟环境,那就安装 anaconda

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

配置环境变量
修改 conda 下载源 ,使用清华的镜像

  conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  conda config --set show_channel_urls yes
yum install zlib-devel openssl-devel sqlite-devel
conda create  -n mullerenv python=3.6.8 pip
conda activate mullerenv

2.安装jupyter

conda install jupyter 
 ###不要使用 pip 安装 jupyter,否则缺少很多辅助的包

,需要注意的是 提前把【zlib sqilite openssl】整好

3.配置 jupyter 密码登录模式 配置jupyter工作目录 ,ip 和port,后台启动,我是 root 用户启动,当然你使用任意用户都可以

mkdir -p /data/jupyter_doc
jupyter notebook --generate-config
jupyter notebook password ##回车后输入两次密码
ip a # ifconfig  #查看本机ip  
 nohup  jupyter notebook  --ip=172.17.39.134 --port=8888  --allow-root --notebook-dir=/data/jupyter_doc &  ## --ip=0.0.0.0 好像也可以的, port 可以随意,如果没有占用,就使用默认的就可以了

4.配置内网转发域名ip,内网 web http环境可以登录访问,需要对特定端口打开出入
这一项 建议使用Nginx 或者 slb转发 ,建议使用https 安全协议

5 如果需要 可以安装jupyter插件库

安装jupyterlab

目前这个项目还在测试过程中,它的目的是增强jupyter的编辑能力,使jupyter如IDE一般强大。

安装: conda install -c conda-forge jupyterlab 
运行: jupyter lab 

jupyter 查看环境列表 和 内核列表

conda info --envs
jupyter kernelspec list

jupyter 配置代码补全


conda install -c conda-forge jupyter_contrib_nbextensions
conda install -c conda-forge jupyter_nbextensions_configurator

pip install jupyter_contrib_nbextensions -i https://pypi.mirrors.ustc.edu.cn/simple
jupyter contrib nbextension install --user

pip install --user jupyter_nbextensions_configurator 
jupyter nbextensions_configurator enable --user


   21  pip install jupyter_contrib_nbextensions
   22  jupyter contrib nbextension install --user
   23  pip install--user jupyter_nbextensions_configurator
   24  pip install --user jupyter_nbextensions_configurator
   25  jupyter nbextensions_configuratorenable --user
   26  jupyter nbextensions_configurator enable --user

参考 https://www.jianshu.com/p/3fe1f9b53dfb

6 jupyter配置主题 ,这个很赞 ,但是有一个小坑 ,工具栏消失 -T ,代码补全消失 ,重启 并新建一个notebook
安装主题包

# install jupyterthemes
pip install jupyterthemes

# upgrade to latest version
pip install --upgrade jupyterthemes

更换
# list available themes
# onedork | grade3 | oceans16 | chesterish | monokai | solarizedl | solarizedd
# 列出所有可用的主题
jt -l

# select theme...
# jt -t 主题名
jt -t chesterish -T -N
jt -t monokai -T -N
[https://www.jianshu.com/p/f591426aadb8](https://www.jianshu.com/p/f591426aadb8)



# restore default theme
# NOTE: Need to delete browser cache after running jt -r
# If this doesn't work, try starting a new notebook session.
# 恢复默认主题
jt -r
使用命令:jt -t 主题名 -N -T 更换主题

再点View-Toggle Header 和 Toggle Toolbar 就出来了

7 ## jupyter 安装scala 环境成功了,具体步骤
如果你使用 conda 默认的环境 就是base,要先切换环境,不然scala 就按照到别的地方了

conda activate base 
pip install toree
git clone https://github.com/jupyter-scala/jupyter-scala.git
cd  jupytter-scala
 $ SCALA_VERSION=2.12.8 ALMOND_VERSION=0.4.0
$ curl -Lo coursier https://git.io/coursier-cli
$ chmod +x coursier
$ ./coursier bootstrap \
    -r jitpack \
    -i user -I user:sh.almond:scala-kernel-api_$SCALA_VERSION:$ALMOND_VERSION \
    sh.almond:scala-kernel_$SCALA_VERSION:$ALMOND_VERSION \
    -o almond
$ ./almond --install
[https://almond.sh/docs/quick-start-install](https://almond.sh/docs/quick-start-install)

另外如果需要安装spark 的话
首先先下载 spark的压缩包,解压到某目录,然后 
pip install pyspark

jupyter toree install --interpreters=Scala --spark_home=/data/spark  --user --kernel_name=apache_toree --interpreters=PySpark,SparkR,Scala,SQL

8 配置spark job 进度条
pip install jupyter-spark
jupyter serverextension enable --py jupyter_spark
jupyter nbextension install --py jupyter_spark
jupyter nbextension enable --py jupyter_spark
jupyter nbextension enable --py widgetsnbextension

spark job 进程图
注意   --spark_home 根据实际调整,  PySpark,SparkR 可能会不成功,无所谓

参考https://blog.csdn.net/sinat_27634939/article/details/80146340

https://blog.csdn.net/fontthrone/article/details/83242415

conda
https://blog.csdn.net/yimingsilence/article/details/79388205

配置pyspark
https://github.com/mozilla/jupyter-spark
.jupyter安装 scala 解释器 和spark 解释器

https://blog.csdn.net/qq_30901367/article/details/73296887

9.安装java
下载 jdk 12

https://download.oracle.com/otn-pub/java/jdk/12.0.1+12/69cfe15208a647278a19ef0990eea691/jdk-12.0.1_linux-x64_bin.rpm?AuthParam=1557549681_2e420906304039202cef64ceb74dc923
yum install  ./jdk-12.0.1_linux-x64_bin.rpm #配置环境变量
 cd /opt/
  git clone https://github.com/SpencerPark/IJava.git
 java -version
 cd IJava/
 chmod u+x gradlew && ./gradlew installKernel

10 . jupyter 配置c++

  1. conda install xeus-cling notebook -c QuantStack -c conda-forge
    https://pymilk.com/jupyter-netbookpei-zhi-c-huan-jing/
    需要注意的是, 安装这个确实有点慢 可以修改 conda 源试试,但是不一定管用
    另外 由于太慢 可能会失败 那就多试试几次 ,在mac 和 centos7 都可以的
    另外由于版本问题,也可能会失败, 如果失败了,可以这样分开执行

 conda install xeus-cling notebook -c QuantStack -c conda-forge


 3306  conda install gcc  -c QuantStack -c conda-forge
 3307  conda install  notebook -c QuantStack -c conda-forge
 3308  conda install xeus-cling -c QuantStack -c conda-forge
 3309  conda install xeus-cling notebook -c QuantStack -c conda-forge

3305 conda install gcc 尽量不要尝试这个,这个安装的gcc 是4.8.5-7,
我们需要的是 gcc-7-7.2.0 ,否则会报错

  1. brew install cling
    https://jiege.ch/programming/2017/11/30/run-cpp-in-jupyter-notebook/

2.http://www.codebelief.com/article/2017/06/run-cpp-code-interactively-on-jupyter-notebook/

11.安装 julia
https://www.jianshu.com/p/3839fb08be1a

12 .jupyter 安装golang 解释器,这个在linux上没有安装成功
https://studygolang.com/articles/13235?fr=sidebar

No package 'libsodium' found

wget https://archive.org/download/zeromq_4.1.4/zeromq-4.1.4.tar.gz

 yum install libtool

 ./configure --prefix=/usr/local/zeromq --without-libsodium

Make && make install 

src/libzmq.pc '/usr/local/zeromq/lib/pkgconfig'

 mkdir -p /usr/lib/pkgconfig

(condaEnv) [root@hzv_content_embedding bin]# cp /usr/local/zeromq/lib/pkgconfig/libzmq.pc /usr/lib/pkgconfig/

 go get [github.com/pebbe/zmq4](http://github.com/pebbe/zmq4)

设置 lgo path
export GOROOT=/usr/lib/golang
export GOPATH=/data/algorithm/
export LGOPATH=/data/algorithm/bin/
export PATH=$GOROOT:$GOPATH:$LGOPATH/cmd:$LGOPATH:$PATH

yum install golang
https://github.com/yunabe/lgo
git clone https://github.com/yunabe/lgo.git
 jupyter console --kernel lgo

13.centos 安装R 语言解释器,重启jupyter 可以支持R ,
如果不使用 R ,建议不要安装R ,安装得一个多小时,很久

conda install -c r r-essentials

https://blog.csdn.net/jacke121/article/details/75378645

14 配置 代码自动补全 Hinterland 和快捷键

jupyter 设置 相关插件和快捷键
首先是 sublime text 快捷键
添加sublime的快捷键
在~/.jupyter/custom下有custom.css custom.js fonts。

修改custom.js中,添加如下代码:

require(["codemirror/keymap/sublime", "notebook/js/cell", "base/js/namespace"],
    function(sublime_keymap, cell, IPython) {
        cell.Cell.options_default.cm_config.keyMap = 'sublime';
        var cells = IPython.notebook.get_cells();
        for(var cl=0; cl< cells.length ; cl++){
            cells[cl].code_mirror.setOption('keyMap', 'sublime');
        }
    }
);


自定义sublime的快捷键
修改keymap路径~/anaconda3/lib/python3.6/site-packages/notebook/static/components/codemirror/keymap/sublime.js。
如果找不到,相应的查找一下计算机中sublime.js的路径。
修改下面的kepmap,修改成自己习惯的按键方式:


keyMap.macSublime = {

// "Cmd-D": "selectNextOccurrence",
// "Shift-Cmd-D": "duplicateLine",
"Cmd-D": "duplicateLine",
// "Cmd-Ctrl-Up": "swapLineUp",
"Shift-Cmd-Up": "swapLineUp",
// "Cmd-Ctrl-Down": "swapLineDown",
"Shift-Cmd-Down": "swapLineDown",

}

作者:longgb246
链接:https://www.jianshu.com/p/02e8dd896cb1

http://resuly.me/2017/11/03/jupyter-config-for-windows/

设置 代码折叠 代码 格式化 代码执行时间 spark job 进度条 py2 to 3


image.png
image.png

15.jupyter 播放视频

import io
import base64
from IPython.display import HTML

video = io.open('/Users/hainingzhang/Documents/nicelive/intest/运动/17e87930-378e-11e9-96fb-0a580a44cd67.mp4.mp4', 'r+b').read()
encoded = base64.b64encode(video)
HTML(data='''<video alt="test" controls>
<source src="data:video/mp4;base64,{0}" type="video/mp4" />
</video>'''.format(encoded.decode('ascii')))
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 160,444评论 4 365
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,867评论 1 298
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 110,157评论 0 248
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,312评论 0 214
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,673评论 3 289
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,802评论 1 223
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 32,010评论 2 315
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,743评论 0 204
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,470评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,696评论 2 250
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,187评论 1 262
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,538评论 3 258
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,188评论 3 240
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,127评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,902评论 0 198
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,889评论 2 283
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,741评论 2 274

推荐阅读更多精彩内容