快速开始
本文描述了如何用 Yarn 服务框架在 Yarn 上部署服务。
配置和启动 HDFS 和 Yarn 组件
首先启动 HDFS 和 Yarn 的各个组件。为启用 Yarn 服务框架,添加以下参数到 yarn-site.xml 文件中并重启 ResourceManager,或在 ResourceManager 启动前就设置号。该参数是启用 Yarn 服务框架的 CLI 和 REST API 所必需的。
<property> <description> 在 ResourceManager 启用 Yarn 服务框架的 REST API。 </description> <name>yarn.webapp.api-service.enable</name> <value>true</value> </property>
示例服务
以下是一个简单的服务定义,它通过一个简单的说明文件在 Yarn 上启动容器执行睡眠命令,整个过程无需写任何代码。
{ "name": "sleeper-service", "components" : [ { "name": "sleeper", "number_of_containers": 1, "launch_command": "sleep 900000", "resource": { "cpus": 1, "memory": "256" } } ] }
执行以下命令,用户可以简单地运行一个预先提供的样例服务:
yarn app -launch <service-name> <example-name>
举例来说,以下命令在 Yarn 上启动了一个 sleeper 服务并命名为 my-sleeper。
yarn app -launch my-sleeper sleeper
如果要使用 Yarn 服务框架启动基于 Docker 的服务,请参阅 API 文档。
通过 CLI 管理 Yarn 上的服务
以下步骤实现用 CLI 部署一个 Yarn 服务。请参阅 Yarn 命令集以获得完整的命令列表。
部署一个服务
yarn app -launch ${SERVICE_NAME} ${PATH_TO_SERVICE_DEF_FILE}
参数 SERVICE_NAME 在某个用户名下必须是唯一的。参数 PATH_TO_SERVICE_DEF 是 Json 格式的服务定义文件夹的路径。
举例来说:
yarn app -launch sleeper-service /path/to/local/sleeper.json
伸缩一个服务的组件
为一个组件增加或减少容器数量:
yarn app -flex ${SERVICE_NAME} -component ${COMPONENT_NAME} ${NUMBER_OF_CONTAINERS}
距离来说,对于一个名叫 sleeper-service 的服务,设置其名为 sleeper 的组件的容器数量为 2 个(绝对值):
yarn app -flex sleeper-service -component sleeper 2
在伸缩命令中,${NUMBER_OF_CONTAINERS} 同样可以是相对值,如 +2 或 -2。
停止一个服务
停止一个服务将停止该服务的所有容器和关联的 ApplicationMaster,但不会删除服务的状态,如在 HDFS 上的服务的根目录。
yarn app -stop ${SERVICE_NAME}
重启一个停止的服务
重启一个停止的服务非常容易,只需调用启动命令!
yarn app -start ${SERVICE_NAME}
销毁一个服务
在停止服务之外,它还会删除该服务在 HDFS 上的根目录以及在 Yarn Service Registry 里的记录。
yarn app -destroy ${SERVICE_NAME}
通过 REST API 管理 Yarn 上的服务
当 yarn.webapp.api-service.enable 为 true时,YARN API Server REST API 作为 ResourceManager 的一部分被激活。
可以通过 ResourceManager 的网络入口在 Yarn 上部署服务。
参阅 API 文档以获得更多 API 说明。
部署一个服务
POST 提交前面提供的样例服务的定义到 ResourceManager API 服务入口:
POST http://localhost:8088/app/v1/services
获取服务的状态
GET http://localhost:8088/app/v1/services/${SERVICE_NAME}
伸缩服务的组件
PUT http://localhost:8088/app/v1/services/${SERVICE_NAME}/components/${COMPONENT_NAME}
PUT 请求体:
{ "name": "${COMPONENT_NAME}", "number_of_containers": ${COUNT} }
举例来说:
{ "name": "sleeper", "number_of_containers": 2 }
停止一个服务
停止一个服务将停止该服务的所有容器和关联的 ApplicationMaster,但不会删除服务的状态,如在 HDFS 上的服务的根目录。
PUT http://localhost:8088/app/v1/services/${SERVICE_NAME}
PUT 请求体:
{ "name": "${SERVICE_NAME}", "state": "STOPPED" }
重启一个停止的服务
重启一个停止的服务非常容易:
PUT http://localhost:8088/app/v1/services/${SERVICE_NAME}
PUT 请求体:
{ "name": "${SERVICE_NAME}", "state": "STARTED" }
销毁一个服务
在停止服务之外,它还会删除该服务在 HDFS 上的根目录以及在 Yarn Service Registry 里的记录。
DELETE http://localhost:8088/app/v1/services/${SERVICE_NAME}
嵌入 Yarn UI2 的服务 UI 和 Timeline Service v2
A new service tab is added in the YARN UI2 specially to show YARN Services in a first class manner. The services framework posts the data into TimelineService and the service UI reads data from TimelineService to render its content.
Enable Timeline Service v2
Please refer to TimeLineService v2 doc for how to enable Timeline Service v2.
Enable new YARN UI
Set below config in yarn-site.xml and start ResourceManager. If you are building from source code, make sure you use -Pyarn-ui in the mvn command - this will generate the war file for the new YARN UI.
<property> <description>To enable RM web ui2 application.</description> <name>yarn.webapp.ui2.enable</name> <value>true</value> </property>
安全地运行
YARN service framework supports running in a secure (kerberized) environment. User needs to specify the kerberos principal name and keytab when they launch the service. E.g. A typical configuration looks like below:
{ "name": "sample-service", ... ... "kerberos_principal" : { "principal_name" : "hdfs-demo/[email protected]", "keytab" : "file:///etc/security/keytabs/hdfs.headless.keytab" } }
Note that _HOST is required in the principal_name field because Hadoop client validates that the server’s (in this case, the AM’s) principal has hostname present when communicating to the server. * principal_name : the principal name of the user who launches the service * keytab : URI of the keytab. Currently supports only files present on the bare host. * URI starts with file:// - A path on the local host where the keytab is stored. It is assumed that admin pre-installs the keytabs on the local host before AM launches.
用 Docker 运行
The above example is only for a non-docker container based service. YARN Service Framework also provides first-class support for managing docker based services. Most of the steps for managing docker based services are the same except that in docker the Artifact type for a component is DOCKER and the Artifact id is the name of the docker image. For details in how to setup docker on YARN, please check Docker on YARN.
With docker support, it also opens up a set of new possibilities to implement features such as discovering service containers on YARN with DNS. Check ServiceDiscovery for more details.
原文地址:https://www.cnblogs.com/shishaochen/p/9657008.html