当前位置:   article > 正文

[JMX]jmx监控hadoop3.x和Hadoop2.x(一步到位)_hadoop jmx

hadoop jmx

背景

Prometheus+jmx_prometheus_javaagent-0.16.1.jar+hadoop3.2.1

jmx监控Hadoop3.x

1 环境的准备

jmx下载地址:https://repo1.maven.org/maven2/io/prometheus/jmx/jmx_prometheus_javaagent/

Prometheus下载地址:
https://prometheus.io/download/

hadoop下载地址:
https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/
安装过程就不一一赘述了,本文着重jmx使用

2 jmx在hadoop中的编写(或见 一步到位)

2.1 hdfs——jmx

[root@bdp01 bin]# pwd
/opt/hadoop/bin
[root@bdp01 bin]# ll
total 1040
-rwxrwxrwx. 1 1001 mysql 442480 Sep 11  2019 container-executor
-rwxrwxrwx. 1 1001 mysql   8707 Sep 10  2019 hadoop
-rwxrwxrwx. 1 1001 mysql  11265 Sep 10  2019 hadoop.cmd
-rwxrwxrwx. 1 1001 mysql  12573 May  7 14:36 hdfs
-rwxrwxrwx. 1 1001 mysql   8081 Sep 11  2019 hdfs.cmd
-rw-r--r--. 1 root root       0 May  5 17:45 kill
-rwxrwxrwx. 1 1001 mysql   6240 May  7 10:59 mapred
-rwxrwxrwx. 1 1001 mysql   6311 Sep 11  2019 mapred.cmd
-rw-------. 1 root root       0 May  5 17:45 nohup.out
-rwxrwxrwx. 1 1001 mysql  29184 Sep 11  2019 oom-listener
-rwxrwxrwx. 1 1001 mysql 484264 Sep 11  2019 test-container-executor
-rwxrwxrwx. 1 1001 mysql  13157 May  7 15:34 yarn
-rwxrwxrwx. 1 1001 mysql  12840 Sep 11  2019 yarn.cmd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
vi hdfs
  • 1

如图
在这里插入图片描述

## hdfs  monitor
export HADOOP_NAMENODE_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=9221 -javaagent:/opt/hadoop/jmx_prometheus_javaagent-0.16.1.jar=5221:/opt/hadoop/nn.yaml $HADOOP_NAMENODE_OPTS"

export HADOOP_DATANODE_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=9222 -javaagent:/opt/hadoop/jmx_prometheus_javaagent-0.16.1.jar=5222:/opt/hadoop/dn.yaml $HADOOP_DATANODE_OPTS"

export HADOOP_JOURNALNODE_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=9225 -javaagent:/opt/hadoop/jmx_prometheus_javaagent-0.16.1.jar=5225:/opt/hadoop/journalnode.yaml $HADOOP_JOURNALNODE_OPTS"

export HADOOP_ZKFC_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=9224 -javaagent:/opt/hadoop/jmx_prometheus_javaagent-0.16.1.jar=5224:/opt/hadoop/zkfc.yaml $HADOOP_ZKFC_OPTS"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.2 yarn——jmx

[root@bdp01 bin]# ll
total 1040
-rwxrwxrwx. 1 1001 mysql 442480 Sep 11  2019 container-executor
-rwxrwxrwx. 1 1001 mysql   8707 Sep 10  2019 hadoop
-rwxrwxrwx. 1 1001 mysql  11265 Sep 10  2019 hadoop.cmd
-rwxrwxrwx. 1 1001 mysql  12573 May  7 14:36 hdfs
-rwxrwxrwx. 1 1001 mysql   8081 Sep 11  2019 hdfs.cmd
-rw-r--r--. 1 root root       0 May  5 17:45 kill
-rwxrwxrwx. 1 1001 mysql   6240 May  7 10:59 mapred
-rwxrwxrwx. 1 1001 mysql   6311 Sep 11  2019 mapred.cmd
-rw-------. 1 root root       0 May  5 17:45 nohup.out
-rwxrwxrwx. 1 1001 mysql  29184 Sep 11  2019 oom-listener
-rwxrwxrwx. 1 1001 mysql 484264 Sep 11  2019 test-container-executor
-rwxrwxrwx. 1 1001 mysql  13157 May  7 15:34 yarn
-rwxrwxrwx. 1 1001 mysql  12840 Sep 11  2019 yarn.cmd
[root@bdp01 bin]# pwd
/opt/hadoop/bin
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

如图
在这里插入图片描述

vi yarn
  • 1
export YARN_RESOURCEMANAGER_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=6464 -javaagent:/opt/hadoop/jmx_prometheus_javaagent-0.16.1.jar=17104:/opt/hadoop/rm.yaml $YARN_RESOURCEMANAGER_OPTS"

