Kafka之--自动启动zookeeper & kafka 脚本
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 脚本的更多相关文章
- bat脚本:windows下一键启动zookeeper+kafka
bat脚本:windows下一键启动zookeeper+kafka 把下面两行代码存为bat文件,双击执行即可.注意更改相应的目录 这里用ping来控制时间(先zookeeper,ping 4 次后 ...
- Zookeeper+Kafka完全分布式实战部署
Zookeeper+Kafka完全分布式实战部署 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 其实我之前部署过kafak和zookeeper的完全分布式,集群是可以正常使用没错, ...
- Redis&MongoDB&Zookeeper&Kafka
目录 Redis MongoDB Zookeeper Kafka Redis 概念 Redis是NoSQL中比较常典型的一个非关系型数据库,在日常工作中也是最为常见的.Redis是一个由C语言编写的开 ...
- kafak manager + zookeeper + kafka 消费队列快速清除
做性能测试时,kafka消息队列比较长,让程序自己消费完毕需要等待很长时间.就需要快速清理kafka队列 清理方式把 这kafak manager + zookeeper + kafka 这些应用情况 ...
- Docker搭建Zookeeper&Kafka集群
最近在学习Kafka,准备测试集群状态的时候感觉无论是开三台虚拟机或者在一台虚拟机开辟三个不同的端口号都太麻烦了(嗯..主要是懒). 环境准备 一台可以上网且有CentOS7虚拟机的电脑 为什么使用虚 ...
- zookeeper/kafka的部署
Ubuntu中安装zookeeper及kafka并配置环境变量 首先安装zookeeper zookeeper需要jdk环境,请在jdk安装完成的情况下安装zookeeper1.从官网下载zook ...
- window环境搭建zookeeper,kafka集群
为了演示集群的效果,这里准备一台虚拟机(window 7),在虚拟机中搭建了单IP多节点的zookeeper集群(多IP节点的也是同理的),并且在本机(win 7)和虚拟机中都安装了kafka. 前期 ...
- zookeeper+kafka集群安装之二
zookeeper+kafka集群安装之二 此为上一篇文章的续篇, kafka安装需要依赖zookeeper, 本文与上一篇文章都是真正分布式安装配置, 可以直接用于生产环境. zookeeper安装 ...
- zookeeper+kafka集群安装之一
zookeeper+kafka集群安装之一 准备3台虚拟机, 系统是RHEL64服务版. 1) 每台机器配置如下: $ cat /etc/hosts ... # zookeeper hostnames ...
随机推荐
- 预测汽车级Linux专业技术的需求
预测汽车级Linux专业技术的需求 Anticipating need for Automotive Grade Linux expertise 在听了多年汽车级Linux(AGL)及其所有潜力之后, ...
- 解决:django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not 的方法
错误类型: 该错误是在在创建Django工程时出现遇到的错误 完整报错信息:(博文标题输入长度有限制) django.core.exceptions.ImproperlyConfigured: Req ...
- 【NX二次开发】Block UI对话框-代码生成部分
常规: 语言:生成的代码语言 生成附注:是否生成注释代码 生成特定与块的代码: 输入点: 回调:对话框通过回调函数调用,例如通过另一个对话框的按钮调用本对话框 菜单:对话框通过菜单调用 用户出口:对话 ...
- 【NX二次开发】uf5945获得旋转矩阵、uf5947根据变换矩阵移动或复制对象
返回一个矩阵,可以绕任意轴旋转. 与uf5947结合可以将对象沿着任意轴进行旋转.不是所有对象都能用uf5947变换,带参的实体.部件都不可以用此函数变换.下面是旋转WCS的例子. extern Dl ...
- 如何让vscode C++ 终端不再显示调试启动信息
按照微软的官方文档(https://go.microsoft.com/fwlink/?LinkID=533484#vscode)配置好C++环境之后. 每次按F5都会在终端输出,但是会附加一串信息.例 ...
- PTA7~9题目集总结与归纳
前言: 总结三次题目集的知识点.题量.难度等情况. 目录: 题目集7(7-1).(7-2)两道题目的递进式设计分析总结 题目集8和题目集9两道ATM机仿真题目的设计思路分析总结 一. 题目集7(7-1 ...
- VBS脚本编程(2)——运算符
算数运算符 用于执行数学计算的运算符. 1.加法运算符( + ) 计算两个数之和. 2.减法运算符( - ) 计算两个数值的差或表示数值表达式的负值. 3.乘法运算符(*) 计算两个数之积. 4.除法 ...
- Vue(1)Vue安装与使用
前言 Vue(读音/vjuː/,类似于view) 是一套用于构建前后端分离的框架.刚开始是由国内优秀选手尤雨溪开发出来的,目前是全球"最"流行的前端框架.使用vue开发网页很简单, ...
- ES7扩展
前一段时间小编一直在更新javascript es6版本的部分新语法和新特性,鉴于现在js一直在更新,接下来小编将和大家一起进步,一块探究js的新特性.今天小编就和大家一起来看看es7更新的语法和新特 ...
- [翻译]Go与C#对比 第三篇:编译、运行时、类型系统、模块和其它的一切
Go vs C#, Part 3: Compiler, Runtime, Type System, Modules, and Everything Else | by Alex Yakunin | S ...