zookeeper / kafka deployment

 

Ubuntu installed zookeeper and kafka and configuration environment variable

First install the zookeeper

zookeeper need jdk environment, install jdk installation is complete in the case of a zookeeper
1. zookeeper downloaded from the official website
http://mirror.bit.edu.cn/apache/zookeeper/, version can be selected according to their use, personal use than recommended the latest version of the low point of release, more stable

https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.5.5/


2. After downloading the archive copy to the installation directory, and pressurize the zookeeper-3.4.11.tar.gz for example
tar -zxvf zookeeper-3.4.11.tar.gz
3. configuration environment variable, I am more I like to configure global environment variables, namely in / etc / profile configuration
first, open the / etc / profile: sudo vim / etc / profile
Export ZOOKEEPER_HOME = / Home / xxx / Software / ZooKeeper-3.4.11
Export the PATH = $ the PATH: $ ZOOKEEPER_HOME / bin
after saving is complete, load the environment variables: Source / etc / Profile
4. the copy and rename zoo_sample.cfg under zookeeper / conf zoo.cfg and modify the path dataDir of
personal recommendations mydata new folder under the zookeeper for storing data:
dataDir = / Home / XXX / Software / ZooKeeper-3.4.11 / mydata
5. The check for the successful installation configuration
commands: zkServer.sh

Close ZooKeeper: zkServer.sh  STOP

mounting kafka

1. From the official website to download the installation package kafka: http://kafka.apache.org/downloads

2. After the downloaded archive copied to the install directory, and pressurized to Example kafka_2.12-1.0.0.tgz
-zxvf kafka_2.12-1.0.0.tgz the tar
the server.properties 3. modify conf file in the log directory log.dirs, to create a new file in the kafka mylog directory, and the path to where
log.dirs = / Home / XXX / Software / kafka_2.12 / MyLog
4. configure the environment variables
Export = KAFKA_HOME / Home / XXX / Software / kafka_2.12
Export the PATH the PATH = $: $ KAFKA_HOME / bin
5. The start kafka, check whether the installation is successful
bin / zookeeper-server-start.sh -daemon config / zookeeper.properties

 

Installation kafka need to install jdk.
First, download
the official website: http: //kafka.apache.org/downloads.html

 

Second, the installation 
Installation Reference: https: //segmentfault.com/a/1190000012990954

1. Unzip the installation (I install directory / opt / kafka /)

# Tar -zvxf kafka_2.11-2.1.0.tgz

2. modify the configuration

 # vim /opt/kafka/kafka_2.11-2.1.0/config/server.properties

3. modify

listeners=PLAINTEXT://ip:9092

Note: ip refers local ip

Third, the verification
 1. installation package script starts Zookeeper single node Example:

# cd  /opt/kafka/kafka_2.11-2.1.0

# bin/zookeeper-server-start.sh -daemon config/zookeeper.properties

2. Use kafka-server-start.sh start kafka services:

# bin/kafka-server-start.sh config/server.properties

3. Use kafka-topics.sh create partitions but single copy of the topic test

# bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test

4. Send message kafka-console-producer.sh 

# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test 

 

5. kafka-console-consumer.sh terminal receives the message and print

# bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning

Fourth, configure the boot from Kai (systemctl)
1. Create a zookeeper service and kafka service configuration files in / lib / systemd / system / directory.

# vim zookeeper.service 

 zookeeper.service add content:

[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

# vim kafka.service 

kafka.service add content:

[Unit]
Description=Apache Kafka server (broker)
After=network.target  zookeeper.service

[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

Note: The above two files the appropriate changes according to their own and kafka jdk installation directory.

 2. Refresh configuration.

# systemctl daemon-reload

3. zookeeper, kafka service to join the post. 

#systemctl enable zookeeper

#systemctl enable kafka

4. systemctl startup / shutdown / restart zookeeper, kafka service systemctl start / stop / restart zookeeper / kafka.

Note: Before starting kafka must first start zookeeper.

 # systemctl start zookeeper

 # systemctl start kafka

 5. Check status.

 # systemctl status zookeeper

 

 # systemctl status kafka

 

 

-------------------------------------------------- local deployment ------------------------------------------

环境变量
#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 Service Creation
[Unit]
the Description = Zookeeper Service
the 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)
After=network.target  zookeeper.service

[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

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/micro-chen/p/11023064.html