Ubuntu中安装zookeeper及kafka并配置环境变量
首先安装zookeeper
zookeeper需要jdk环境,请在jdk安装完成的情况下安装zookeeper
1.从官网下载zookeeper
http://mirror.bit.edu.cn/apache/zookeeper/,版本可以根据自己需要选择使用,个人建议使用比最新版本低一点的版本,比较稳定
https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.5/
2.将下载后的压缩包复制到安装目录下,并加压,以zookeeper-3.4.11.tar.gz为例
tar -zxvf zookeeper-3.4.11.tar.gz
3.配置环境变量,我比较喜欢配置全局性环境变量,即在/etc/profile配置
首先打开/etc/profile:sudo vim /etc/profile
export ZOOKEEPER_HOME=/home/xxx/software/zookeeper-3.4.11
export PATH=$PATH:$ZOOKEEPER_HOME/bin
保存完成之后,加载环境变量:source /etc/profile
4.将zookeeper/conf下的zoo_sample.cfg复制一份并重命名为zoo.cfg并修改其中dataDir的路径
个人建议在zookeeper下新建mydata文件夹,用于存储数据:
dataDir=/home/xxx/software/zookeeper-3.4.11/mydata
5.检查是否安装配置成功
命令:zkServer.sh
关闭zookeeper:zkServer.sh
安装kafka
1.从官网下载kafka安装包:http://kafka.apache.org/downloads
2.将下载后的压缩包复制到安装目录下,并加压,以kafka_2.12-1.0.0.tgz为例
tar -zxvf kafka_2.12-1.0.0.tgz
3.修改conf中的server.properties文件中的日志目录log.dirs,可在kafka目录下新建mylog文件,并将路径指向此处
log.dirs=/home/xxx/software/kafka_2.12/mylog
4.配置环境变量
export KAFKA_HOME=/home/xxx/software/kafka_2.12
export PATH=$PATH:$KAFKA_HOME/bin
5.启动kafka,检查是否安装成功
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
安装 kafka 需要先安装 jdk。
一、下载
官网:http://kafka.apache.org/downloads.html
安装参考:https://segmentfault.com/a/1190000012990954
1. 解压安装(我的安装目录/opt/kafka/)
3. 修改其中
listeners=PLAINTEXT://ip:9092
注:ip指的是本机ip地址
三、验证
# bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
四、配置开机自启(systemctl)
1. 在 /lib/systemd/system/ 目录下创建 zookeeper服务和kafka服务 的配置文件。
[Unit]
Description=Zookeeper service
After=network.target
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/jdk-11.0.1/bin"
User=root
Group=root
ExecStart=/opt/kafka/kafka_2.11-2.1.0/bin/zookeeper-server-start.sh /opt/kafka/kafka_2.11-2.1.0/config/zookeeper.properties
ExecStop=/opt/kafka/kafka_2.11-2.1.0/bin/zookeeper-server-stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
kafka.service 添加内容:
[Unit]
Description=Apache Kafka server (broker)
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/java/jdk-11.0.1/bin"
User=root
Group=root
ExecStart=/opt/kafka/kafka_2.11-2.1.0/bin/kafka-server-start.sh /opt/kafka/kafka_2.11-2.1.0/config/server.properties
ExecStop=/opt/kafka/kafka_2.11-2.1.0/bin/kafka-server-stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
#systemctl enable zookeeper
#systemctl enable kafka
注:启动kafka前必须先启动zookeeper 。
--------------------------------------------------本地部署------------------------------------------
环境变量
#java
export JAVA_HOME=/usr/java/
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
#zookeeper
export ZOOKEEPER_HOME=/usr/kafka_2.12-2.2.0/
export PATH=$PATH:$ZOOKEEPER_HOME/bin
#kafka
export KAFKA_HOME=/usr/kafka_2.12-2.2.0
export PATH=$PATH:$KAFKA_HOME/bin
ZooKeeper
https://www.cnblogs.com/kingsonfu/p/10631332.html
https://blog.csdn.net/ybk233/article/details/81266667
KafKa
https://blog.csdn.net/csdnlihai/article/details/87787236
#ZooKeeper 服务创建
[Unit]
Description=Zookeeper service
After=network.target
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/java/bin"
User=root
Group=root
ExecStart=/usr/kafka_2.12-2.2.0/bin/zookeeper-server-start.sh /usr/kafka_2.12-2.2.0/config/zookeeper.properties
ExecStop=/usr/kafka_2.12-2.2.0/bin/zookeeper-server-stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target
#kafka服务创建
[Unit]
Description=Apache Kafka server (broker)
[Service]
Type=simple
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/java/bin"
User=root
Group=root
ExecStart=/usr/kafka_2.12-2.2.0/bin/kafka-server-start.sh /usr/kafka_2.12-2.2.0/config/server.properties
ExecStop=/usr/kafka_2.12-2.2.0/bin/kafka-server-stop.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target