這篇文章將為大家詳細(xì)講解有關(guān)CentOS7中怎么安裝kafka環(huán)境,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個(gè)參考,希望大家閱讀完這篇文章后對(duì)相關(guān)知識(shí)有一定的了解。
10年積累的網(wǎng)站設(shè)計(jì)制作、網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站策劃后付款的網(wǎng)站建設(shè)流程,更有東安免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
第一步:安裝zookeeper環(huán)境
1、下載zookeeper包 zookeeper-3.4.5.tar.gz 2、解壓至 /usr/local/zookeeper-3.4.5 3、在 /usr/local/zookeeper-3.4.5 創(chuàng)建兩個(gè)文件夾 #mkdir data #數(shù)據(jù)文件保存目錄 #mkdir logs #日志文件保存目錄
4、在conf目錄下新增zoo.cfg配置文件 內(nèi)容如下
# 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-3.4.5/data dataLogDir=/usr/local/zookeeper-3.4.5/logs # the port at which the clients will connect clientPort=2181
5、把zookeeper注冊(cè)為centos服務(wù)
#在/usr/lib/systemd/system 目錄下創(chuàng)建zookeeper.service文件 #vim /usr/lib/systemd/system/zookeeper.service [Unit] Description=zookeeper service After=network.target [Service] Type=forking ExecStart=/usr/local/zookeeper-3.4.5/bin/zkServer.sh start ExecReload=/usr/local/zookeeper-3.4.5/bin/zkServer.sh restart ExecStop=/usr/local/zookeeper-3.4.5/bin/zkServer.sh stop PrivateTmp=true [Install] WantedBy=multi-user.target
6、后續(xù)在文件/zookeeper/apache-zookeeper-3.5.6-bin/bin/zkEnv.sh開(kāi)頭處插入JAVA環(huán)境路徑:
JAVA_HOME="/usr/java/jdk1.8.0_231"
二、kafka安裝
1、把文件解壓到 /usr/local/kafka_2.12-1.0.2
2、修改配置文件/usr/local/kafka_2.12-1.0.2/config/server.properties
broker.id=1 # 唯一ID同一集群下broker.id不能重復(fù) listeners=PLAINTEXT://localhost:9092 # 監(jiān)聽(tīng)地址 log.dirs=/opt/kafka_2.11-1.0.1/data # 數(shù)據(jù)目錄 log.retention.hours=168 # kafka數(shù)據(jù)保留時(shí)間單位為hour 默認(rèn) 168小時(shí)即 7天 log.retention.bytes=1073741824 #(kafka數(shù)據(jù)量最大值,超出范圍自動(dòng)清理,和 log.retention.hours配合使用,注意其最大值設(shè)定不可超磁盤大?。? zookeeper.connect:192.168.8.13:2181 #(zookeeper連接ip及port,多個(gè)以逗號(hào)分隔)
3、注冊(cè)kafka為服務(wù)
#在/etc/systemd/system 目錄下創(chuàng)建kafka.service文件 #vim /etc/systemd/system/kafka.service [Unit] Description=kafka service After=network.target [Service] Type=forking ExecStart=/usr/local/kafka_2.12-1.0.2/bin/kafka-server-start.sh -daemon /usr/local/kafka_2.12-1.0.2/config/server.properties ExecStop=/usr/local/kafka_2.12-1.0.2/bin/kafka-server-stop.sh PrivateTmp=true [Install] WantedBy=multi-user.target
4、設(shè)置sasl加密
# 1.新建配置文件 vi ./config/kafka_server_jaas.conf # 文件內(nèi)容 # username定義一個(gè)公共的用戶名,用于節(jié)點(diǎn)之間進(jìn)行通信,user_xxxx主要是客戶端用來(lái)連接kafka的,等號(hào)后面是密碼,xxxxx是用戶名,這里大小寫(xiě)一個(gè)字都不能差,除了用戶名和密碼 KafkaServer { org.apache.kafka.common.security.plain.PlainLoginModule required username="admin" password="admin-sec" user_admin="admin-sec" user_producer="prod-sec" user_consumer="cons-sec"; }; # 2.修改kafka啟動(dòng)時(shí)的配置文件,server.properties # 我的做法是復(fù)制一份 cp ./config/server.properties ./config/server_sasl.properties # 修改內(nèi)容如下,在文末添加如下內(nèi)容: # 注意點(diǎn):192.168.8.13是我當(dāng)前主機(jī)ip,9092是kafka通信端口,其他的地方保持一致 listeners=SASL_PLAINTEXT://192.168.8.13:9092 security.inter.broker.protocol=SASL_PLAINTEXT sasl.enabled.mechanisms=PLAIN sasl.mechanism.inter.broker.protocol=PLAIN authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer allow.everyone.if.no.acl.found=true # 3.修改啟動(dòng)腳本 vi ./bin/kafka-server-start.sh # 找到 export KAFKA_HEAP_OPTS #添加jvm 參數(shù),注意kafka_server_jaas.conf文件是之前第一步創(chuàng)建的安全認(rèn)證文件 #-Djava.security.auth.login.config=/usr/local/software/kafka/config/kafka_server_jaas.conf if [ "x$KAFKA_HEAP_OPTS" = "x" ]; then export KAFKA_HEAP_OPTS="-Xmx1G -Xms1G -Djava.security.auth.login.config=/usr/local/software/kafka/config/kafka_server_jaas.conf" fi
關(guān)于CentOS7中怎么安裝kafka環(huán)境就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。