首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ambari 自定义服务启动成功后,依旧显示停止状态的解决方案

Ambari 自定义服务启动成功后,依旧显示停止状态的解决方案

作者头像
create17
发布2019-08-23 14:15:50
2.4K2
发布2019-08-23 14:15:50
举报
1、概述

如果遇到该情况,首先前往 /var/log/ambari-agent/ambari-agent.log 查看日志输出。

服务安装后,每隔大约 60s 会执行 status() 方法。如果执行 status() 方法的过程中报错,则在 Ambari 页面上会显示服务已停止。如果执行 status() 方法的过程中没报错,则在 Ambari 页面上显示服务正常。

通常在 status() 方法中,我们会使用 Ambari 提供的 resource_management 模块里的 check_process_status() 来判断服务的状态。

check_process_status() 通过检测一个 pid 文件里面的进程号,来判断服务的启动状态。通常 pid 文件内只有一个进程号,如 12168 。

2、问题示例分析

2.1、报错

以自定义服务 JanusGraph 为例,status() 方法是这样写的:

from resource_management import *

def status(self, env):
    import graphexp_params
    env.set_params(graphexp_params)
    check_process_status(graphexp_params.graphexp_nginx_pid_file)

graphexp_params.py 文件的局部内容:

from resource_management import *

config = Script.get_config()
# graphexp的nginx pid文件路径
graphexp_pid_dir = config['configurations']['graphexp-server']['graphexp_pid_dir']
# graphexp的nginx pid文件路径
graphexp_nginx_pid_file = os.path.join(graphexp_pid_dir, 'graphexp_nginx.pid')

上述代码是动态获取 Ambari 页面上的 graphexp_pid_dir 配置项,然后拼凑成一个 pid 文件路径,这个 pid 文件内容只有 graphexp 组件的进程号。

结果出错了,根据 /var/log/ambari-agent/ambari-agent.log 日志输出,发现在 status_params.py 里面获取 graphexp-server.xml 文件内的参数值报错,如下图所示:

2.2、问题排查

在 status() 方法下,输出 config['configurations'] 发现只能打印出:

ams-hbase-env,infra-solr-env,hbase-env,ams-env,elastic-env,janusgraph-env,ams-grafana-env,hadoop-env,zookeeper-env,cluster-env

以上这些值,没有 graphexp-server 项。

而在 start() 方法里面打印有很多,所有的 configurations 的 xml 文件都被加载到了:

ranger-hdfs-audit,ssl-client,infra-solr-log4j,ranger-hdfs-policymgr-ssl,ams-hbase-site,elastic-config,ranger-hbase-audit,hdfs-logsearch-conf,ams-grafana-env,ranger-hdfs-security,ams-ssl-client,infra-solr-env,ranger-hdfs-plugin-properties,hbase-policy,ams-logsearch-conf,ams-hbase-security-site,hdfs-site,ams-env,ams-site,ams-hbase-policy,janusgraph-env,hadoop-metrics2.properties,hadoop-policy,hdfs-log4j,hbase-site,infra-logsearch-conf,ranger-hbase-plugin-properties,ams-grafana-ini,graphexp-server,ams-ssl-server,infra-solr-xml,ams-log4j,ams-hbase-env,core-site,infra-solr-security-json,gremlin-server,janusgraph-hbase-solr,infra-solr-client-log4j,hbase-logsearch-conf,hadoop-env,zookeeper-log4j,hbase-log4j,postgresql,ssl-server,hbase-env,zoo.cfg,elastic-env,ranger-hbase-policymgr-ssl,zookeeper-logsearch-conf,cluster-env,zookeeper-env,ams-hbase-log4j,ranger-hbase-security

所以猜测在 status() 方法里面,只能识别 xxx-env.xml 里面的配置内容。但是 ambari2.7 的自定义服务没有这个问题,只在 ambari2.6 上出现了。

2.3、解决办法

新建 graphexp-env.xml 文件,将 graphexp_pid_dir 配置项添加到该文件内。graphexp_params.py 文件的 graphexp_pid_dir 写法修改为:

# graphexp的nginx pid文件路径
graphexp_pid_dir = config['configurations']['graphexp-env']['graphexp_pid_dir']
# graphexp的nginx pid文件路径
graphexp_nginx_pid_file = os.path.join(graphexp_pid_dir, 'graphexp_nginx.pid')

小结:在 status() 方法内,获取 graphexp-env.xml 文件内的配置,只有 xxx-env.xml 的内容才可以被 status() 方法加载到。

3、status()方法调试建议

由于 status() 是轮询调用,且目前还不知道日志输出的具体位置(没有输出到 ambari-agent.log 里面),所以可以用 Execute("echo {0} >> /tmp/test.log".format(status_params.gtm_standby_pid_file)) 命令来输出需要的参数值。同时也可以根据上述 Execute 语句位置来判断代码具体的报错行数,方便定位代码报错地点。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-08-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 大数据实战演练 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 2、问题示例分析
    • 2.1、报错
      • 2.2、问题排查
        • 2.3、解决办法
        • 3、status()方法调试建议
        相关产品与服务
        Grafana 服务
        Grafana 服务(TencentCloud Managed Service for Grafana,TCMG)是腾讯云基于社区广受欢迎的开源可视化项目 Grafana ,并与 Grafana Lab 合作开发的托管服务。TCMG 为您提供安全、免运维 Grafana 的能力,内建腾讯云多种数据源插件,如 Prometheus 监控服务、容器服务、日志服务 、Graphite 和 InfluxDB 等,最终实现数据的统一可视化。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档