阿里云搭建远程jupyterlab

情况说明

趁着疫情,210元3年1核2m的服务器。赶紧下手。

因为我那个腾讯云,原先为了写毕设,统一生活和工作俩电脑都不同步的原因,另外需要记录一下常用的测试操作,需要一个电脑来另外记录,云服务器成了最好的选择,便宜好用。

因为腾讯云续了一年的期到了,续费超贵,所以这次用了阿里云。

搭建远程服务工具jupyterlab

原先我是使用jupyter notebook 来远程使用python工具的,没想到这次上网搜索的时候发现还有进阶版jupyterlab。果断试试。

准备工作

首先我们需要一个anaconda。

为啥用这个呢。方便。比你自己下载python,然后又整其他乱七八糟的东西好太多了。这玩意可以统一管理所有包

推荐清华的镜像。点击这里

自己选择适合自己电脑类型且最新的。当然最新的也不过是2018版的,不过没关系,能用就行,下载完了,自己在更新也不迟啊。

wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-5.3.1-Linux-x86_64.sh

下载完成后,使用以下命令进行安装anaconda:
sh Anaconda3-5.3.1-Linux-x86_64.sh

安装完成之后,关闭当前session,重新打开一个session,再使用conda检查是否安装完成。

正确出现提示,就代表安装正确。

这个anaconda 安装完成之后,使用conda list可以看到jupyterlab赫然在列。

我们所要做的就是配置和启动了。

配置

首先呢,要找到.jupyter这个目录。

cd ~   # 到你的默认目录
ll   
cd .jupyter

首先要生成配置文件。

jupyter notebook --generate-config

ls 可以看到jupyter_notebook_config.py

首先,要生成远程登录jupyterlab的登录密码。这里我们用的是ipython中的方法。

from notebook.auth import passwd
passwd()

这里会提示让你输入两次密码,终端不会显示,注意两次密码要一致

终端会输出一段字符
'sha1:ded51e3a8038:dfd78825da8fb0f1ba127a26bc604f81435787fa'

复制,备用

此时 使用vim进行jupyter_notebook_config.py文件的更改。

c.NotebookApp.ip='*'  # 允许任何ip访问
c.NotebookApp.open_browser = False  # 开始时是否自动开启浏览器
c.NotebookApp.port =8888 # 可自行指定一个端口, 访问时使用该端口
c.NotebookApp.password = 'sha1:ded51e3a8038:dfd78825da8fb0f1ba127a26bc604f81435787fa'  # 粘贴上刚才生成的密码
c.NotebookApp.notebook_dir = u'/root/jupyterlab'  # 设置jupyterlab的根目录
# 允许远程访问 
c.NotebookApp.allow_remote_access = True

设置完成之后,启动。
nohup jupyter lab --allow-root &

远程访问你的服务器地址+8888,就可以访问啦。

记得要配置好你服务器的安全组规则

重新docker下制作远程jupyterlab

apt-get update
apt-get upgrade

# 下载docker
apt-get install docker.io

# 获取镜像
docker pull ubuntu:16.04

# 生成容器
docker run -d -it  --name='jupyterlab' -p 3090:22 -p 3091:8888 -p 3092:3092 xxxx   # xxxx 是指刚才下载镜像的id前四位

# 获取刚才运行中的容器
docker ps  

# xxx 是指刚才获取的容器id
docker exec -it xxx /bin/bash 

apt-get update

apt-get install python-pip

apt-get install vim

pip install jupyterlab

# 此时我发现我得docker下的ubuntu镜像容器中是python2,我需要python3,于是

apt-get install python-software-properties

apt-get install software-properties-common

add-apt-repository ppa:fkrull/deadsnakes

# 更新源文件
vim /etc/apt/sources.list

# 将下面这些文字贴在最后
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

apt-get update
apt-get upgrade

# 重新使用 apt-get install python3.7 仍然下载不了,决定直接下载源码
wget 'https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz'

tar -zxvf Python-3.7.3.tgz

apt-get install zlib1g-dev libbz2-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev tk-dev libgdbm-dev libdb-dev libpcap-dev xz-utils libexpat1-dev

apt-get install liblzma-dev libffi-dev libc6-dev

cd Python-3.7.3

mkdir -p /usr/local/python3

./configure --prefix=/usr/local/python3  --enable-optimizations

make

make install

# 删除原有软连接
rm -rf /usr/bin/python3
rm -rf /usr/bin/pip3

ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3

# 使用python3验证,如果不对,重复上面安装过程

wget https://files.pythonhosted.org/packages/8e/76/66066b7bc71817238924c7e4b448abdb17eb0c92d645769c223f9ace478f/pip-20.0.2.tar.gz

wget https://files.pythonhosted.org/packages/b5/96/af1686ea8c1e503f4a81223d4a3410e7587fd52df03083de24161d0df7d4/setuptools-46.1.3.zip

unzip setuptools-40.6.2.zip
cd setuptools-40.6.2
python3.7 setup.py build
python3.7 setup.py install

tar -zxvf pip-18.1.tar.gz
cd pip-18.1
python3.7 setup.py build
python3.7 setup.py install

ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3

# 运行jupyterlab
# 先生成需要的 地址 
cd /root
mkdir jupyterlab
nohup jupyter lab --allow-root > nohup.out  &

以上有一个python3的bin放置问题。需要在/etc/profile 末尾处添加 export PATH=$PATH:/usr/local/python3/bin 然后
退出当前vim操作页面。使用source /etc/profile立即生效。然后再启动jupyterlab

我已生成对应镜像,放在dockerhub中。可以拉取

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值