export YARN_NODEMANAGER_OPTS="-Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.port=6474 -javaagent:/opt/hadoop/jmx_prometheus_javaagent-0.16.1.jar=17105:/opt/hadoop/nm.yaml $YARN_NODEMANAGER_OPTS"
  • 1
  • 2
  • 3

3.jmx相关参数的yaml文件编写

如图把jar包放到hdfs和yarn配置的相同路径位置,并编写yaml文件。
在这里插入图片描述
举两个例子,其实只要端口号修改一下,跟上面hdfs和yarn端口对应就行(也可以看后面的最简yaml编写)

vi nn.yaml
  • 1
startDelaySeconds: 0
hostPort: 192.168.x.xxx:9221
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
  • 1
  • 2
  • 3
  • 4
  • 5
 vi dn.yaml
  • 1
startDelaySeconds: 0
hostPort: 192.168.0.101:9222
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
  • 1
  • 2
  • 3
  • 4
  • 5

4.Prometheus部分

 vi prometheus.yml
  • 1

这样写的好处是今后可以动态修改Prometheus配置,无需重启Prometheus

 - job_name: 'hdfs'
    scrape_interval: 80s
    scrape_timeout: 60s
    file_sd_configs:
     - files:
       - /opt/prometheus/prom/hdfs.json
       refresh_interval: 5s

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

上文中有个json文件,我编写了一个json,举个hdfs的例子。hdfs包括namenode,datanode,journalnode和zkfc
在这里插入图片描述

vi hdfs.json
  • 1
[
  {
      "targets": [
         "192.168.x.xxx:5221"
      ],
      "labels": {
         "project_name": "namenode"
      }
   },
 {
      "targets": [
         "192.168.x.xxx:5222"
      ],
      "labels": {
         "project_name": "datanode"
      }
   },
   {
      "targets": [
         "192.168.x.xxx:5225"
      ],
      "labels": {
         "project_name": "historyserver"
      }
   },
   {
      "targets": [
         "192.168.x.xxx:5224"
      ],
      "labels": {
         "project_name": "zkfc"
      }
   }
]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

5.最后操作启停

hdfs yarn Prometheus 重启
查看Prometheus
在这里插入图片描述
如果安装成功,http://ip:port也会有数据,如图
在这里插入图片描述

一步到位:Hadoop3.x的jmx配置在hadoop-env.sh,直接重启角色

export HADOOP_NAMENODE_OPTS=" -javaagent:/opt/hadoop/jmx_prometheus_javaagent-0.16.1.jar=5229:/opt/hadoop/nn.yaml $HADOOP_NAMENODE_OPTS"

  • 1
  • 2

在这里插入图片描述
在这里插入图片描述

一步到位:jmx监控hadoop2.x

vi etc/hadoop/hadoop-env.sh
  • 1
export HADOOP_IDENT_STRING=$USER
export HADOOP_JOURNALNODE_OPTS="-javaagent:/opt/bdp/monitor/jmx_prometheus_javaagent-0.16.1.jar=2101:/opt/bdp/monitor/hadoop/journalnode.yaml $HDFS_JOURNALNODE_OPTS"
export HADOOP_NAMENODE_OPTS="-javaagent:/opt/bdp/monitor/jmx_prometheus_javaagent-0.16.1.jar=2012:/opt/bdp/monitor/hadoop/namenode.yaml $HDFS_NAMENODE_OPTS"
export JAVA_HOME=/usr/local/java
export HADOOP_DATANODE_OPTS=" -javaagent:/opt/bdp/monitor/jmx_prometheus_javaagent-0.16.1.jar=2014:/opt/bdp/monitor/hadoop/datanode.yaml $HDFS_DATANODE_OPTS"

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

然后启动对应的角色,用浏览器访问 http://ip:port就可以 ,如http:192.168.80.161:2101,
或者shell命令: curl http:192.168.80.161:2101

最简yanl文件编写

栗子:

vi /opt/bdp/monitor/hadoop/datanode.yaml
  • 1
rules:
    - pattern: '.*'
  • 1
  • 2
vi /opt/bdp/monitor/hadoop/namenode.yaml
  • 1
rules:
    - pattern: '.*'
  • 1
  • 2

此时的jmx监控如下:只有一个端口号需要传入

export HADOOP_NAMENODE_OPTS="-javaagent:/opt/bdp/monitor/jmx_prometheus_javaagent-0.16.1.jar=2012:/opt/bdp/monitor/hadoop/namenode.yaml $HDFS_NAMENODE_OPTS"
  • 1

其他

bash -x  hdfs --daemon stop datanode
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/人工智能uu/article/detail/941655
推荐阅读
相关标签
  

闽ICP备14008679号