Apache ZooKeeper 是一个分布式应用程序协调服务;用于维护配置信息、命名、提供分布式同步和组服务。
Zookeeper 官网:https://zookeeper.apache.org/
Zookeeper 3.8.3:https://zookeeper.apache.org/doc/r3.8.3/index.html
Zookeeper Getting Started:https://zookeeper.apache.org/doc/r3.8.3/zookeeperStarted.html
Prometheus 官网:https://prometheus.io/
Prometheus 文档:https://prometheus.io/docs/introduction/overview/
Grafana 官网:https://grafana.com/oss/grafana/
Grafana 文档:https://grafana.com/docs/grafana/latest/?pg=oss-graf&plcmt=hero-btn-2
ZooKeeper Monitor:https://zookeeper.apache.org/doc/r3.6.4/zookeeperMonitor.html
CentOS7安装部署Java11:https://blog.csdn.net/u011424614/article/details/132418561
CentOS基础操作命令:https://blog.csdn.net/u011424614/article/details/94555916
端口 | 作用 |
---|---|
2181 | 客户端连接端口,用于客户端与 ZooKeeper 集群通信 |
2888 | 用于集群内部服务器之间的 Leader 选举 |
3888 | 用于集群内部服务器之间的复制(数据同步) |
机器名 | IP | 节点部署 |
---|---|---|
zk-cluster-01 | 192.168.249.141 | zk 节点 |
zk-cluster-02 | 192.168.249.142 | zk 节点 |
zk-cluster-03 | 192.168.249.143 | zk 节点 |
zk-cluster-04 | 192.168.249.144 | 监控节点(Prometheus + Grafana) |
# 141 执行
hostnamectl set-hostname zk-cluster-01 --static
hostnamectl set-hostname zk-cluster-01 --transient
# 142 执行
hostnamectl set-hostname zk-cluster-02 --static
hostnamectl set-hostname zk-cluster-02 --transient
# 143 执行
hostnamectl set-hostname zk-cluster-03 --static
hostnamectl set-hostname zk-cluster-03 --transient
# 144 执行
hostnamectl set-hostname zk-cluster-04 --static
hostnamectl set-hostname zk-cluster-04 --transient
# 查询状态
hostnamectl status
cat > /etc/hosts <
在 4 台服务器上执行
#--关闭防火墙
systemctl stop firewalld.service
#--开机禁用防火墙
systemctl disable firewalld.service
#--防火墙状态
systemctl status firewalld.service
在 4 台服务器上安装JDK
/opt/java/jdk-11.0.19
在 141 服务器上执行
mkdir /opt/zookeeper
cd /opt/zookeeper
# 下载
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.8.3/apache-zookeeper-3.8.3-bin.tar.gz --no-check-certificate
# 解压
tar -xzf apache-zookeeper-3.8.3-bin.tar.gz
# 修改文件夹名称
mv /opt/zookeeper/apache-zookeeper-3.8.3-bin /opt/zookeeper/apache-zookeeper-3.8.3
# 进入安装目录
cd /opt/zookeeper/apache-zookeeper-3.8.3
cat > /opt/zookeeper/apache-zookeeper-3.8.3/conf/zoo.cfg <
mkdir -p /data/zookeeper
chown -R `whoami` /data/zookeeper
cd /opt/zookeeper/apache-zookeeper-3.8.3
# 启动
bin/zkServer.sh start
# 停止
bin/zkServer.sh stop
bin/zkServer.sh status
cd /opt/zookeeper/apache-zookeeper-3.8.3
bin/zkCli.sh -server 192.168.249.141:2181
# 创建数据
create /test mydata
# 获取数据
get /test
# 列出全部节点
ls /
# 更新数据
set /test newdata
# 删除数据
delete /test
# 退出客户端
quit
cat > /etc/systemd/system/zookeeper.service <
systemctl daemon-reload
systemctl start zookeeper.service
systemctl enable zookeeper.service
systemctl status zookeeper.service
在 141 服务器上执行
mkdir /opt/zookeeper
cd /opt/zookeeper
# 下载
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.8.3/apache-zookeeper-3.8.3-bin.tar.gz --no-check-certificate
# 解压
tar -xzf apache-zookeeper-3.8.3-bin.tar.gz
# 修改文件夹名称
mv /opt/zookeeper/apache-zookeeper-3.8.3-bin /opt/zookeeper/apache-zookeeper-3.8.3
# 进入安装目录
cd /opt/zookeeper/apache-zookeeper-3.8.3
在 141 服务器上执行
cat > /opt/zookeeper/apache-zookeeper-3.8.3/conf/zoo.cfg <
在 142、143 服务器上执行
mkdir /opt/zookeeper
在 141 服务器上执行
scp -r /opt/zookeeper/apache-zookeeper-3.8.3 [email protected]:/opt/zookeeper
scp -r /opt/zookeeper/apache-zookeeper-3.8.3 [email protected]:/opt/zookeeper
在 141、142、143 服务器上执行
mkdir -p /data/zookeeper
chown -R `whoami` /data/zookeeper
# 141 服务器
echo "1" > /data/zookeeper/myid
# 142 服务器
echo "2" > /data/zookeeper/myid
# 143 服务器
echo "3" > /data/zookeeper/myid
在 141、142、143 服务器上执行
cd /opt/zookeeper/apache-zookeeper-3.8.3
# 启动
bin/zkServer.sh start
# 停止
bin/zkServer.sh stop
bin/zkServer.sh status
在 141 服务器上执行
cd /opt/zookeeper/apache-zookeeper-3.8.3
bin/zkCli.sh -server 192.168.249.141:2181
# 创建数据
create /test mydata
# 获取数据
get /test
# 列出全部节点
ls /
# 更新数据
set /test newdata
# 删除数据
delete /test
# 退出客户端
quit
在 141、142、143 服务器上执行
cat > /etc/systemd/system/zookeeper.service <
systemctl daemon-reload
systemctl start zookeeper.service
systemctl enable zookeeper.service
systemctl status zookeeper.service
PrettyZoo-GitHub:https://github.com/vran-dev/PrettyZoo
PrettyZoo 是一个基于 Apache Curator 和 JavaFX 实现的 Zookeeper 图形化管理客户端。
ZooInspector:https://issues.apache.org/jira/secure/attachment/12436620/ZooInspector.zip
Apache ZooKeeper 官方提供的一个简单的 GUI 工具,用于浏览和编辑存储在 ZooKeeper 中的数据。
Prometheus 官网:https://prometheus.io/
Prometheus 文档:https://prometheus.io/docs/introduction/overview/
Grafana 官网:https://grafana.com/oss/grafana/
Grafana 文档:https://grafana.com/docs/grafana/latest/?pg=oss-graf&plcmt=hero-btn-2
ZooKeeper Monitor:https://zookeeper.apache.org/doc/r3.6.4/zookeeperMonitor.html
Zookeeper 从 3.6.0 开始支持 Prometheus 和 Grafana 进行监控。
Prometheus 是一个开源系统监控和警报工具包。
Grafana 是一款多平台开源分析和交互式可视化网络应用程序。
在 141、142、143 服务器上执行
cat > /opt/zookeeper/apache-zookeeper-3.8.3/conf/zoo.cfg <
systemctl stop zookeeper.service
systemctl daemon-reload
systemctl start zookeeper.service
在 144 服务器上执行
# 安装目录
mkdir /opt/prometheus
cd /opt/prometheus
# 下载
wget https://github.com/prometheus/prometheus/releases/download/v2.48.1/prometheus-2.48.1.linux-amd64.tar.gz --no-check-certificate
# 解压
tar xvfz prometheus-*.tar.gz
# 修改文件夹名称
mv /opt/prometheus/prometheus-2.48.1.linux-amd64 /opt/prometheus/prometheus-2.48.1
# 进入安装目录
cd /opt/prometheus/prometheus-2.48.1
vim prometheus.yml
- job_name: "Zookeeper-QuarumPeermain"
static_configs:
- targets: ['zk-cluster-01:7000','zk-cluster-02:7000','zk-cluster-03:7000']
./prometheus --config.file=prometheus.yml
http://192.168.249.144:9090/status
http://192.168.249.144:9090/targets
cat > /etc/systemd/system/prometheus.service <
systemctl daemon-reload
systemctl start prometheus.service
systemctl enable prometheus.service
systemctl status prometheus.service
在 144 服务器上执行
tee /etc/yum.repos.d/grafana.repo <
yum install grafana
systemctl start grafana-server
systemctl enable grafana-server.service
systemctl status grafana-server
http://192.168.249.144:3000
zookeeper-by-prometheus:https://grafana.com/grafana/dashboards/10465-zookeeper-by-prometheus/
命令 | 说明 |
---|---|
systemctl daemon-reload | 重新加载服务配置 |
systemctl start zookeeper.service | 启动服务 |
systemctl enable zookeeper.service | 开机自启动服务 |
systemctl status zookeeper.service | 查询服务状态 |
systemctl stop zookeeper.service | 停止服务 |
systemctl restart zookeeper.service | 重启服务 |
systemctl disable zookeeper.service | 禁用开机自启动服务 |