這篇文章主要講解了Python如何通過kerberos安全認(rèn)證操作kafka,內(nèi)容清晰明了,對此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會有幫助。
十余年的永年網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。營銷型網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整永年建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)建站從事“永年網(wǎng)站設(shè)計”,“永年網(wǎng)站推廣”以來,每個客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。如何通過Kerberos認(rèn)證.
1.安裝Kerberos客戶端
CentOS:
yum install krb5-workstation
使用which kinit查看是否安裝成功;
2.拷貝Kerberos配置文件
conf目錄下krb5.conf和kafka.keytab和jaas.conf拷貝到客戶端機(jī)器的etc目錄, 同時,krb5.conf中的kdc集群主機(jī)名和IP配置到客戶端機(jī)器hosts配置文件中
3.Kinit客戶端通過kerberos認(rèn)證
獲取Principal
klist -kt kafka.keytab
4.安裝python-gssapi
pip install gssapi
遇到的問題,如下:
a.在linux中執(zhí)行wget命令提示 -bash: wget: command not found 解決方法
yum -y install wget
b.報錯:bash: pip: command not found
wget https://bootstrap.pypa.io/get-pip.py python get-pip.py pip -V #查看pip版本
python -m pip install --upgrade --force pip easy_install -U setuptools pip install --upgrade setuptools
3.pip安裝出現(xiàn)Command “python setup.py egg_info” failed with error code 1 的解決方法
Traceback (most recent call last): File “”, line 1, in File “/tmp/pip-install-6HfDE3/gssapi/setup.py”, line 109, in raise Exception("Could not find main GSSAPI shared library. Please " Exception: Could not find main GSSAPI shared library. Please try setting GSSAPI_MAIN_LIB yourself or setting ENABLE_SUPPORT_DETECTION to ‘false'
Command “python setup.py egg_info” failed with error code 1 in /tmp/pip-install-6HfDE3/gssapi/
yum install -y krb5-devel.x86_64
4.關(guān)于error: command ‘gcc' failed with exit status 1錯誤的解決方法
yum install gcc python-devel
安裝kafka-python
pip install kafka-python
初始化環(huán)境變量
export KAFKA_OPTS="-Djava.security.auth.login.config=/etc/conf/jaas.conf -Djava.security.krb5.conf=/etc/krb5.conf"
Python操作kafka樣例
from kafka import KafkaProducer from kafka.errors import KafkaError import os class Kafka_Producer(): def __init__(self, kafkahost, kafkaport, kafkatopic): self.kafkaHost = kafkahost self.kafkaPort = kafkaport self.kafkatopic = kafkatopic self.producer = KafkaProducer( bootstrap_servers = '{kafka_host}:{kafka_port}'.format(kafka_host=self.kafkaHost,kafka_port=self.kafkaPort), security_protocol="SASL_PLAINTEXT", sasl_mechanism="GSSAPI", sasl_kerberos_service_name="kafka", compression_type='gzip' #壓縮方式 ) def sendFileData(self, params): try: f = open(params,'rb') parmasMessage = f.read(-1).strip() producer = self.producer producer.send(self.kafkatopic, parmasMessage) producer.flush() except KafkaError as e: print (e) def main(): filePath = "/home/public/data/" topic = "demo" producer = Kafka_Producer("xxx.xx.xx.xx","9092",topic) dirList = os.listdir(filePath) for fileName in dirList: producer.sendFileData(filePath+fileName) print('send success!!!') if __name__=='__main__': main()