CentOS7 安装 kafka

安装 JDK

JDK地址

[root@localhost ~]# rpm -qa | grep java
[root@localhost ~]# rpm -qa | grep jdk
[root@localhost ~]# rpm -qa | grep java | xargs rpm -e --nodeps		#卸载老版本


[root@localhost ~]# yum install java-1.8.0-openjdk* -y
[root@localhost ~]# java -version
#这里为了图方便使用了 yum 安装 JDK

安装 zookeeper

zookeeper地址

[root@localhost ~]# ls
anaconda-ks.cfg  apache-zookeeper-3.8.0-bin-bin.tar.gz kafka_2.12-3.0.1.tgz

[root@localhost ~]# tar -xf apache-zookeeper-3.8.0-bin-bin.tar.gz -C /usr/local/
[root@localhost local]# ls
apache-zookeeper-3.8.0-bin-bin  bin  etc  games  include  lib  lib64  libexec  sbin  share  src
[root@localhost local]# cd apache-zookeeper-3.8.0-bin/

[root@localhost local]# mv apache-zookeeper-3.8.0-bin/ zookeeper
[root@localhost local]# ls
bin  etc  games  include  lib  lib64  libexec  sbin  share  src  zookeeper

//配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/zookeeper/bin:$PATH' > /etc/profile.d/zookeeeper.sh
[root@localhost ~]# source /etc/profile.d/zookeeeper.sh 
[root@localhost ~]# echo $PATH
/usr/local/zookeeper/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin


//修改配置文件
[root@localhost ~]# cp /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg

[root@localhost ~]# vi /usr/local/zookeeper/conf/zoo.cfg 
dataDir=/usr/local/zookeeper/data			#修改数据存放目录
dataLogDir=/usr/local/zookeeper/log			#添加存放日志
pidfile=/var/run/zookeeper.pid

[root@localhost ~]# mkdir /usr/local/zookeeper/data
[root@localhost ~]# mkdir /usr/local/zookeeper/log

//启动
[root@localhost ~]# /usr/local/zookeeper/bin/zkServer.sh  start
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@localhost ~]# ss -anlt | grep 2181
LISTEN    0         50                       *:2181                   *:*       

//设置自启动
[root@localhost ~]# cat > /usr/lib/systemd/system/zookeeper.service <
[Unit]
Description=The zookeeper Server
After=network.target


[Service]
Type=forking
ExecStart=/usr/local/zookeeper/bin/zkServer.sh  start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh  stop

[Install]
WantedBy=multi-user.target
EOF   

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl start zookeeper.service                    

安装 kafka

kafka地址

[root@localhost ~]# tar -xf kafka_2.12-3.0.1.tgz  -C /usr/local/
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ls
bin  etc  games  include  kafka_2.12-3.0.1  lib  lib64  libexec  sbin  share  src  zookeeper
[root@localhost local]# mv kafka_2.12-3.0.1/ kafka


[root@localhost ~]# vi /usr/local/kafka/config/server.properties 
# broker 的编号,如果集群中有多个 broker,则每个 broker 的编号需要设置的不同
broker.id=0
# 31 行
listeners=PLAINTEXT://192.168.129.250:9092
# 123 行,修改 zookeeper.connect 为自己的 IP:PORT
zookeeper.connect=localhost:2181/kafka


[root@localhost ~]# cat > /usr/lib/systemd/system/kafka.service <
[Unit]
Description=The kafka Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/kafka/bin/kafka-server-start.sh -daemon  /usr/local/kafka/config/server.properties 
ExecStop=/usr/local/kafka/bin/kafka-server-stop.sh -daemon /usr/local/kafka/config/server.properties 
ExecReload=/bin/kill -HUP

[Install]
WantedBy=multi-user.target
EOF

[root@localhost ~]# systemctl daemon-reload 
[root@localhost ~]# systemctl start kafka.service  


[root@localhost ~]# netstat -apn | grep 9092
[root@localhost ~]# ps aux | grep kafka

你可能感兴趣的:(Linux,linux)