1) 首先配置SSH免密登录,在这里我用kafka(151)这台机器来作为启动脚本的存放和执行机器

[root@kafaka3 .ssh]# pwd

#生成SSH KEY
/root/.ssh
[root@kafaka .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
a7:82:b2:ce:c2:e0:21:7d:4e:63:7c:03:d5:3c:98:25 root@kafaka
The key's randomart image is:
+--[ RSA 2048]----+
| E*. |
| +.+ |
| . . |
| . |
| . . . S . |
|o.. *.o o |
|= o=.o... |
|.+ o. . |
| o+ |
+-----------------+
[root@kafaka .ssh]# ls -l
total 8
-rw------- 1 root root 1675 Jul 13 20:12 id_rsa
-rw-r--r-- 1 root root 393 Jul 13 20:12 id_rsa.pub #复制到另外两台机器上
[root@kafaka .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.56.152
The authenticity of host '192.168.56.152 (192.168.56.152)' can't be established.
ECDSA key fingerprint is e6:c4:48:fa:0d:76:3e:2c:3b:60:e7:61:90:ad:9a:ee.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.56.152's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@192.168.56.152'"
and check to make sure that only the key(s) you wanted were added. [root@kafaka .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.56.153
The authenticity of host '192.168.56.153 (192.168.56.153)' can't be established.
ECDSA key fingerprint is e6:c4:48:fa:0d:76:3e:2c:3b:60:e7:61:90:ad:9a:ee.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.56.153's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@192.168.56.153'"
and check to make sure that only the key(s) you wanted were added. #修改kafka2 & kafka3目录和文件的权限。如果不修改,可能无法正常免密登录成功
#kafka2文件权限修改
[root@kafaka2 .ssh]# chmod 700 ~/.ssh
[root@kafaka2 .ssh]# chmod 600 ~/.ssh/authorized_keys
#kafka3文件权限修改
[root@kafaka3 .ssh]# chmod 700 ~/.ssh
[root@kafaka3 .ssh]# chmod 600 ~/.ssh/authorized_keys #免密登录测试
[root@kafaka .ssh]# ssh 192.168.56.152
Last login: Tue Jul 13 20:04:08 2021 from 192.168.56.1
[root@kafaka2 ~]# exit
logout
Connection to 192.168.56.152 closed.

2)启动脚本内容

2.1)启动zookeeper脚本

[root@kafaka ~]# cat zooman.sh
#! /bin/bash
case $1 in
"start"){
echo " --------Start 192.168.56.151 Zookeeper-------"
zkServer.sh start for i in 192.168.56.152 192.168.56.153
do
echo " --------Start $i Zookeeper-------"
ssh $i "source /etc/profile; zkServer.sh start"
done
};;
"stop"){
echo " --------Stop 192.168.56.151 Zookeeper-------"
zkServer.sh stop
for i in 192.168.56.152 192.168.56.153
do
echo " --------Stop $i Zookeeper-------"
ssh $i "source /etc/profile; zkServer.sh stop"
done
};;
"status"){
echo " --------192.168.56.151 Zookeeper Status-------"
zkServer.sh status
for i in 192.168.56.152 192.168.56.153
do
echo " --------$i Zookeeper status-------"
ssh $i "source /etc/profile; zkServer.sh status"
done
};;
esac

可以用zooman.sh start启动。启动完后,可以用zooman.sh status查看zookeeper状态

[root@kafaka ~]# ./zooman.sh status
--------192.168.56.151 Zookeeper Status-------
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
--------192.168.56.152 Zookeeper status-------
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
--------192.168.56.153 Zookeeper status-------
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/apache-zookeeper-3.7.0-bin/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower

4)kafka启动停止脚本

[root@kafaka ~]# cat kfman.sh
#! /bin/bash
case $1 in
"start"){
echo " --------Start 192.168.56.151 Kafka Broker $j-------"
# 用于KafkaManager监控
export JMX_PORT=9988 && /usr/local/kafka_2.13-2.7.0/bin/kafka-server-start.sh -daemon /usr/local/kafka_2.13-2.7.0/config/server.properties for i in 192.168.56.152 192.168.56.153
do
echo " --------Start $i Kafka Broker $j-------"
# 用于KafkaManager监控
ssh $i "export JMX_PORT=9988 && /usr/local/kafka_2.13-2.7.0/bin/kafka-server-start.sh -daemon /usr/local/kafka_2.13-2.7.0/config/server.properties "
done
};;
"stop"){
echo " --------Stop 192.168.56.151 Kafka-------"
/usr/local/kafka_2.13-2.7.0/bin/kafka-server-stop.sh stop for i in 192.168.56.152 192.168.56.153
do
echo " --------Stop $i Kafka-------"
ssh $i "/usr/local/kafka_2.13-2.7.0/bin/kafka-server-stop.sh stop"
done
};;
esac

5)启动完成后,可以用如下命令查看brokers

(注:因为用daemon启动,一台物理服务器只能启动一个实例,所以这里我只启动了3个broker。

至于能否多个我还没研究透,如果有知道的朋友也请回复告知我一声)

[zk: localhost:2181(CONNECTED) 0] ls /
[admin, brokers, cluster, config, consumers, controller, controller_epoch, feature, isr_change_notification, latest_producer_id_block, log_dir_event_notification, zookeeper]
[zk: localhost:2181(CONNECTED) 1] ls /brokers
[ids, seqid, topics]
[zk: localhost:2181(CONNECTED) 2] ls /brokers/ids
[0, 2, 4]
[zk: localhost:2181(CONNECTED) 3]

