linux下kafka與zookeeper集群部署

*********************************配置主機名,通過主機名連接機器*********************************

比如說,已經有了三臺主機

1,在linux上設置hostname,通過hostname來訪問linux虛擬機

1.1. 修改hosts文件

vim /etc/hosts#/etc/hosts 的內容一般有如下類似內容:
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.202.156    node1
192.168.202.157    node2
192.168.202.158    node3

node1我當時沒有專門加這一行,而是直接在127.0.0.1后面,把localhost.localdomain修改為 node1

1.2. 修改network

修改配置文件/etc/sysconfig/network
修改HOSTNAME=yournameNETWORKING=yes
HOSTNAME=node1

然后三臺機器重啟,reboot

重啟后,ssh node2 ,發現能通過主機名字,連上

*********************************不同機器間,免密訪問*********************************

通過secureCRT,send commands to all sessions,可以達到一個輸入,在多個linux中響應

免密訪問可以看 http://blog.chinaunix.net/uid-26284395-id-2949145.html

1、ssh-keygen

2、ssh-copy-id -i? /root/.ssh/id_rsa.pub node1? (更換node2、3,然后一共重復三遍,將每臺機器的publickey放到三臺機器中)

最后,可以查看 cat /root/.ssh/authorized_keys 是否有node1、2、3,有的話就是可以

通過ssh node1、2、3,可以分別連上三臺機器。

*********************************安裝clustershell*********************************

我的linux是CentOS6.5

去下載包?clustershell-1.6-1.el6.noarch.rpm — RPM RHEL6/CentOS6/SL6

https://github.com/cea-hpc/clustershell/downloads

執行命令,安裝:rpm -ivh?clustershell-1.6-1.el6.noarch.rpm

安裝成功后,

vim /etc/clustershell/groups在groups里面加一個組kafka: node[1-3]

這樣就把node[1-3] 加入到kafka這個組里面。

這樣,clustershell 安裝成功

clush? -g kafka -c /opt/kafka

可以將/opt/kafka復制到集群中這個組中去

*********************************安裝zookeeper,并啟動*********************************

?

cd zookeeper-3.4.10cd conf/cp zoo_sample.cfg zoo.cfgvim zoo.cfg 
加入:
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888clush -g kafka -c zoo.cfg clush -g kafka mkdir /tmp/zookeeperecho "1" > /tmp/zookeeper/myid[root@node1 conf]# clush -g kafka cat /tmp/zookeeper/myid 
node3: 3
node2: 2
node1: 1[root@node1 zookeeper-3.4.10]# clush -g kafka "/opt/kafka/zookeeper-3.4.10/bin/zkServer.sh start /opt/kafka/zookeeper-3.4.10/conf/zoo.cfg "
node1: ZooKeeper JMX enabled by default
node1: Using config: /opt/kafka/zookeeper-3.4.10/conf/zoo.cfg
node2: ZooKeeper JMX enabled by default
node3: ZooKeeper JMX enabled by default
node2: Using config: /opt/kafka/zookeeper-3.4.10/conf/zoo.cfg
node3: Using config: /opt/kafka/zookeeper-3.4.10/conf/zoo.cfg
node1: Starting zookeeper ... STARTED
node2: Starting zookeeper ... STARTED
node3: Starting zookeeper ... STARTED[root@node1 zookeeper-3.4.10]# clush -g kafka "/opt/kafka/zookeeper-3.4.10/bin/zkServer.sh status /opt/kafka/zookeeper-3.4.10/conf/zoo.cfg "
通過看各個節點的狀態,驗證zookeeper集群是否啟動成功
也可以通過看 2181/2888/3888這幾個端口是否都被占用來驗證

如果沒有啟動成功,那就可能是防火墻的問題,吧防火墻關了即可

clush -g kafka service iptables stop

接下來,可以看看三臺機器數據是不是同步的:
在 node1 上,用 zookeeper 的客戶端工具,連接服務器
bin/zkCli.sh -server node1:2181
#
#
#
#
ls /
會看到 / 下面的一些東西
也可以創建一個節點,并給他一個值hello:
create /test hello
ls / 可以看一下
然后在 node2 上,如果可以看到node1 創建的數據,說明數據是同步一致的:
bin/zkCli.sh -server node1:2181
get /test 可以看到剛才輸入的hello
通過quit可以退出

?

*********************************安裝kafka,并啟動*********************************

安裝:
修改server.properties 
broker.id=1
zookeeper.connect=node1:2181,node2:2181,node3:2181
修改完成后,分發到集群中
并單獨修改broker.id=2 、3 之類在三臺機器上啟動:
bin/kafka-server-start.sh -daemon config/server.properties
啟動后,查看9092端口是否被監聽
lsof -i:9092


?

在node1上創建消費者,接收消息

