Linux运维笔记[3]-部署网络服务
部署jupyter
Docker 部署Jupyter book
Jupyter Docker Stacks are a set of ready-to-run Docker images containing Jupyter applications and interactive computing tools. You can use a stack image to do any of the following (and more):
Start a personal Jupyter Server with JupyterLab frontend (default)
Run JupyterLab for a team using JupyterHub
Start a personal Jupyter Notebook server in a local Docker container
Write your own project Dockerfile
从零开始学习线性代数:使用Jupyter Notebook
镜像说明
镜像关系:
大数据分析:
mkdir /home/jupyter
chmod 777 /home/jupyter
docker run --name first_jupyter -it -p 40000:8888 -v /home/jupyter:/home/jovyan/work jupyter/datascience-notebook:latest
神经网络:
docker run --name second_jupyter -it --rm -p 40001:8888 -v "${PWD}":/home/jovyan/work jupyter/tensorflow-notebook:latest
提示:
To access the server, open this file in a browser:
file:///home/jovyan/.local/share/jupyter/runtime/jpserver-8-open.html
Or copy and paste one of these URLs:
[https://cloud.tencent.com/developer/ask/sof/1468015]
其他电脑可以过http://服务器ip:10000/lab?token=3d01d631dcb9b*****a018be1a38817de88a84cf31888d65
来访问jupyter,会让输入token
设置密码,以后不用输入token了
#查询token
docker exec -it first_jupyter jupyter notebook list
#设置密码
docker exec -it first_jupyter jupyter notebook password
#重启实例
docker restart first_jupyter
Due to the usage of the flag --rm Docker automatically cleans up the container and removes the file system when the container exits, but any changes made to the ~/work directory and its files in the container will remain intact on the host. The -it flag allocates pseudo-TTY.
正式部署
[https://jupyter-docker-stacks.readthedocs.io/en/latest/index.html]
解决docker容器启动秒退
#亲测可用
docker pull jupyter/tensorflow-notebook:2022-05-05
#这样运行不会秒退,终端有root权限
docker run -p 91:8888 -v /home/server/files:/home/jovyan/work --user root -e CHOWN_EXTRA=/home/server/files -d jupyter/tensorflow-notebook:2022-05-05 /bin/sh -c "jupyter server --allow-root;while true;do echo hello;sleep 5;done"
docker ps
docker exec -it 7f4f3fc63294 bash
jupyter server list
exit
#容器仍在后台运行
按照说明打开网址
http://192.168.50.80:91/lab?token=191b708f1701860eed3548c9a0cb15aa5a7dc358c7bbb382
注意端口号和token
http://192.168.50.80:91/lab
这里可以设置密码
token is the secret token printed in the console.
Ctrl+P和Ctrl+Q分别按,可以退出容器,让容器仍运行,
不能用的:docker pull docker pull jupyter/tensorflow-notebook:latest
镜像是每日自动生成,但是不保证每天的都能用,笔者试了很多总算找到能用的😮💨,其他的会有网络错误
小提示
欧拉记得允许防火墙
firewall-cmd --list-all
firewall-cmd --permanent --add-port=40000/tcp
firewall-cmd --reload
firewall-cmd --list-all
添加docker使用用户
sudo groupadd docker
sudo usermod -aG docker $USER
linux进阶网络设置
在线设置多个ip
ifconfig
ifconfig enp3s0:0 192.168.156.88 netmask 255.255.255.0 up
ifconfig
写到文件,使启动时自动生效
vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=enp3s0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.156.88
设置主机名
hostnamectl set-hostname Ryzen
添加DNS
nmcli connection modify eth0 ipv4.dns 114.114.114.114
内部端口转发
需求:9090端口映射到80端口
[https://zhuanlan.zhihu.com/p/490631573]
端口转发就是把网络流量从一个网络监听者(称为一个“端口”)发送到另一个上,无论这两个端口是否属于同一台电脑。在这里,端口不是某个物理实体,而是一个监听网络活动的软件程序。
当流量被定向发往到某个特定的端口,它会先到达一个路由器或是防火墙,亦或是其他的网络程序。它最终收到的响应可能会根据它想要通讯的端口来定义。比如,当你使用端口转发时,你可以捕获到发往 8080 端口的流量,然后把它转发到 80 端口。对于接收信号的原端口来说,这个新的目标端口可能和它在同一台设备上,也可能是在另一台设备上。我们在很多情况下都会用到端口转发,实现的方式也有很多。本文将介绍其中最常见的几种使用场景。
系统管理员有时候需要转发访问服务器的流量。比如说,你可能想要接收来自 80 端口的流量,但是用户的服务却运行在 8065 端口。如果不进行端口转发的话,你的用户就不得不在输入浏览器的 URL 末尾,加上一个指定的端口号,例如 example.com:8065。大多数用户都不习惯于考虑端口的问题,所以你需要把访问网络通用的 80 端口的请求拦截下来,然后转发到你的网络应用的具体端口,这会给用户带来巨大的方便
sudo firewall-cmd
--add-forward-port
port=80:proto=tcp:toport=9090
sudo firewall-cmd --runtime-to-permanent
Python建立简单网页服务器
cd /www
touch index.html
vim index.html
<html>
<h1>hello</h1>
</html>
python3 -m http.server 80
可在127.0.0.1:80访问网页
记得允许防火墙
传输文件
touch /home/phablet/hello
另外开一个终端rsync qsbye@192.168.50.80:/home/phablet/hello ~/Downloads
或者
sftp工具连接ssh
linux命令后台运行
命令 &
例如
python3 -m http.server 20791 & disown
或者用Tmux
tmux new -d 'ping -c 10 8.8.8.8 > www.itpro.net.cn.log'
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」