当前位置: 首页> 健康> 养生 > 重庆二级建造师证书查询_相关网站查询_合肥seo网站建设_广州网站优化排名

重庆二级建造师证书查询_相关网站查询_合肥seo网站建设_广州网站优化排名

时间:2025/7/11 14:32:19来源:https://blog.csdn.net/wanglei19891210/article/details/142349626 浏览次数:0次
重庆二级建造师证书查询_相关网站查询_合肥seo网站建设_广州网站优化排名

一、产品介绍

1、官方 Github

https://github.com/PrefectHQ/prefect

在这里插入图片描述

2、官方文档

https://docs.prefect.io/3.0/get-started/index

3、Pgsql说明

正确的python链接pgsql如下:

import psycopg2
from sqlalchemy import create_enginedef connect_with_psycopg2():try:conn = psycopg2.connect(dbname="prefect",user="prefect_user",password="123456-AbCd",host="127.0.0.1",port="5432")print("Connection successful with psycopg2!")except Exception as e:print(f"Connection failed with psycopg2: {e}")finally:if conn:conn.close()def connect_with_sqlalchemy():try:engine = create_engine("postgresql://prefect_user:123456-AbCd@127.0.0.1:5432/prefect")with engine.connect() as connection:print("Connection successful with SQLAlchemy!")except Exception as e:print(f"Connection failed with SQLAlchemy: {e}")if __name__ == "__main__":connect_with_psycopg2()connect_with_sqlalchemy()

如何我们将密码设置为 123456-Ab@
整体字符串如下:postgresql://prefect_user:123456-Ab@@127.0.0.1:5432/prefect
链接失败!所以不要将密码设置为含有@的字符串

def connect_with_sqlalchemy():try:engine = create_engine("postgresql://prefect_user:123456-Ab@@127.0.0.1:5432/prefect")with engine.connect() as connection:print("Connection successful with SQLAlchemy!")except Exception as e:print(f"Connection failed with SQLAlchemy: {e}")if __name__ == "__main__":connect_with_sqlalchemy()

二、搭建私有Prefect Server

私有化搭建,通过pgsql作为整个数据库

1、Docker搭建 PGsql

这里如果服务器拉不到最新版本的pgsql,可以通过科学上网做一份自己的pgsql镜像
这里我使用自己创建的镜像 :registry.cn-beijing.aliyuncs.com/dkzx_test/postgres

version: '3'services:postgres:image: registry.cn-beijing.aliyuncs.com/dkzx_test/postgres:latestcontainer_name: postgresenvironment:POSTGRES_DB: prefectPOSTGRES_USER: prefect_userPOSTGRES_PASSWORD: 123456-AbCdvolumes:- /home/postgres_data:/var/lib/postgresql/dataports:- "5432:5432"restart: always

注意:
1、这里要给 /home/postgres_data 足够的权限

2、Docker搭建 Prefect

启动成功如下:
在这里插入图片描述

2.1、打Prefect镜像

因为 prefect没有最新的Docker Image 所以这里我们自己通过Dockerfile创建一个Prefect镜像
同样这里如果服务器拉不到最新版本的 Prefect,可以通过科学上网做一份自己的Prefect镜像
这里我使用自己创建的镜像 :registry.cn-beijing.aliyuncs.com/dkzx_test/python:3.9-slim

# unc_name)
#n 作为基础镜像
FROM registry.cn-beijing.aliyuncs.com/dkzx_test/python:3.9-slim# 设置工作目录
WORKDIR /app# 更新 pip 并安装 Prefect
RUN pip install --upgrade pip && \pip install -U prefect# 运行 Prefect 以显示版本
CMD ["prefect", "--version"]

上面的 Dockerfile 通过打包程序打包成 Docker Image

docker build -t <docker-image-name> .

然后将image推送到私有镜像仓库,或者直接放本地直接启动
这里我们推送到私有镜像仓库registry.cn-beijing.aliyuncs.com/dkzx_test/prefect:customer-define-new

2.2、编写Prefect Docker-compose

在这里插入图片描述

下面注意几个点:
1、PREFECT_API_DATABASE_CONNECTION_URL :这个是连接pgsql的字符串信息,这里要使用前缀postgresql+asyncpg:,并且这里我们踩坑密码一定不能含@结尾数据
2、PREFECT_API_URL:这个对外开放API一定要用0.0.0.0的IP,不要用127.0.0.1
3、command:如果我们的Dashboard想被外网访问一定要指定host为0.0.0.0

version: "3"services:prefect-server:image: registry.cn-beijing.aliyuncs.com/dkzx_test/prefect:customer-define-newcontainer_name: prefect_serverenvironment:PREFECT_API_DATABASE_CONNECTION_URL: postgresql+asyncpg://prefect_user:123456-AbCd@127.0.0.1:5432/prefectPREFECT_API_URL: http://0.0.0.0:4200/apiports:- "4200:4200"command: ["prefect", "server", "start","--host", "0.0.0.0"]restart: always

3、PGsql初始化

通过启动 prefect_server 会在指定的数据库自动创建如下所有的数据库表

在这里插入图片描述

4、公网可访问的裸奔服务

不得不吐槽一下,启动的私有部署Prefect是没有登录权限的
也没有token

5、Nginx 配置 Basic Auth

三、对比:Cloud & 私有部署

1、Cloud

cloud的功能更丰富,且可以创建Namespace

在这里插入图片描述

2、私有部署

私有部署的server相对比cloud要简单一些

在这里插入图片描述

关键字:重庆二级建造师证书查询_相关网站查询_合肥seo网站建设_广州网站优化排名

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: