首页 > 其他分享 >Kafka环境安装

Kafka环境安装

时间:2024-01-14 09:12:12浏览次数:29  
标签:-- local sudo 环境 kafka usr server 安装 Kafka

wget https://downloads.apache.org/kafka/3.6.1/kafka_2.13-3.6.1.tgz

sudo mkdir /usr/local/kafka-server && cd $_

sudo tar -xvzf ~/kafka_2.13-3.6.1.tgz --strip 1

sudo useradd -r -d /usr/local/kafka-server -s /usr/sbin/nologin kafka

sudo -u kafka mkdir -p /usr/local/kafka-server/logs

sudo -u kafka mkdir -p /usr/local/kafka-server/data

sudo touch /usr/local/kafka-server/test.txt

sudo chmod a+w /usr/local/kafka-server/test.txt

sudo -u kafka echo -e "消息甲\n消息乙(文件流)" > /usr/local/kafka-server/test.txt

 

sudo vi /usr/local/kafka-server/config/server.properties

# log.dirs=/tmp/kafka-logs
log.dirs=/usr/local/kafka-server/logs

# Listener name, hostname and port the broker will advertise to clients.
# If not set, it uses the value for "listeners".
#advertised.listeners=PLAINTEXT://your.host.name:9092

# Maps listener names to security protocols, the default is for them to be the same. See the config documentation for more details
#listener.security.protocol.map=PLAINTEXT:PLAINTEXT,SSL:SSL,SASL_PLAINTEXT:SASL_PLAINTEXT,SASL_SSL:SASL_SSL

 

sudo vi /usr/local/kafka-server/config/zookeeper.properties

# dataDir=/tmp/zookeeper
dataDir=/usr/local/kafka-server/data

 

sudo chown -R kafka:kafka /usr/local/kafka-server

 

sudo vi /etc/systemd/system/zookeeper.service

[Unit]
Requires=network.target remote-fs.target
After=network.target remote-fs.target

[Service]
Type=simple
User=kafka
ExecStart=/usr/local/kafka-server/bin/zookeeper-server-start.sh /usr/local/kafka-server/config/zookeeper.properties
ExecStop=/usr/local/kafka-server/bin/zookeeper-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

 

sudo vi /etc/systemd/system/kafka.service

[Unit]
Requires=zookeeper.service
After=zookeeper.service

[Service]
Type=simple
User=kafka
ExecStart=/bin/sh -c '/usr/local/kafka-server/bin/kafka-server-start.sh /usr/local/kafka-server/config/server.properties > /usr/local/kafka-server/logs/start-kafka.log 2>&1'
ExecStop=/usr/local/kafka-server/bin/kafka-server-stop.sh
Restart=on-abnormal

[Install]
WantedBy=multi-user.target

 

sudo systemctl daemon-reload

sudo systemctl enable --now zookeeper

sudo systemctl enable --now kafka

sudo systemctl status zookeeper

sudo systemctl status kafka

sudo systemctl restart zookeeper

sudo systemctl restart kafka

 

# 查看主题

sudo -u kafka /usr/local/kafka-server/bin/kafka-topics.sh --list --bootstrap-server localhost:9092

  # 新建主题

sudo -u kafka /usr/local/kafka-server/bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic TestTopic

 

# 查看主题

sudo -u kafka /usr/local/kafka-server/bin/kafka-topics.sh --list --bootstrap-server localhost:9092

TestTopic

 

# 订阅消息

sudo -u kafka /usr/local/kafka-server/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic TestTopic --from-beginning

 

# 发送消息

sudo -u kafka /usr/local/kafka-server/bin/kafka-console-producer.sh --broker-list localhost:9092 --topic TestTopic

 

# 删除主题

sudo -u kafka /usr/local/kafka-server/bin/kafka-topics.sh --bootstrap-server localhost:9092 --delete --topic TestTopic

 

# 文件流消息的使用

sudo -u kafka vi /usr/local/kafka-server/config/connect-standalone.properties

plugin.path=/usr/local/kafka-server/libs/connect-file-3.6.1.jar

 

sudo -u kafka vi /usr/local/kafka-server/config/connect-file-source.properties

name=local-file-source
connector.class=FileStreamSource
tasks.max=1
file=test.txt
topic=connect-test

 

cd /usr/local/kafka-server/