創建一個topic: [root@node1 kafka_2.
10-0.10.2.1]# bin/kafka-topics.sh --zookeeper node1:2181 --topic topic1 --create --partitions 3 --replication-factor 2 Created topic "topic1". 查看這個topic [root@node1 kafka_2.10-0.10.2.1]# bin/kafka-topics.sh --zookeeper node1:2181 --topic topic1 --describe Topic:topic1 PartitionCount:3 ReplicationFactor:2 Configs:Topic: topic1 Partition: 0 Leader: 1 Replicas: 1,3 Isr: 1,3Topic: topic1 Partition: 1 Leader: 2 Replicas: 2,1 Isr: 2,1Topic: topic1 Partition: 2 Leader: 3 Replicas: 3,2 Isr: 3,2 創建一個consumer,去接收生產者的消息 [root@node1 kafka_2.10-0.10.2.1]# bin/kafka-console-consumer.sh --zookeeper node1:2181 --topic topic1 Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].1 hello

?

在node2上創建生產者,生產消息
[root@node2 kafka_2.
10-0.10.2.1]# bin/kafka-console-producer.sh --broker-list node2:9092 --topic topic1 1 hello

?

查看已有的topic
bin/kafka-topics.sh --list --zookeeper node1:2181

?

Furthermore, ConsumerOffestChecker shows a row for each topic partition. Your topic topic5 does have some partitions.
  • Pid: partition ID
  • Offset: the latest committed offset for a partition for the corresponding consumer group
  • logSize: the number of messages stored in the partition
  • Lag: the number of not yet consumed message for a partition for the corresponding consumer group (ie, lag = logSize - offset)
  • Owner: unique ID of the running consumer thread

[orco@node1 kafka_2.10-0.10.1.1]$ bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zookeeper node1 --topic topic5 --group group1
[
2017-07-26 11:39:16,748] WARN WARNING: ConsumerOffsetChecker is deprecated and will be dropped in releases following 0.9.0. Use ConsumerGroupCommand instead. (kafka.tools.ConsumerOffsetChecker$) Group Topic Pid Offset logSize Lag Owner group1 topic5 0 0 0 0 none group1 topic5 1 10 10 0 none group1 topic5 2 0 0 0 none

?

有點記不清,eclipse中使用java api 調用kafka服務,好像額外需要在service.properties中修改下面這個

#listeners=PLAINTEXT://:9092

listeners=PLAINTEXT://192.168.202.156:9092

或者是

listeners=PLAINTEXT://node1:9092

不同機器,不同的node2 node3等等

轉載于:https://www.cnblogs.com/orco/p/6844757.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/254620.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/254620.shtml
英文地址,請注明出處:http://en.pswp.cn/news/254620.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

調用Xvid編碼器流程(基于xvid1.1.0)

xvid有兩種編碼方式:single pass和twopass single pass模式編碼簡單,速度也快,但最終效果不如twopass。 twopass就是視頻壓制需要經過兩次編碼,分別為twopass-1st pass(簡稱1pass)和twopass…

關于box-shadow屬性的一點心得

一般我用到box-shadow都是用于諸如按鈕,文本塊,某些圖標,css類似為: box-shadow: 1px 1px 5px rgba(0, 0, 0, .8);這樣,樣式看上去會更加柔和,或者增加了立體感。 我個人的理解上,box-shadow的本質就是本體…

Laravel核心解讀--控制器

