Jupyter
启动关闭
jupyter notebook list: 得到当前正在运行的notebook列表
Currently running servers:
http://0.0.0.0:8890/?token=c3a4f2dca530d704926d90e22926a688f300f2ab8384345b :: /mnt/home/chengyongru
jupyter notebook stop [port]: 关闭指定端口的notebook 有些时候会报错
chengyongru@client1 ~ $ jupyter-notebook stop 8898
[C 10:25:46.583 NotebookApp] No such file or directory: /mnt/home/chengyongru/stop
这是因为jupyter版本太低了,如果你没有权限升级jupyter 那么解决方案是:
From ShusenTang This might help:
first, runjupyter notebook listto get jupyter used port-number.
then,runlsof -n -i4TCP:[port-number]to get PID, The PID is the second field in the output.
finally, runkill -9 [PID]to kill this process.
geturl.sh
jupyter notebook list| grep -Eo "(http|https)://[a-zA-Z0-9./?=_%:-]*" | sed 's/0\.0\.0\.0/client1.bjtx.ishumei.com/g'
server部署jupyter
python解释器
这里我选择用venv创建虚拟环境
python -m venv your_env_namesource your/env/path/bin/activatepip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Jupyter设置
首先创建jupyter配置文件
jupyter notebook --generate-config然后常规操作取消密码和token
这里我配置了一点shell脚本帮助我更好的使用jupyter
function jupyterls() {
jupyter notebook list
}
function jupyterst() {
nohup jupyter notebook "$@" > jupyter.log 2>&1 &
}
function jupyterkill() {
if [ $# -eq 0 ]; then
echo "Usage: jupyterkill <port>"
exit 1
fi
port=$1
pid=$(lsof -ti :$port)
if [ -z "$pid" ]; then
echo "No Jupyter server running on port $port."
else
kill $pid
echo "Jupyter server on port $port has been killed."
fi
}本地访问jupyter
这里我通过建立ssh隧道将远程端口映射到了本地 可以使用SSH隧道(SSH Tunneling)来实现远程访问。SSH隧道允许你在本地计算机上创建一个安全的连接,将远程服务器上的服务映射到本地端口,从而可以通过本地浏览器访问远程Jupyter服务。
以下是连接到服务器上开启的Jupyter服务的步骤:
- 登录到远程服务器:
使用SSH登录到你的远程服务器。打开终端(命令行界面)并执行以下命令(将
username和your_server_ip替换为实际的用户名和服务器IP地址):
ssh username@your_server_ip输入服务器密码(如果有密码)或者SSH密钥密码,然后登录到服务器。
- 启动Jupyter服务: 在服务器上启动Jupyter服务。在终端上执行以下命令:
jupyter notebookJupyter服务会在默认端口(通常是8888)上启动。
- 创建SSH隧道:
打开一个新的本地终端窗口,执行以下命令(将
username和your_server_ip替换为实际的用户名和服务器IP地址,remote_port替换为Jupyter服务在服务器上的端口号):
ssh -N -f -L localhost:local_port:localhost:remote_port username@your_server_ip这将在本地计算机上创建一个SSH隧道,将远程服务器上的Jupyter服务映射到本地端口(local_port),从而可以在本地访问Jupyter服务。
请确保 local_port 未被其他进程占用。通常,你可以选择大于1024的任意未被使用的端口号,比如8889。
- 访问Jupyter服务: 打开本地浏览器,并在地址栏中输入以下URL:
http://localhost:local_port
然后,你就可以在本地浏览器中访问远程服务器上的Jupyter服务了。 5. 关闭ssh隧道
ps -ef | grep ssh
kill pid