您正在查看的是 Apigee Edge 文档。
转到 Apigee X 文档。 信息
本主题介绍如何从命令行部署代理。Apigee Edge 提供了两种从命令行部署的方式。第一种方法是使用以 Python 编写的 Apigee Edge 部署工具。另一种方法是配置并运行 Shell 脚本。
在系统上直接使用代理源文件时,请使用命令行部署方法。离线工作的原因可能有很多。您可能希望使用喜爱的 XML 编辑器,或者您可能正在开发需要进行 Java 编码的政策,并且您主要在 IDE 中工作。借助本部分介绍的技术,您可以将源文件上传并部署到所选的 API 服务环境。
如果您主要在管理界面中操作,请参阅在界面中部署代理。
您正在查看 Apigee Edge 文档。
转到 Apigee X 文档。 信息
运行 Apigee Edge Python 部署工具
Apigee Edge Python 部署工具可与 Edge Management API 搭配使用,以导入和部署 API 代理。该工具作为 GitHub 上的 API 平台示例发行版的一部分提供。请参阅使用示例 API 代理。
利用 Apigee Edge Python 工具,只需一个简单的流程即可导入(上传)和部署您的 API。
部署工具必须从 API 平台示例发行版的基本目录运行,其中基本目录是 setup
和 tools
目录的父目录。
在以下命令中,替换代理名称、您的 Edge 用户名和密码、Edge 组织和环境,以及 API 代理的“apiproxy"
目录”所在目录的路径:
python tools/deploy.py -n proxyname -u name:passW -o org -e env -d proxypath -p /
例如:
python tools/deploy.py -n weatherapi -u me@myCo.com:foo -o myCo -e test -d weatherapi -p /
此命令会压缩您的文件,将其推送到您在 Apigee Edge 上的组织,并将它们部署到指定的环境。
部署工具会自动发现 API 代理的当前修订版本,取消部署现有修订版本,并部署 API 代理的递增修订版本。
成功后,您会看到如下格式的输出:
Writing ./<proxybasedir>/apiproxy/weatherapi.xml to apiproxy/weatherapi.xml Writing ./<proxybasedir>/apiproxy/proxies/default.xml to apiproxy/proxies/default.xml Writing ./<proxybasedir>/apiproxy/targets/default.xml to apiproxy/targets/default.xml Imported new proxy version 1 Environment: test Revision: 1 BasePath = / State: deployed
默认情况下,该工具会将 API 代理上传到 https://api.enterprise.apigee.com
(与云端的 Edge 相对应)。您还可以指定 -h
标志,使用此工具将 API 代理上传到本地版本的 Edge:
python tools/deploy.py -n weatherapi -u me@myCo.com:foo -o myCo -e test -d weatherapi -p / -h https://192.168.11.111:8080
在此示例中,您需要指定边缘管理服务器的 IP 地址。如果您已为管理服务器创建 DNS 记录,则可以按如下格式指定网址:
https://ms_URL:8080
此命令的完整标志列表如下:
-n
:您的 API 代理的名称。-u
:您的 Apigee Edge 组织中帐号的用户名和密码。-o
:您拥有帐号的组织名称。-e
:应部署 API 代理的环境(test
或prod
)。-d
:包含 API 代理文件的目录的路径。您的 API 代理文件必须存储在名为“apiproxy”的目录下。此值是包含“apiproxy”目录的目录的路径,而不是“apiproxy”目录本身的路径。-p
:用作模式匹配以将传入消息路由到此 API 代理部署的 URI 路径。在大多数情况下,除非您有高级部署和路由要求,否则可以将此值设为“/”。用于 API 代理路由的主路径在 API 代理的 ProxyEndpoint 配置文件中定义。-h
:Edge 网址。默认情况下,网址为https://api.enterprise.apigee.com
,与云端的 Edge 相对应。对于本地部署,请使用边缘管理服务器的网址和端口 8080,如下所示:https://ms_URL:8080
或者,使用管理服务器的 IP 地址,如
https://192.168.11.111:8080
中所示。
配置并运行部署 Shell 脚本
最简单的方法是运行随示例 API 代理提供的部署脚本。Shell 脚本封装了 Apigee Edge Python 部署工具。
从 /simplyProxy
目录运行:
$ sh deploy.sh
您应该会看到:
Enter your password for user {myname} in the Apigee Enterprise organization {org_name}, followed by [ENTER]:
输入密码,按 Enter 键。
然后,您应该会看到:
Deploying to test on https://api.enterprise.apigee.com using {myname} on enterprise.apigee.com and {org_name} on enterprise.apigee.com
如果您看到以下内容:
Enter your password for user Your USERNAME on enterprise.apigee.com in the Apigee Enterprise organization Your ORG on enterprise.apigee.com, followed by [ENTER]:
则表示您需要修改平台示例发行版中的 /setup/setenv.sh
文件。有关说明,请参阅自述文件或 Apigee Edge API。
成功后,部署工具会将 /apiproxy,
下的文件压缩到 Apigee Edge 上的组织中,然后将 API 代理部署到“测试”环境。
您的 API 代理已准备就绪,可以调用了。