How To Install Apache Kafka on Ubuntu 14.04
打算学习kafka ,接触一些新的知识。加油!!!
参考:https://www.digitalocean.com/community/tutorials/how-to-install-apache-kafka-on-ubuntu-14-04
这篇文章也不错,翻译的: http://www.howtoing.com/how-to-install-apache-kafka-on-ubuntu-14-04/
Introduction
Apache Kafka is a popular distributed message broker designed to handle large volumes of real-time data efficiently. A Kafka cluster is not only highly scalable and fault-tolerant, but it also has a much higher throughput compared to other message brokers such as ActiveMQ and RabbitMQ. Though it is generally used as a pub/sub messaging system, a lot of organizations also use it for log aggregation because it offers persistent storage for published messages.
In this tutorial, you will learn how to install and use Apache Kafka 0.8.2.1 on Ubuntu 14.04.
Prerequisites
To follow along, you will need:
- Ubuntu 14.04 Droplet
- At least 4GB of swap space
Step 1 — Create a User for Kafka
As Kafka can handle requests over a network, you should create a dedicated user for it. This minimizes damage to your Ubuntu machine should the Kafka server be comprised.
Note: After setting up Apache Kafka, it is recommended that you create a different non-root user to perform other tasks on this server.
As root, create a user called kafka using the useradd command:
- useradd kafka -m
Set its password using passwd:
- passwd kafka
Add it to the sudo group so that it has the privileges required to install Kafka's dependencies. This can be done using the adduser command:
- adduser kafka sudo
Your Kafka user is now ready. Log into it using su:
- su - kafka
Step 2 — Install Java
Before installing additional packages, update the list of available packages so you are installing the latest versions available in the repository:
- sudo apt-get update
As Apache Kafka needs a Java runtime environment, use apt-get to install the default-jre package:
- sudo apt-get install default-jre
Step 3 — Install ZooKeeper
Apache ZooKeeper is an open source service built to coordinate and synchronize configuration information of nodes that belong to a distributed system. A Kafka cluster depends on ZooKeeper to perform—among other things—operations such as detecting failed nodes and electing leaders.
Since the ZooKeeper package is available in Ubuntu's default repositories, install it using apt-get.
- sudo apt-get install zookeeperd
After the installation completes, ZooKeeper will be started as a daemon automatically. By default, it will listen on port 2181.
To make sure that it is working, connect to it via Telnet:
- telnet localhost 2181
At the Telnet prompt, type in ruok and press ENTER.
If everything's fine, ZooKeeper will say imok and end the Telnet session.
Step 4 — Download and Extract Kafka Binaries
Now that Java and ZooKeeper are installed, it is time to download and extract Kafka.
To start, create a directory called Downloads to store all your downloads.
- mkdir -p ~/Downloads
Use wget to download the Kafka binaries.
- wget "http://mirror.cc.columbia.edu/pub/software/apache/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz" -O ~/Downloads/kafka.tgz
Create a directory called kafka and change to this directory. This will be the base directory of the Kafka installation.
- mkdir -p ~/kafka && cd ~/kafka
Extract the archive you downloaded using the tar command.
- tar -xvzf ~/Downloads/kafka.tgz --strip 1
Step 5 — Configure the Kafka Server
The next step is to configure the Kakfa server.
Open server.properties using vi:
- vi ~/kafka/config/server.properties
By default, Kafka doesn't allow you to delete topics. To be able to delete topics, add the following line at the end of the file:
delete.topic.enable = true
Save the file, and exit vi.
Step 6 — Start the Kafka Server
Run the kafka-server-start.sh script using nohup to start the Kafka server (also called Kafka broker) as a background process that is independent of your shell session.
- nohup ~/kafka/bin/kafka-server-start.sh ~/kafka/config/server.properties > ~/kafka/kafka.log 2>&1 &
Wait for a few seconds for it to start. You can be sure that the server has started successfully when you see the following messages in ~/kafka/kafka.log:
...
[2015-07-29 06:02:41,736] INFO New leader is 0 (kafka.server.ZookeeperLeaderElector$LeaderChangeListener)
[2015-07-29 06:02:41,776] INFO [Kafka Server 0], started (kafka.server.KafkaServer)
You now have a Kafka server which is listening on port 9092.
Step 7 — Test the Installation
Let us now publish and consume a "Hello World" message to make sure that the Kafka server is behaving correctly.
To publish messages, you should create a Kafka producer. You can easily create one from the command line using the kafka-console-producer.sh script. It expects the Kafka server's hostname and port, along with a topic name as its arguments.
Publish the string "Hello, World" to a topic called TutorialTopic by typing in the following:
- echo "Hello, World" | ~/kafka/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic TutorialTopic > /dev/null
As the topic doesn't exist, Kafka will create it automatically.
To consume messages, you can create a Kafka consumer using the kafka-console-consumer.sh script. It expects the ZooKeeper server's hostname and port, along with a topic name as its arguments.
The following command consumes messages from the topic we published to. Note the use of the --from-beginning flag, which is present because we want to consume a message that was published before the consumer was started.
- ~/kafka/bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic TutorialTopic --from-beginning
If there are no configuration issues, you should see Hello, World in the output now.
The script will continue to run, waiting for more messages to be published to the topic. Feel free to open a new terminal and start a producer to publish a few more messages. You should be able to see them all in the consumer's output instantly.
When you are done testing, press CTRL+C to stop the consumer script.
Step 8 — Install KafkaT (Optional)
KafkaT is a handy little tool from Airbnb which makes it easier for you to view details about your Kafka cluster and also perform a few administrative tasks from the command line. As it is a Ruby gem, you will need Ruby to use it. You will also need the build-essential package to be able to build the other gems it depends on. Install them using apt-get:
- sudo apt-get install ruby ruby-dev build-essential
You can now install KafkaT using the gem command:
- sudo gem install kafkat --source https://rubygems.org --no-ri --no-rdoc
Use vi to create a new file called .kafkatcfg.
- vi ~/.kafkatcfg
This is a configuration file which KafkaT uses to determine the installation and log directories of your Kafka server. It should also point KafkaT to your ZooKeeper instance. Accordingly, add the following lines to it:
{
"kafka_path": "~/kafka",
"log_path": "/tmp/kafka-logs",
"zk_path": "localhost:2181"
}
You are now ready to use KafkaT. For a start, here's how you would use it to view details about all Kafka partitions:
- kafkat partitions
You should see the following output:
Topic Partition Leader Replicas ISRs
TutorialTopic 0 0 [0] [0]
To learn more about KafkaT, refer to its GitHub repository.
Step 9 — Set Up a Multi-Node Cluster (Optional)
If you want to create a multi-broker cluster using more Ubuntu 14.04 machines, you should repeat Step 1, Step 3, Step 4 and Step 5 on each of the new machines. Additionally, you should make the following changes in the server.properties file in each of them:
- the value of the
broker.idproperty should be changed such that it is unique throughout the cluster - the value of the
zookeeper.connectproperty should be changed such that all nodes point to the same ZooKeeper instance
If you want to have multiple ZooKeeper instances for your cluster, the value of the zookeeper.connectproperty on each node should be an identical, comma-separated string listing the IP addresses and port numbers of all the ZooKeeper instances.
Step 10 — Restrict the Kafka User
Now that all installations are done, you can remove the kafka user's admin privileges. Before you do so, log out and log back in as any other non-root sudo user. If you are still running the same shell session you started this tutorial with, simply type exit.
To remove the kafka user's admin privileges, remove it from the sudo group.
- sudo deluser kafka sudo
To further improve your Kafka server's security, lock the kafka user's password using the passwdcommand. This makes sure that nobody can directly log into it.
- sudo passwd kafka -l
At this point, only root or a sudo user can log in as kafka by typing in the following command:
- sudo su - kafka
In the future, if you want to unlock it, use passwd with the -u option:
- sudo passwd kafka -u
Conclusion
You now have a secure Apache Kafka running on your Ubuntu server. You can easily make use of it in your projects by creating Kafka producers and consumers using Kafka clients which are available for most programming languages. To learn more about Kafka, do go through its documentation.
How To Install Apache Kafka on Ubuntu 14.04的更多相关文章
- Install Google Pinyin on Ubuntu 14.04
Install Google Pinyin on Ubuntu 14.04 I've been spending more and more time on Ubuntu and I'm not us ...
- Install eclipse ns3 in ubuntu 14.04
1. NS3 install 参考NS3 tutorial即可. 2.eclipse 2.1下载 下载地址:http://www.eclipse.org/downloads/ ...
- Install and Configure Apache Kafka on Ubuntu 16.04
https://devops.profitbricks.com/tutorials/install-and-configure-apache-kafka-on-ubuntu-1604-1/ by hi ...
- [译]How to Install Node.js on Ubuntu 14.04 如何在ubuntu14.04上安装node.js
原文链接为 http://www.hostingadvice.com/how-to/install-nodejs-ubuntu-14-04/ 由作者Jacob Nicholson 发表于October ...
- Install Atom editor in ubuntu 14.04
Step 1: Add repository sudo add-apt-repository ppa:webupd8team/atom Step 2: Update the repository su ...
- Ubuntu 14.04 安装adobe flash player
参考: How to install flash payer in Ubuntu 14.04 LTS? [duplicate] Ubuntu 14.04 安装adobe flash player 32 ...
- Ubuntu 14.04 使用VirtualBox 4.3.10 虚拟 Windows 7
Ubuntu 14.04 尽管不错,可是有些事仅仅能在Windows下才干完毕,所以在 Ubuntu 下利用虚拟机软件Oracle VirtualBox,虚拟安装个Windows系统是个不错的选择. ...
- [转] 如何在 Ubuntu 14.04 上通过 apt-get 安装 Apache Tomcat 7
PS:war 部署路径:/var/lib/tomcat7/webapps http://www.linfuyan.com/how-to-install-apache-tomcat7-on-ubuntu ...
- Linux Ubuntu 14.04安装LAMP(Apache+MySQL+PHP)网站环境
从虚拟主机到VPS/服务器的过度,对于普通的非技术型的站长用户来说可能稍许有一些困难,麦子建议我们如果能够在虚拟主机环境中满足建站需要的, 还是用虚拟主机比较好.除非我们真的有需要或者希望从虚拟主机过 ...
随机推荐
- 常用类型转换 一.常用int和string类型转换
常用类型转换 一.常用int类型转换1. int.parse(string) 这个类型只支持string类型 2.double doubleType = Int32.MaxValue + 1; i ...
- art中的部分内容,留着慢慢研究
root@hbg:/tmp# cat /proc/mtddev: size erasesize namemtd0: 00040000 00010000 "u-boot" ...
- CSS3 学习小结
写样式时有时遇到浏览器兼容问题:-webkit-transition:chrome和safari-moz-transition:firefox-ms-transition:IE-o-transitio ...
- python 信用卡系统+购物商城见解
通过完成信用卡系统+购物商城 使自己在利用 字典和列表方面有了较大的提升,感悟很深, 下面将我对此次作业所展示的重点列表如下: #!/usr/bin/env python3.5 # -*-coding ...
- Developing a Custom Membership Provider from the scratch, and using it in the FBA (Form Based Authentication) in SharePoint 2010
//http://blog.sharedove.com/adisjugo/index.php/2011/01/05/writing-a-custom-membership-provider-and-u ...
- 归并排序的go语言与C++实现对比
最近对go语言发生了兴趣,发现go语言语法简洁,非常适合算法的描述和实现,于是对归并排序进行了实现. 例子中需要排序的队列是长度为100的从100到1的数列,排序算法是正序排序,排序正确的话,结果应当 ...
- robotframework代码定位感悟
robotframework代码定位感悟: 在做自动化的时候,有时候还是要考虑真实的操作,考虑人为反应,网络,页面渲染,服务器处理请求的过程及数据是否真实到达响应的位置, 不能一味的按照程序的速度 去 ...
- 使用gulp构建nodejs,你只需要记住5个函数
gulp gulp是一个nodejs的streaming构建工具,所谓的streaming大致意思就是把构建流程想成一个个链接的管道(pipe). 为什么要这样做呢? 要解释原因,就不得不提到unix ...
- Windows下QT4.8.4编译环境的搭建(转载http://blog.csdn.net/bestgonghuibin/article/details/38933141)
开始使用QT了,所以第一步就是把环境搭起来,这里小记一下,以免以后忘记. 1. 下载安装文件 要使用QT功能,那么必须要下载QT的源码,还必须要一个是用QT的编译环境,可以是VS2010,也可以是专用 ...
- linux nfs开启
nfs设置: NFS的配置过程很简单.在服务器端中编辑/etc/exports文件,添加如下内容: /home/cotton/data/cotton/zghy 192.168.2.*(rw,s ...