设为首页 加入收藏

TOP

CentOS7安装kafka(scala)和zookeeper
2019-04-23 14:27:30 】 浏览:35
Tags:CentOS7 安装 kafka scala zookeeper
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/linzi0712/article/details/83621425

1、安装scala

cd /usr/local/

下载 https://www.scala-lang.org/download/ 安装包,我准备安装kafka_2.12-2.0.0,所以我需要安装2.12版本的scala。

解压:tar -zxvf scala-2.12.6.tgz

设置环境变量:

echo "export SCALA_HOME=/usr/local/scala-2.12.6" >> /etc/profile

echo -e 'export PATH=$PATH:$SCALA_HOME/bin'>> /etc/profile

source /etc/profile

进入scala的shell环境:scala

按照惯例来个hello world: object HelloWorld { def main(args: Array[String]):Unit = { println("hello, world!")}}

hello world调用方式: HelloWorld.main(Array())

退出repl环境::q

如果要将scala scp到其他节点,(也即拷贝文件夹scala-2.12.6到目录/usr/local/下):

sudo scp -r /usr/local/scala-2.12.6 node2:/usr/local/

sudo scp -r /usr/local/scala-2.12.6 node3:/usr/local/

scp过去以后,配置scala的环境变量即可。

2、安装zookeeper(单机和集群)

下载地址:地址:http://mirror.bit.edu.cn/apache/zookeeper/

stable/ 中下载最新的稳定版,例如zookeeper-3.4.12.tar.gz

在自己的安装目录解压,我在/opt/zookeeper/安装:

cd /opt/zookeeper/

tar -zxvf zookeeper-3.4.12.tar.gz

Zookeeper解压完成后。

cd zookeeper-3.4.12/conf/

进入zookeeper-3.4.12/conf/看到有个名为zoo_sample.cfg的官方实例配置文件,而运行Zookeeper需要一个名为zoo.cfg的配置文件。如果我们想使用默认配置,直接将该文件复制并且改名即可。里面可以配置端口号,是否启用集群等等,直接执行cp复制重命名。以下为详细配置解释。

命令: cp zoo_sample.cfg zoo.cfg

zoo.cfg配置详解:

# The number of milliseconds of each tick

#客户端与服务器或者服务器与服务器之间维持心跳的间隔,单位是毫秒,2000毫秒也就是两秒心跳一次。

tickTime=2000

# The number of ticks that the initial

# synchronization phase can take

#集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数#(tickTime的数量)。

initLimit=10

# The number of ticks that can pass between

# sending a request and getting an acknowledgement

#集群中flower服务器(F)跟leader(L)服务器之间的请求和答应最多能容忍的心跳数。

syncLimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

#该属性对应的目录是用来存放myid信息跟一些版本,日志,跟服务器唯一的ID信息等。

dataDir=/opt/zookeeper/data

# the port at which the clients will connect

#客户端连接的接口,客户端连接zookeeper服务器的端口,zookeeper会监听这个端口,接收客户端的请求访问!这个端口默认是2181。

clientPort=2181

# the maximum number of client connections.

# increase this if you need to handle more clients

#maxClientCnxns=60

#

# Be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

#

# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance

#

# The number of snapshots to retain in dataDir

#autopurge.snapRetainCount=3

# Purge task interval in hours

# Set to "0" to disable auto purge feature

#autopurge.purgeInterval=1

我在此均使用的默认配置。

接着启动Zookeeper,先进入bin目录,然后执行zkServer.sh脚本进行启动,命令是:

cd /opt/zookeeper/zookeeper-3.4.12/bin

./zkServer.sh start

提示:

Using config: /opt/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

说明启动成功。

也可以查看状态

./zkServer.sh status

提示:

Using config: /opt/zookeeper/zookeeper-3.4.12/bin/../conf/zoo.cfg

Mode: standalone

standalone 单机模式

记得开一下端口:

firewall-cmd --zone=public --add-port=2181/tcp --permanent

firewall-cmd --reload

接着将zookeeper配置为开机启动

cd /etc/rc.d/init.d

touch zookeeper

vim zookeeper

填入以下内容

=========================================================

#!/bin/bash

#chkconfig: 2345 10 90

#description: service zookeeper

export JAVA_HOME=/opt/java/jdk1.8.0_121

export ZOO_LOG_DIR=/opt/zookeeper/log

ZOOKEEPER_HOME=/opt/zookeeper/zookeeper-3.4.12

su root ${ZOOKEEPER_HOME}/bin/zkServer.sh "$1"

=========================================================

JAVA_HOME 需要配置为自己jdk的目录,用

ls -lrt /etc/alternatives/java

为新建的/etc/rc.d/init.d/zookeeper文件添加可执行权限,命令是:

chmod +x /etc/rc.d/init.d/zookeeper

把zookeeper这个脚本添加到开机启动项里面,命令是:

chkconfig --add zookeeper

如果想看看是否添加成功,命令是:

chkconfig --list

配置集群:

在zoo.cfg配置文件中 最后面加入以下内容

server.1=10.6.20.121:2888:3888

server.2=10.6.20.122:2888:3888

server.3=10.6.20.123:2888:3888

然后在/opt/zookeeper/data 目录创建myid文件

然后写入内容

在10.6.20.121 写入1 echo 1 >myid

在10.6.20.122写入2 echo 2 >myid

在10.6.20.123写入3 echo 3 >myid

接着重新启动每个节点,可以用./zkServer.sh status 查看状态

mode:follower 为follower节点

mode:leader 为leader节点

3.安装kafka

下载 http://kafka.apache.org/downloads

我在此下载的是 kafka_2.12-2.0.0 ,2.12是scala版本号。

下载到 /usr/local/kafka/

解压:

tar -zxvf kafka_2.12-2.0.0.tgz

配置:

进入config目录

cd kafka_2.12-2.0.0/config

vim server.properties

配置项相关详解:

broker.id=0 设置每一个节点的ID,且该ID属于唯一值。

log.dirs=/tmp/kafka-logs 设置消息持久化目录。

zookeeper.connect=10.6.20.121:2181,10.6.20.122:2181,10.6.20.123:2181设置zookeeper链接地址。

listeners=PLAINTEXT://10.6.20.121:9092服务器监听的地址,如果不配置从java.net.InetAddress.getCanonicalHostName()获得。在配置集群的时候,必须设置。

需要注意:在集群的时候,broker.id和listeners不能相同。

启动

[root@localhost config]# cd /usr/local/kafka/kafka_2.12-2.0.0/

[root@localhost kafka_2.12-2.0.0]# ./bin/kafka-server-start.sh -daemon config/server.properties

记得开一下端口:

firewall-cmd --zone=public --add-port=9092/tcp --permanent

firewall-cmd --reload

推荐安装一个KafkaOffsetMonitor 监控工具

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇kafka - 自定义序列化器 下一篇kafka-connect-fs 二次开发总结

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目