- 1.linux单机版
- The address the socket server listens on. It will get the value returned from
- java.net.InetAddress.getCanonicalHostName() if not configured.
- FORMAT:
- listeners = listener_name://host_name:port
- EXAMPLE:
- listeners = PLAINTEXT://your.host.name:9092
- Hostname and port the broker will advertise to producers and consumers. If not set,
- it uses the value for “listeners” if configured. Otherwise, it will use the value
- returned from java.net.InetAddress.getCanonicalHostName().
- A comma separated list of directories under which to store log files
- Zookeeper connection string (see zookeeper docs for details).
- This is a comma separated host:port pairs, each corresponding to a zk
- server. e.g. “127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002”.
- You can also append an optional chroot string to the urls to specify the
- root directory for all kafka znodes.
- Timeout in ms for connecting to zookeeper
1.linux单机版
前置条件
Zookeeper部署
Kafka目前还是需要借助于Zookeeper实现分布式部署,因此需要先部署一个zookeeper
进入目录
下载地址
下载地址如下:https://zookeeper.apache.org/releases.html
下载对应版本即可
点击之后跳转到如下页面,点击HTTP下载即可,当然也可以复制下载链接,直接在服务器端下载
下载命令示例:wget https://dlcdn.apache.org/zookeeper/zookeeper-3.5.10/apache-zookeeper-3.5.10-bin.tar.gz
解压
- tar -zxvf apache-zookeeper-3.5.10-bin.tar.gz
- mv apache-zookeeper-3.5.10-bin zookeeper
- rm -rf apache-zookeeper-3.5.10-bin.tar.gz
- cd zookeeper/
- ls
创建文件夹
- mkdir data
-
修改配置文件
mv conf/zoo_sample.cfg conf/zoo.cfg
- vim conf/ zoo.cfg
修改为如下内容即可,其实最终修改的还是dataDir属性
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/usr/local/zookeeper/data
# the port at which the clients will connect
clientPort=2181
启动zookeeper
/usr/local/zookeeper/bin/zkServer.sh start
- jps -l
如图,启动了一个zookeeper的JAVA进程
- ps -ef|grep zookeeper
其他命令
- 重启zookeeper:/usr/local/zookeeper/bin/zkServer.sh restart
停止zookeeper:/usr/local/zookeeper/bin/zkServer.sh stop
使用客户端工具链接测试
Kafka部署
进入目录
下载地址
下载地址如下:https://kafka.apache.org/downloads
下载对应版本即可
下载命令示例:wget https://archive.apache.org/dist/kafka/3.0.0/kafka_2.12-3.0.0.tgz解压
tar -zxvf kafka_2.13-3.0.0.tgz
- mv kafka_2.13-3.0.0 kafka
- rm -rf kafka_2.13-3.0.0.tgz
- cd kafka
- ls
创建文件夹
修改配置文件
- vim /usr/local/kafka/config/kraft/server.properties
- 主要变动如下3处,确保Kafka能被外网链接、修改log保存地址、修改zookeeper地址
```properties
####################### Socket Server Settings
The address the socket server listens on. It will get the value returned from
java.net.InetAddress.getCanonicalHostName() if not configured.
FORMAT:
listeners = listener_name://host_name:port
EXAMPLE:
listeners = PLAINTEXT://your.host.name:9092
listeners=PLAINTEXT://0.0.0.0:9092
Hostname and port the broker will advertise to producers and consumers. If not set,
it uses the value for “listeners” if configured. Otherwise, it will use the value
returned from java.net.InetAddress.getCanonicalHostName().
advertised.listeners=PLAINTEXT://120.48.107.224:9092
####################### Log Basics
A comma separated list of directories under which to store log files
log.dirs=/usr/local/kafka/logs
####################### Zookeeper
Zookeeper connection string (see zookeeper docs for details).
This is a comma separated host:port pairs, each corresponding to a zk
server. e.g. “127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002”.
You can also append an optional chroot string to the urls to specify the
root directory for all kafka znodes.
zookeeper.connect=localhost:2181
Timeout in ms for connecting to zookeeper
zookeeper.connection.timeout.ms=18000
<a name="A0HIU"></a>
### 整合supervisor管理进程
1. touch /usr/local/kafka/logs/run.log
2. cd /etc/supervisord.d/
3. vim kafka.ini
4. 输入如下内容
```shell
[program:kafka]
directory=/usr/local/kafka/bin
command=/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties
autorestart=true
redirect_stderr=true
stdout_logfile=/usr/local/kafka/logs/run.log
- supervisorctl update
- supervisorctl status
- 如图,Kafka进程已开始运行
- tail -f -n 100 /usr/local/kafka/logs/run.log
使用客户端工具链接测试
如图,Kafka链接成功