最后说明,因为我为了节约一台机器,所以脚本放在了其中的一台机器。

如果放在另一台不同的机器上,脚本可以写得更简洁,不需要分开本地与远程机器分别处理。

Kafka之--自动启动zookeeper & kafka 脚本的更多相关文章

  1. bat脚本:windows下一键启动zookeeper+kafka

    bat脚本:windows下一键启动zookeeper+kafka 把下面两行代码存为bat文件,双击执行即可.注意更改相应的目录 这里用ping来控制时间(先zookeeper,ping 4 次后 ...

  2. Zookeeper+Kafka完全分布式实战部署

    Zookeeper+Kafka完全分布式实战部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 其实我之前部署过kafak和zookeeper的完全分布式,集群是可以正常使用没错, ...

  3. Redis&MongoDB&Zookeeper&Kafka

    目录 Redis MongoDB Zookeeper Kafka Redis 概念 Redis是NoSQL中比较常典型的一个非关系型数据库,在日常工作中也是最为常见的.Redis是一个由C语言编写的开 ...

  4. kafak manager + zookeeper + kafka 消费队列快速清除

    做性能测试时,kafka消息队列比较长,让程序自己消费完毕需要等待很长时间.就需要快速清理kafka队列 清理方式把 这kafak manager + zookeeper + kafka 这些应用情况 ...

  5. Docker搭建Zookeeper&Kafka集群

    最近在学习Kafka,准备测试集群状态的时候感觉无论是开三台虚拟机或者在一台虚拟机开辟三个不同的端口号都太麻烦了(嗯..主要是懒). 环境准备 一台可以上网且有CentOS7虚拟机的电脑 为什么使用虚 ...

  6. zookeeper/kafka的部署

    Ubuntu中安装zookeeper及kafka并配置环境变量   首先安装zookeeper zookeeper需要jdk环境,请在jdk安装完成的情况下安装zookeeper1.从官网下载zook ...

  7. window环境搭建zookeeper,kafka集群

    为了演示集群的效果,这里准备一台虚拟机(window 7),在虚拟机中搭建了单IP多节点的zookeeper集群(多IP节点的也是同理的),并且在本机(win 7)和虚拟机中都安装了kafka. 前期 ...

  8. zookeeper+kafka集群安装之二

    zookeeper+kafka集群安装之二 此为上一篇文章的续篇, kafka安装需要依赖zookeeper, 本文与上一篇文章都是真正分布式安装配置, 可以直接用于生产环境. zookeeper安装 ...

  9. zookeeper+kafka集群安装之一

    zookeeper+kafka集群安装之一 准备3台虚拟机, 系统是RHEL64服务版. 1) 每台机器配置如下: $ cat /etc/hosts ... # zookeeper hostnames ...

随机推荐

  1. Imec推出高性能芯片的低成本冷却解决方案

    Imec推出高性能芯片的低成本冷却解决方案 Imec unveils low-cost cooling solution for high-performance chips 3D打印冷却器优于传统解 ...

  2. OpenCV开发实战1——抖音哈哈镜效果

    前言 在抖音中,我们经常看到各种抖音玩家都喜欢使用哈哈镜效果.那么什么是哈哈镜呢? 在现实生活中,哈哈镜是指一种表面凹凸不平的镜子,可以反应出人像及物体的扭曲面貌.简单点来说就是拉伸人脸(物件),或者 ...

  3. 如何让vscode C++ 终端不再显示调试启动信息

    按照微软的官方文档(https://go.microsoft.com/fwlink/?LinkID=533484#vscode)配置好C++环境之后. 每次按F5都会在终端输出,但是会附加一串信息.例 ...

  4. Linux之RPM包

    RPM:Redhat Package Manager 安装软件:rpm -ivh filename.rpm 升级软件:rpm -Uvh filename.rpm 卸载软件:r;pm -e filena ...

  5. 再试Hibernate框架

    几个月前因为学习需要第一次接触了Hibernate(之前一直在用MyBatis),后来觉得有点难,也急着找工作,所以就没继续学下去了.但是找工作的时候发现Hibernate的需求更高,使用率更高,所以 ...

  6. cos中的文件结构(DF/EF/MF/FID/AID/SFI..)

    转载自:https://blog.csdn.net/Enjoy_endless/article/details/75108349 刚开始接触CPU卡的时候,对于各种文件.应用的定义容易模糊不清,通常不 ...

  7. ES6 数组的方法

     数组的类 数组的类是Array 数组的定义 var arr=[元素] var arr=new Array(3) 数字3,代表有三个元素或者三个空位 如果数组定义采用 new 实例,类中跟的是一个数字 ...

  8. Unix、Linux 软件包管理快速入门对照:apt、brew、pkg、yum

    请访问原文链接:https://sysin.org/blog/apt-brew-pkg-yum/,查看最新版.原创作品,转载请保留出处. 作者:gc(at)sysin.org,主页:www.sysin ...

  9. 二、JavaSE语言基础之常量与变量

    1.常量   所谓常量值的是数据处理过程中值不能更改的数据. 2.变量   所谓变量值的是运算过程中值可以改变的数据,类似于代数中的未知数.   在Java语言中,使用变量时必须遵循先定义,而后赋值, ...

  10. ActiveMq 之JMS 看这一篇就够了

    什么是JMS MQ 全称:Java MessageService 中文:Java 消息服务. JMS 是 Java 的一套 API 标准,最初的目的是为了使应用程序能够访问现有的 MOM 系 统(MO ...