1 解压kafka
创建一个kafka的文件夹,用户存放kafka文件
mkdir /usr/local/kafka
通过ftp工具把下载好的kafka安装包上传到kafka文件夹下。
解压:
cd /usr/local/kafka</pre>
tar -vxzf redis-3.2.10.tar.gz
解压完成
1.png2 修改配置
zookeeper相关
进入到kafka配置文件夹并编辑zookeeper配置
cd kafka_2.11-2.0.0/config
vim zookeeper.properties
设置zookeeper的数据存放位置以及端口:
# 数据的存放目录
dataDir=/tmp/zookeeper
# 端口,默认就是2181
clientPort=2181
kafka相关
编辑kafka配置
vim server.properties
修改kafka配置
# broker的全局唯一编号,不能重复
broker.id=0
# 监听
listeners=PLAINTEXT://10.168.1.213:9092
# 日志目录
log.dirs=/tmp/kafka-logs
# 配置zookeeper的连接(如果不是本机,需要该为ip或主机名)
zookeeper.connect=localhost:2181
2.png
1.3 启动
进入kafka根目录
cd /usr/local/kafka/kafka_2.11-2.0.0
启动zookeeper
./bin/zookeeper-server-start.sh -daemon ./config/zookeeper.properties &
启动kafka
./bin/kafka-server-start.sh -daemon ./config/server.properties &
查看是否启动成功
jps
3.png
1.4 设置开机启动
进入/etc/init.d/
目录下
cd /etc/init.d/
创建文件kafka
vim kafka
写入开机启动相关的脚本内容
#!/bin/bash
#chkconfig:2345 20 90
#description:kafka
#processname:kafka
### BEGIN INIT INFO
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: kafka server
# Description: kafka server.
### END INIT INFO
export JAVA_HOME=/usr/local/java/jdk1.8.0_181
export PATH=$JAVA_HOME/bin:$PATH
zookeeperStart(){
/usr/local/kafka/kafka_2.11-2.0.0/bin/zookeeper-server-start.sh -daemon /usr/local/kafka/kafka_2.11-2.0.0/config/zookeeper.properties &
}
kafkaStart(){
/usr/local/kafka/kafka_2.11-2.0.0/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka_2.11-2.0.0/config/server.properties &
}
zookeeperStop(){
/usr/local/kafka/kafka_2.11-2.0.0/bin/zookeeper-server-stop.sh
}
kafkaStop(){
/usr/local/kafka/kafka_2.11-2.0.0/bin/kafka-server-stop.sh
}
case $1 in
start)
echo -n "Starting Kafka:"
zookeeperStart
sleep 5
kafkaStart
exit $?
;;
stop)
echo -n "stop Kafka:"
kafkaStop
sleep 5
zookeeperStop
exit $?
;;
status)
jps
exit $?
;;
restart)
echo "restart"
stop
sleep 5
start
exit $?
;;
*)
echo "require start|stop|status|restart"
exit 1
;;
esac
设置文件权限
chmod +x kafka
添加到服务中
update-rc.d -f kafka defaults
测试
service kafka start
查看服务是否启动成功
jps
4.png
重启测试
reboot
网友评论