Apache Kafka 简明教程
Apache Kafka - Installation Steps
以下是在您的机器上安装 Java 的步骤。
Following are the steps for installing Java on your machine.
Step 1 - Verifying Java Installation
希望您现在已经安装 Java,只需使用以下命令进行验证。
Hopefully you have already installed java on your machine right now, so you just verify it using the following command.
$ java -version
如果 Java 在您的设备上安装成功,您将看到所安装 Java 的版本。
If java is successfully installed on your machine, you could see the version of the installed Java.
Step 1.1 - Download JDK
如果没有下载 Java,请访问以下链接下载最新版本的 JDK,然后下载最新版本。
If Java is not downloaded, please download the latest version of JDK by visiting the following link and download latest version.
现在最新版本是 JDK 8u 60,文件是“jdk-8u60-linux-x64.tar.gz”。请在您的机器上下载此文件。
Now the latest version is JDK 8u 60 and the file is “jdk-8u60-linux-x64.tar.gz”. Please download the file on your machine.
Step 1.2 - Extract Files
一般来说,下载的文件都存储在下载文件夹中,验证并使用以下命令提取 tar 设置。
Generally, files being downloaded are stored in the downloads folder, verify it and extract the tar setup using the following commands.
$ cd /go/to/download/path
$ tar -zxf jdk-8u60-linux-x64.gz
Step 1.3 - Move to Opt Directory
为了让所有使用者都能使用 java,将提取的 java 内容移动到 usr/local/java/ 文件夹中。
To make java available to all users, move the extracted java content to usr/local/java/ folder.
$ su
password: (type password of root user)
$ mkdir /opt/jdk
$ mv jdk-1.8.0_60 /opt/jdk/
Step 1.4 - Set path
若要设置 path 及 JAVA_HOME 变量,请将以下命令添加到 ~/.bashrc 文件中。
To set path and JAVA_HOME variables, add the following commands to ~/.bashrc file.
export JAVA_HOME =/usr/jdk/jdk-1.8.0_60
export PATH=$PATH:$JAVA_HOME/bin
现在,将所有变更应用到当前运行系统中。
Now apply all the changes into current running system.
$ source ~/.bashrc
Step 1.5 - Java Alternatives
使用以下命令更改 Java 备用项。
Use the following command to change Java Alternatives.
update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_60/bin/java 100
Step 1.6 − 现在使用步骤 1 中说明的验证命令 (java -version) 验证 java。
Step 1.6 − Now verify java using verification command (java -version) explained in Step 1.
Step 2 - ZooKeeper Framework Installation
Step 2.1 - Download ZooKeeper
要将 ZooKeeper 框架安装到您的计算机上,请访问以下链接并下载 ZooKeeper 的最新版本。
To install ZooKeeper framework on your machine, visit the following link and download the latest version of ZooKeeper.
截至目前,ZooKeeper 的最新版本是 3.4.6 (ZooKeeper-3.4.6.tar.gz)。
As of now, latest version of ZooKeeper is 3.4.6 (ZooKeeper-3.4.6.tar.gz).
Step 2.2 - Extract tar file
使用以下命令解压 tar 文件
Extract tar file using the following command
$ cd opt/
$ tar -zxf zookeeper-3.4.6.tar.gz
$ cd zookeeper-3.4.6
$ mkdir data
Step 2.3 - Create Configuration File
使用命令 vi "conf/zoo.cfg" 打开名为 conf/zoo.cfg 的配置文件,并将所有以下参数设置为起点。
Open Configuration File named conf/zoo.cfg using the command vi “conf/zoo.cfg” and all the following parameters to set as starting point.
$ vi conf/zoo.cfg
tickTime=2000
dataDir=/path/to/zookeeper/data
clientPort=2181
initLimit=5
syncLimit=2
配置文件成功保存并返回到终端后,您就可以启动 zookeeper 服务器。
Once the configuration file has been saved successfully and return to terminal again, you can start the zookeeper server.
Step 2.4 - Start ZooKeeper Server
$ bin/zkServer.sh start
执行此命令后,您将得到以下所示的响应 −
After executing this command, you will get a response as shown below −
$ JMX enabled by default
$ Using config: /Users/../zookeeper-3.4.6/bin/../conf/zoo.cfg
$ Starting zookeeper ... STARTED
Step 2.5 - Start CLI
$ bin/zkCli.sh
输入上述命令之后,您将连接到 zookeeper 服务器,并将得到以下响应。
After typing the above command, you will be connected to the zookeeper server and will get the below response.
Connecting to localhost:2181
................
................
................
Welcome to ZooKeeper!
................
................
WATCHER::
WatchedEvent state:SyncConnected type: None path:null
[zk: localhost:2181(CONNECTED) 0]
Step 2.6 - Stop Zookeeper Server
连接服务器并执行所有操作之后,您可以使用以下命令停止 zookeeper 服务器 −
After connecting the server and performing all the operations, you can stop the zookeeper server with the following command −
$ bin/zkServer.sh stop
现在您已成功在自己的计算机上安装 Java 和 ZooKeeper。让我们看看安装 Apache Kafka 的步骤。
Now you have successfully installed Java and ZooKeeper on your machine. Let us see the steps to install Apache Kafka.
Step 3 - Apache Kafka Installation
让我们继续执行以下步骤以在您的计算机上安装 Kafka。
Let us continue with the following steps to install Kafka on your machine.
Step 3.1 - Download Kafka
要将 Kafka 服务器安装到计算机上,请点击以下链接 −
To install Kafka on your machine, click on the below link −
现在,最新版本,即 – kafka_2.11_0.9.0.0.tgz 将下载到您的计算机上。
Now the latest version i.e., – kafka_2.11_0.9.0.0.tgz will be downloaded onto your machine.
Step 3.2 - Extract the tar file
使用以下命令解压 tar 文件 −
Extract the tar file using the following command −
$ cd opt/
$ tar -zxf kafka_2.11.0.9.0.0 tar.gz
$ cd kafka_2.11.0.9.0.0
现在您已在自己的计算机上下载了 Kafka 的最新版本。
Now you have downloaded the latest version of Kafka on your machine.
Step 3.3 - Start Server
您可以使用以下命令启动服务器 −
You can start the server by giving the following command −
$ bin/kafka-server-start.sh config/server.properties
服务器启动后,您将在屏幕上看到以下响应 −
After the server starts, you would see the below response on your screen −
$ bin/kafka-server-start.sh config/server.properties
[2016-01-02 15:37:30,410] INFO KafkaConfig values:
request.timeout.ms = 30000
log.roll.hours = 168
inter.broker.protocol.version = 0.9.0.X
log.preallocate = false
security.inter.broker.protocol = PLAINTEXT
…………………………………………….
…………………………………………….
Step 4 - Stop the Server
执行所有操作之后,您可以使用以下命令停止服务器 −
After performing all the operations, you can stop the server using the following command −
$ bin/kafka-server-stop.sh config/server.properties
我们已经讨论了 Kafka 安装,在下一章中,我们可以了解如何对 Kafka 执行基本操作。
Now that we have already discussed the Kafka installation, we can learn how to perform basic operations on Kafka in the next chapter.