1. 程式人生 > >Kafka與.net core(一)安裝

Kafka與.net core(一)安裝

1.安裝JDK

目前官網不能直接下載,在網上找到1.8.0版本安裝包下載到本地。

1.1.下載jdk並解壓

[[email protected] java]# ls
jdk1.8.0_191  jdk-8u191-linux-x64.tar.gz

1.2.配置java環境變數

在檔案中/etc/profile追加配置:

export JAVA_HOME=/usr/local/java/jdk1.8.0_191
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH
=$PATH:$JAVA_HOME/bin

使配置生效

[[email protected] java]# source /etc/profile

1.3.驗證jdk是否安裝成功

[[email protected] java]# java -version
java version "1.8.0_191"
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

2.安裝zookeeper

2.1.下載

http://zookeeper.apache.org/releases.html

2.2.解壓

tar –zxvf zookeeper-3.4.10.tar.gz

2.3.複製conf目錄下的zoo_sample.cfg,並命名為zoo.cfg

2.4.修改zoo.cfg配置檔案

複製程式碼

# 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/zookeeper-3.4.10/data

dataLogDir=/usr/local/zookeeper/zookeeper-3.4.10/logs

# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1


#2888,3888 are election port
server.1=39.**.**.**:2888:3888   #改成自己ip

複製程式碼

其中,2888埠號是服務之間通訊的埠,而3888是;zookeeper與其他應用程式通訊的埠.

2.5.建立myid檔案

建立dataDir引數指定的目錄(這裡指的是“/usr/local/zookeeper/zookeeper-3.4.10/data”),並在目錄下建立檔案,命名為“myid”。

2.6.編輯myid檔案

在對應的IP的機器上輸入對應的編號。如在zookeeper上,“myid”檔案內容就是1。由於本次只在單點上進行安裝配置,所以只有一個server.1。若還有其他伺服器,比如地址為192.168.1.102,則在zoo.cfg檔案中還需加入server.2=192.168.1.102:2888:3888。那麼myid檔案在192.168.1.102伺服器上的內容就是2。至此,如果是多伺服器配置,就需要將zookeeper-3.4.3目錄拷貝到其他伺服器,然後按照上述的方法修改myid。

2.7.在/etc/profile檔案設定PATH

在profile檔案尾追加:

export PATH=$PATH:/usr/local/zookeeper/zookeeper-3.4.10/bin

安裝完畢!

2.8.啟動

zkServer.sh start

輸入jps命令檢視程序

1573 QuorumPeerMain
1654 Jps

其中,QuorumPeerMain是zookeeper程序,啟動正常。

檢視狀態:zkServer.sh status

-
JMX enabled by default
Using config: /usr/local/zookeeper-3.4.6/bin/../conf/zoo.cfg
Mode: standalone

啟動客戶端指令碼:zkCli.sh -server ip:2181

停止zookeeper程序:zkServer.sh stop

3.安裝kafka

下載地址:https://mirrors.cnnic.cn/apache/kafka 

3.1.下載kafka

wget https://mirrors.cnnic.cn/apache/kafka/2.1.0/kafka_2.11-2.1.0.tgz

解壓

tar -zxvf kafka_2.12-1.1.0.tgz

 

3.2.配置kafka環境變數

在/etc/profile檔案中追加配置:

export KAFKA_HOME=/usr/local/kafka/kafka_2.11-2.1.0
export PATH=$KAFKA_HOME/bin:$PATH

使配置生效

[[email protected] kafka]# source /etc/profile

3.3.驗證kafka是否安裝成功

[[email protected] kafka]#  echo $KAFKA_HOME
/usr/local/kafka/kafka_2.11-2.1.0

3.4.修改kafka配置檔案中以下配置

broker.id=0
listeners=PLAINTEXT://:9092

advertised.listeners=PLAINTEXT://你的ip:9092

zookeeper.connect=localhost:2181

3.4.啟動kafka服務

[[email protected] config]#  kafka-server-start.sh -daemon $KAFKA_HOME/config/server.properties
[[email protected] config]# jps
24177 QuorumPeerMain
899 Kafka
8506 Jps

3.4.關閉服務

先關閉kafka,在關閉zookeeper

 kafka-server-stop.sh
zookeeper-server-stop.sh

檢視服務是否已關閉

[[email protected] ~]# jps
15462 Jps