JMX监控zookeeper

JMX监控zookeeper

一.修改 zkServer.sh 参数ZOOMAIN

默认配置
JMX监控zookeeper
修改后配置
JMX监控zookeeper
修改说明:

是否建立远程连接,false可远程建立连接
-Dcom.sun.management.jmxremote.local.only=false
zookeeper地址
-Djava.rmi.server.hostname=127.0.0.1  
连接端口,并不是zookeeper端口,也不能和zookeeper端口冲突
 -Dcom.sun.management.jmxremote.port=2180 
 是否ssl连接,如果JMX无法ssl连接上zookeeper,需要改为false
 -Dcom.sun.management.jmxremote.ssl=false  
 是否开启访问权限
 -Dcom.sun.management.jmxremote.authenticate=true  
 设置访问权限,参考jdk目录/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/management/下该文件
 -Dcom.sun.management.jmxremote.access.file=/usr/local/data/zookeeper/conf/jmxremote.access  
 -Dcom.sun.management.jmxremote.password.file=/usr/local/data/zookeeper/conf/jmxremote.password  
 是否开日志
 -Dzookeeper.jmx.log4j.disable=true

如果不开启访问权限控制去掉以下三个配置:

 
 -Dcom.sun.management.jmxremote.authenticate=true  
 -Dcom.sun.management.jmxremote.access.file=/usr/local/data/zookeeper/conf/jmxremote.access  
 -Dcom.sun.management.jmxremote.password.file=/usr/local/data/zookeeper/conf/jmxremote.password  

二. 创建授权文件jmxremote.access和jmxremote.password

参考JDK文件说明
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/management/jmxremote.access
/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/jre/lib/management/jmxremote.password

zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ cd /usr/local/data/zookeeper/conf/
zhenglubiaodeMacBook-Pro:conf zlb$ ls -l
total 16
-rw-------  1 root  wheel  149  6 13 15:46 jmxremote.access
-rw-------  1 root  wheel   40  6 13 15:48 jmxremote.password
zhenglubiaodeMacBook-Pro:conf zlb$ sudo cat jmxremote.access 
monitorRole   readonly
controlRole   readwrite \
              create javax.management.monitor.*,javax.management.timer.* \
              unregister
zhenglubiaodeMacBook-Pro:conf zlb$ sudo cat jmxremote.password 
monitorRole  1234  
controlRole  123456
zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ 

必须修改这两个文件权限为:-rw------- (600) 只有拥有者有读写权限。

zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ cd /usr/local/data/zookeeper/conf/
zhenglubiaodeMacBook-Pro:conf zlb$ sudo chmod 600 jmxremote.*
zhenglubiaodeMacBook-Pro:conf zlb$ ls -l
total 16
-rw-------  1 root  wheel  149  6 13 15:46 jmxremote.access
-rw-------  1 root  wheel   40  6 13 15:48 jmxremote.password
zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ 

三.重启zookeeper

zkServer.sh restart
观察日志 zookeeper.out

四. JConsole连接

命令行输入

zhenglubiaodeMacBook-Pro:conf zlb$ 
zhenglubiaodeMacBook-Pro:conf zlb$ JConsole

弹出窗口 选择输入地址 连接端口 用户名 密码
JMX监控zookeeper

连接后
JMX监控zookeeper

五.了解JMX、JConsole

相关连接:

  1. JMX监控和管理Java虚拟机
  2. JMX技术概述
  3. Java教程中的JMX技术跟踪
  4. JMX文档
  5. Java管理扩展(JMX)技术
上一篇:linux命令总结:sed


下一篇:定义一个分数类,分子分母各为私有成员,