Ubuntu快速安裝kafka集羣

搭建集羣做少需要三臺服務器 一個centos和兩個ubuntu
每臺都按照下面做:
安裝JDK

  sudo apt-get install default-jre
    java -version
    apt-get install default-jdk
    java -version
  1. 安裝:
sudo apt-get install zookeeper
/etc/init.d/zookeeper start  //自啓動

默認信息:

#安裝路徑
/usr/share/zookeeper
#配置文件
/etc/zookeeper/conf/zoo.cfg
2. 啓動zookeeper

cd /usr/share/zookeeper/bin
sudo sh zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /etc/zookeeper/conf/zoo.cfg
Starting zookeeper ... STARTED

啓動zookeeper時遇到錯誤以下錯誤

zkServer.sh: 157: zkServer.sh: Syntax error: "(" unexpected (expecting ";;")
原因是:zookeeper使用的shell版本和系統使用的shell版本不兼容,當前ubuntu系統的shell默認使用的是dash,而zookeeper使用的是bash
解決辦法:
dpkg-reconfigure dash
Tab 移動到NO(選擇否) 回車即可
驗證是否啓動成功
/usr/share/zookeeper/bin$ sudo zkCli.sh -server localhost:2181

Connecting to localhost:2181
Welcome to ZooKeeper!
JLine support is enabled

WATCHER::

WatchedEvent state:SyncConnected type:None path:null
zookeeper基本操作

啓動ZK服務: sh bin/zkServer.sh start

查看ZK服務狀態: sh bin/zkServer.sh status

停止ZK服務: sh bin/zkServer.sh stop

重啓ZK服務: sh bin/zkServer.sh restart 

3.1 配置文件
需要修改server連接地址 dataDir可以不修改 新增logDir=(可選)

# http://hadoop.apache.org/zookeeper/docs/current/zookeeperAdmin.html
  
# 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.
dataDir=/var/lib/zookeeper
# Place the dataLogDir to a separate physical disc for better performance
# dataLogDir=/disk2/zookeeper

# the port at which the clients will connect
clientPort=2181

# specify all zookeeper servers
# The fist port is used by followers to connect to the leader
# The second one is used for leader election
server.1=IP1:2888:3888
server.2=IP2:2888:3888
server.3=IP3:2888:3888


# To avoid seeks ZooKeeper allocates space in the transaction log file in
# blocks of preAllocSize kilobytes. The default block size is 64M. One reason
# for changing the size of the blocks is to reduce the block size if snapshots
# are taken more often. (Also, see snapCount).
#preAllocSize=65536

# Clients can submit requests faster than ZooKeeper can process them,
# especially if there are a lot of clients. To prevent ZooKeeper from running
# out of memory due to queued requests, ZooKeeper will throttle clients so that
# there is no more than globalOutstandingLimit outstanding requests in the
# system. The default limit is 1,000.ZooKeeper logs transactions to a
# transaction log. After snapCount transactions are written to a log file a
# snapshot is started and a new transaction log file is started. The default
# snapCount is 10,000.
#snapCount=1000

# If this option is defined, requests will be will logged to a trace file named
# traceFile.year.month.day. 
#traceFile=

# Leader accepts client connections. Default value is "yes". The leader machine
# coordinates updates. For higher update throughput at thes slight expense of
# read throughput the leader can be configured to not accept clients and focus
# on coordination.
#leaderServes=yes

安裝kafka

wget http://mirror.bit.edu.cn/apache/kafka/2.5.0/kafka_2.12-2.5.0.tgz
tar -zxvf kafka_2.12-2.5.0.tgz
mv  kafka_2.12-2.5.0.tgz kafka
cd kafka
//x修改配置文件 server.properties  其他可不變
broker.id=0   每臺服務器設置不同的值  
zookeeper.connect=ip1.3:2181,ip2:2181,ip3:2181

bin/kafka-server-start.sh -daemon  config/server.properties//啓動服務

bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic test //創建topic
bin/kafka-topics.sh --list --bootstrap-server localhost:9092  //查看topic
bin/kafka-console-producer.sh --bootstrap-server localhost:9092 --topic test //生產消息
> hello
> good moring
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning //消費者獲取消息
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章