控制器 控制器能夠將相關的請求處理邏輯組成一個單獨的類, 通過前面的路由和中間件兩個章節我們多次強調Laravel應用的請求在進入應用后首現會通過Http Kernel里定義的基本中間件 protected $middleware [\Illuminate\Foundation\Http\Middleware\CheckForMaintena…

C#枚舉、值、字符串的相互轉換

目錄枚舉的定義使用方式優點代碼示例枚舉的定義 枚舉是整數類型,用戶自定義的整數類型的一個集合。 使用方式 public enum A {a0,b1,c2 }注意:枚舉定義的不同變量之間要用“,”分割,結尾不需要加上“,” 優點 可以…

制作404頁面的重要性

在網站的運行過程中會面臨很多問題,當用戶搜索頁面時,會提示服務器出錯,請求的頁面不存在,程序配置錯誤等問題。用戶請求瀏覽網頁碰到這些的情況時,會自動跳出系統默認的錯誤提示,對用戶體驗造成不好的感觸…

明晰C++內存分配的五種方法的區別

在C中,內存分成5個區,他們分別是堆、棧、自由存儲區、全局/靜態存儲區和常量存儲區。 棧,就是那些由編譯器在需要的時候分配,在不需要的時候自動清楚的變量的存儲區。里面的變量通常是局部變量、函數參數等。 堆,就是那…

【BZOJ-4631】踩氣球 線段樹 + STL

4631: 踩氣球 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 224 Solved: 114[Submit][Status][Discuss]Description 六一兒童節到了, SHUXK 被迫陪著M個熊孩子玩一個無聊的游戲:有N個盒子從左到右排成一排,第i個盒子里裝著Ai個氣球。SH…

3D Reconstruction三維重建halcon算子,持續更新

目錄3D Reconstruction三維重建Binocular Stereo雙目立體binocular_disparitybinocular_disparity_mgbinocular_disparity_msbinocular_distancebinocular_distance_mgbinocular_distance_msdisparity_image_to_xyzdisparity_to_distancedisparity_to_point_3ddistance_to_disp…

遺傳算法初級

遺傳算法是一種基于仿生學的計算機算法,通過模擬自然進化和優勝劣汰法則來搜索問題的最優解(我會說這其實就是稍微改良了一下的暴搜?) 它是由美國的J.Holland于1975年提出來的玄學概率學混合暴力搜索方法,廣泛適用于尋找算法優解、機器學習、…

C++ vector容器類型

vector類為內置數組提供了一種替代表示&#xff0c;與string類一樣 vector 類是隨標準 C引入的標準庫的一部分 &#xff0c;為了使用vector 我們必須包含相關的頭文件 &#xff1a;#include <vector> 使用vector有兩種不同的形式&#xff0c;即所謂的數組習慣和 STL習慣…

redis在linux命令行下連續進行命令操作

redis-cli -a password -n 9 keys "friend*" -a 是auth -n 是選擇數據池 keys就是找key啦、 要是后面再跟上 xargs */redis-cli del redis-cli -a password -n 9 keys "friend*" | xargs redis-cli -a password -n 9 del 就完美了23333 轉載于:https://www…

Calibration校準halcon算子,持續更新

目錄Calibration校準Binocular雙目相機binocular_calibrationCalibration Object 校準物體caltab_pointscreate_caltabdisp_caltabfind_calib_objectfind_caltabfind_marks_and_posegen_caltabsim_caltabCamera parameter相機參數cam_mat_to_cam_parcam_par_to_cam_matdeserial…

javascript:正則表達式、一個表單驗證的例子

閱讀目錄 本文內容&#xff1a;正則表達式&#xff1a;利用正則表達式進行表單驗證的例子&#xff1a;回到頂部本文內容&#xff1a; 正則表達式正則表達式的使用方法正則表達式的特殊匹配字符正則表達式修飾符利用正則表達式進行表單驗證的例子首發日期&#xff1a;2018-05-13…

Spring_01 spring容器、控制反轉(IOC)、依賴注入(DI)

目錄 1 什么是spring框架 2 spring框架的特點 3 spring容器 3.1 什么是spring容器 3.2 spring容器創建對象的編程步驟 3.4 spring容器創建對象的方式 3.5 bean元素的幾個重要屬性 4 IOC 4.1 什么是IOC 4.2 什么事DI 4.3 DI的三種方式 1 什么是spring框架 是一個開源的用來簡化企…

EntityFramework 插件之EntityFramework.Extended (批量處理)

接手了一個用EF來做的項目&#xff0c;由于項目中使用的原生處理&#xff0c;導致很多update都是采用先select 后 update的方式來實現&#xff0c;同時無法批量執行邏輯如&#xff1a;根據訂單類型統一更新狀態等。所以在經過了N多查找之后 發現了一個國外寫的擴展插件EntityFr…

一個傳值的問題”*”與”*”

1/********************************************************* 2* Desc:參數傳遞&#xff1a;使用引用傳遞指針和直接傳遞指針地址的區別 3* Author:charley 4* DateTime:2010-12-7 11:00 02***********************************************************/ 03#include <…

Classification分類halcon算子,持續更新

目錄ClassificationGaussian Mixture Models高斯混合模型add_class_train_data_gmmadd_sample_class_gmmclassify_class_gmmclear_class_gmmclear_samples_class_gmmcreate_class_gmmdeserialize_class_gmmevaluate_class_gmmget_class_train_data_gmmget_params_class_gmmget_…

spring boot 擴展之AutoConfigurationImportListener

最近閱讀spring boot源碼時發現&#xff0c;發現當spring使用ConfigurationClassParser加載使用Configuration注解類后&#xff0c;會使用AutoConfigurationImportSelector對加載的 Configuration注解的類進行一次過濾。當AutoConfigurationImportSelector過濾完成后會自動加載…

classpath: spring 中的查找方式

Spring可以通過指定classpath*:與classpath:前綴加路徑的方式從classpath加載文件,如bean的定義文件.classpath*:的出現是為了從多個jar文件中加載相同的文件.classpath:只能加載找到的第一個文件. 比如 resource1.jar中的package com.test.rs 有一個 jarAppcontext.xml 文件,內…

《高效程序員的45個習慣》-之一

敏捷開發是當下最流行的開發方法&#xff0c;它采用的是一種以人為核心、迭代、循序漸進的開發思想&#xff0c;值得你關注和學習。 最近我就閱讀了一本有關敏捷開發的書籍&#xff0c;《高效程序員的45個習慣》。 它以“舉反例”的方式來講述了敏捷開發中程序員應該運用的…