Zookeeper 3.8.0 集群安装及监控
Zookeeper 集群安装及监控
1. 前言
业务需要对Zookeeper集群进行监控,发现的方案有三种:
- JMX
- zookeeper exporter
- ZK Monitor(Since 3.6.0)
采用JMX 进行监控,可获取到的指标项不够丰富。Zookeeper Exporter监控可获得的指标项亦不太够丰富。从3.6.0之后,Zookeeper自带的Monitor结合Prometheus、Grafana可绘制出丰富的监控图表项。
2.下载并安装
- 下载并安装
# 下载
wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.8.0/apache-zookeeper-3.8.0-bin.tar.gz --no-check-certificate
# 安装
tar -zxvf pache-zookeeper-3.8.0-bin.tar.gz -C /opt
- 创建data目录并myid
mkdir data
echo 1 >> myid
- 修改zk配置文件
cp zoo_sample.cfg zoo.cfg
vi zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/opt/apache-zookeeper-3.8.0-bin/data
clientPort=2181
maxClientCnxns=1200
autopurge.snapRetainCount=10
autopurge.purgeInterval=24
server.1=192.168.2.53:2888:3888
server.2=192.168.2.35:2888:3888
server.3=192.168.2.45:2888:3888
# metrics
metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
metricsProvider.httpHost=0.0.0.0
metricsProvider.httpPort=7000
metricsProvider.exportJvmInfo=true
- 分发安装包并修改myid
scp -r /opt/apache-zookeeper-3.8.0-bin root@slave1:/opt
scp -r /opt/apache-zookeeper-3.8.0-bin root@slave2:/opt
echo 2 >> myid
echo 3 >> myid
3.启动
# 集群中每个机器逐个启动
zkServer.sh start
# 查看
zkServer.sh status
访问metrics地址: http://192.168.2.53:7000/metrics
4.接入Prometheus
# prometheus.yml
- job_name: ZOOKEEPER-QuarumPeermain
static_configs:
- targets: ['master:7000','slave1:7000','slave2:7000']
重启prometheus
systemctl restart prometheus
5. 接入Grafana
点击import,载入模板10465