pip install -U prefect
prefect server start
prefect deploy
activate fri
source /opt/prefect-env/bin/activate
创建新会话 tmux new -s 会话名
分离会话(保持运行) Ctrl+b d
查看所有会话 tmux ls
重新连接会话 tmux attach -t 会话名
杀死会话 tmux kill-session -t 会话名
重命名会话 Ctrl+b $
1. 创建并进入虚拟环境
cd /opt
python3 -m venv prefect-env
source /opt/prefect-env/bin/activate
2. 安装 prefect
pip install prefect
3. 启动 Prefect Server(在 tmux 或后台运行)
先安装 tmux 以便保持服务运行
apt install tmux -y
启动 server
tmux new -s prefect-server
prefect server start
按 Ctrl+B 然后 D 退出 tmux 会话
4. 创建 work pool(新终端或另一个 tmux 会话)
tmux new -s prefect-worker
source /opt/prefect-env/bin/activate
prefect work-pool create my-work-pool --type process
prefect worker start --pool my-work-pool
按 Ctrl+B 然后 D 退出
5. 设置 API URL(重要!)
如果你在服务器本机访问,用 localhost
prefect config set PREFECT_API_URL="http://127.0.0.1:4200/api"
如果从其他机器访问,用服务器的实际 IP
prefect config set PREFECT_API_URL="http://你的服务器IP:4200/api"
接下来是要发布的命令需要的
第五步:本地连接远程 Prefect server
在本地执行:
prefect config set PREFECT_API_URL=http://104.168.101.159:4200/api
检查是否连上:
prefect work-pool ls
你应该能看到:
my-work-pool
第六步:本地发布 deployment
在本地项目根目录执行:
prefect deploy
如果你的 prefect.yaml 里只有一个 deployment,它会直接发布。
如果有多个,可以指定:
prefect deploy --name hello-remote
成功后,查一下:
prefect deployment ls
你应该能看到类似:
hello-flow/hello-remote
第七步:触发远程执行
本地执行:
prefect deployment run hello-flow/hello-remote
如果名字不确定,先看:
prefect deployment ls
然后复制列表里的完整名字执行。
也可以去浏览器打开:
http://104.168.101.159:4200
在 UI 里点 deployment,然后点 Run。

评论
填写昵称与邮箱即可评论,无需登录。