sudo -u kafka /usr/local/kafka-server/bin/connect-standalone.sh config/connect-standalone.properties config/connect-file-source.properties config/connect-file-sink.properties

  # 订阅主题

sudo -u kafka /usr/local/kafka-server/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic connect-test --from-beginning

  # 写文件 sudo -u kafka echo "文件流新信息" >> /usr/local/kafka-server/test.txt  

标签:--,local,sudo,环境,kafka,usr,server,安装,Kafka
From: https://www.cnblogs.com/terry-cc/p/17963353

相关文章

  • Vue3环境安装
    curl-o-https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh|bashbashinstall.shsource/home/cc/.bashrcnvm--version#安装指定的版本nvminstallv12.22.12#安装当前稳定的LTS版本nvminstall--lts#切换版本nvmusev20.11.0#查看本地已安装的Nod......
  • hyperf 3.1安装和配置php-zookeeper扩展
    Hyperf提供了分布式系统的外部化配置支持,默认适配了:由携程开源的 ctripcorp/apollo,由 hyperf/config-apollo 组件提供功能支持。阿里云提供的免费配置中心服务 应用配置管理(ACM,ApplicationConfigManager),由 hyperf/config-aliyun-acm 组件提供功能支持。ETCDNac......
  • docker安装nginx
    1、查找镜像源dockersearchnginx2、拉取img镜像dockerpullnginx:latest 3、创建Nginx配置文件启动前需要先创建Nginx外部挂载的配置文件(/home/nginx/conf/nginx.conf)之所以要先创建,是因为Nginx本身容器只存在/etc/nginx目录,本身就不创建nginx.conf文件当服务......
  • docker 安装mysql
    dockersearchmysql    #查找镜像源dockerpullmysql:latest   #拉取image解决方案1.先创建一个简单的mysql容器实例dockerrun-p3306:3306--namesample-mysql-eMYSQL_ROOT_PASSWORD=123456-dmysql:5.72.复制里面的/etc/mysql文件夹dockercpsample......
  • RockyLinux安装QEMU/KVM虚拟化
    一、QEMU/KVM技术简介QEMU/KVM是一种开源虚拟化技术,全称是QuickEmulator/KernelBasedVirtualMachine。它结合了QEMU的模拟器和KVM(内核虚拟机)的加速器,提供了基于硬件的全虚拟化和容器级的系统虚拟化能力。QEMU是一个用于模拟计算机硬件的开源软件,它可以模拟各种硬件设备,包括CP......
  • WSL2下Ubuntu中的Scala环境安装
    sudosed-i's/http:\/\/archive.ubuntu.com/https:\/\/mirrors.ustc.edu.cn/g'/etc/apt/sources.listsudoaptupdate&&sudoaptupgrade-ysudoaptinstallopenjdk-17-jdk-yvi~/.profileexportJAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd6......
  • Nocalhost 为 KubeSphere 提供更强大的云原生开发环境
    1应用商店安装NocalhostServer已集成在KubeSphere应用商店,直接访问:设置应用「名称」,确认应用「版本」和部署「位置」,点击「下一步」:在「应用设置」标签页,可手动编辑清单文件或直接点击「安装」。建议把service.type设置为ClusterIP,以确保安装不受Kubernetes网络环境......
  • spark 3.x idea linux远程开发环境搭建
    依赖包jdk8或11都行,不要到jdk17jdk17第一个问题是jdk内部类默认不允许反射,很多配置要改。scala2.13scala2.13版本是为scala3.0版本准备的,改进挺多。可通过scala编程(第四版)学习。hadoop3.2.1因为windowshadoopwinutils当前最新仅仅到3.2.1,所以最好是相......
  • Centos安装docker步骤
    安装docker1、Docker要求CentOS系统的内核版本高于3.10,查看本页面的前提条件来验证你的CentOS版本是否支持Docker。  通过uname-r命令查看你当前的内核版本:$uname-r2、使用root权限登录Centos。确保yum包更新到最新。   $sudoyumupdate移除旧......
  • VMware虚拟机安装银河麒麟桌面版V10系统
    1镜像下载1.1打开官网百度搜索或浏览器地址栏直接输入地址1.2找到镜像下载选择桌面版操作系统进行安装我们日常办公使用的是桌面版的系统,选择桌面版操作系统进行下载1.3申请试用现在安装系统需要填写申请试用表,填写完之后,才会调转到镜像下载随着国产系统的日益发展,......