Operating system: CentOS 6.x 64-bit
Kafka version: kafka_2.11-0.8.2.1
Stand-alone installation Configuration Kafka
First, close SELinux, open firewall 9092 port
#SELINUXTYPE =targeted #注释掉
2, configure the firewall, open 9092 ports
Vi/etc/sysconfig/iptables #编辑防火墙配置文件
# Firewall configuration written by System-config-firewall
# Manual Customization of this file is not recommended.
-A input-m state--state established,related-j ACCEPT
-A input-m state--state new-m tcp-p TCP--dport 22-j ACCEPT
-A input-m state--state new-m tcp-p TCP--dport 9092-j ACCEPT
-A input-j REJECT--reject-with icmp-host-prohibited
-A forward-j REJECT--reject-with icmp-host-prohibited
Service iptables Restart #最后重启防火墙使配置生效
Second, the installation of JDK
Kafka running requires JDK support
http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-linux-x64.rpm
Note: Copy directly to the download tool for download, version please use JDK7,JDK8 may not be compatible kafka_2.11-0.8.2.1
When the download is complete, upload it to the/USR/LOCAL/SRC directory
chmod +x jdk-7u79-linux-x64.rpm # Add Execute Permissions
RPM-IVH jdk-7u79-linux-x64.rpm #安装
After the installation is complete, you can cd/usr/java/to the installation directory to view
3. Adding JDK to System environment variables
Vi/etc/profile #编辑, add the following code at the end
java_home=/usr/java/jdk1.7.0_79
Path= $PATH: $JAVA _home/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/x11r6/bin
Classpath=.: $JAVA _home/lib/tools.jar: $JAVA _home/lib/dt.jar
Source/etc/profile #使配置文件立即生效
To this end, the JDK installation is complete.
Iii. installation of Kafka
wget http://archive.apache.org/dist/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz
Note that the KAFKA_2.11-0.8.2.1.TGZ version is a compiled version that can be used for decompression.
TAR-XZVF kafka_2.11-0.8.2.1.tgz #解压
MV Kafka_2.11-0.8.2.1/usr/local/kafka #移动到安装目录
Mkdir/usr/local/kafka/log/kafka #创建kafka日志目录
Cd/usr/local/kafka/config #进入配置目录
VI server.properties #编辑修改相应的参数
host.name=192.168.0.11 #服务器IP地址, modify the IP for your own server
Log.dirs=/usr/local/kafka/log/kafka #日志存放路径, the directory created above
zookeeper.connect=localhost:2181 #zookeeper地址和端口, single configuration deployment, localhost:2181
Mkdir/usr/local/kafka/zookeeper #创建zookeeper目录
Mkdir/usr/local/kafka/log/zookeeper #创建zookeeper日志目录
Cd/usr/local/kafka/config #进入配置目录
VI zookeeper.properties #编辑修改相应的参数
Datadir=/usr/local/kafka/zookeeper #zookeeper数据目录
Datalogdir=/usr/local/kafka/log/zookeeper #zookeeper日志目录
Create startup, shutdown Kafka scripts
VI kafkastart.sh #编辑, add the following code
/usr/local/kafka/bin/zookeeper-server-start.sh/usr/local/kafka/config/zookeeper.properties &
/usr/local/kafka/bin/kafka-server-start.sh/usr/local/kafka/config/server.properties &
VI kafkastop.sh #编辑, add the following code
/usr/local/kafka/bin/zookeeper-server-stop.sh/usr/local/kafka/config/zookeeper.properties &
/usr/local/kafka/bin/kafka-server-stop.sh/usr/local/kafka/config/server.properties &
Five, set script to boot automatically execution
Vi/etc/rc.d/rc.local #编辑, adding a row at the end
Sh/usr/local/kafka/kafkastart.sh & # Set up to run the script in the background automatically
Sh/usr/local/kafka/kafkastart.sh #启动kafka
Sh/usr/local/kafka/kafkastop.sh #关闭kafka
At this point, Linux under the Kafka stand-alone installation configuration completed.
/usr/local/kafka/bin/kafka-topics.sh--create--zookeeper localhost:2181--replication-factor 1--partitions 1--topic Test
/usr/local/kafka/bin/kafka-topics.sh--list--zookeeper localhost:2181 test
/usr/local/kafka/bin/kafka-console-producer.sh--broker-list localhost:9092--topic test--from-beginning