服务器完整搭建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=''''''.format(encoded.decode('ascii')))

你可能感兴趣的:(服务器完整搭建jupyter 科学环境服务)