準備:
3臺內(nèi)存4G的機器用于運行zookeeper腰埂,配置要求不高
3臺16核128G的機器槽棍,我這里使用的4核32G逼友,每臺運行一個bookkeeper和broker
域名:
zk1.test.com, zk2.test.com, zk3.test.com 分別指向3臺要運行zookeeper的機器
pulsar.test.com 指向另外三項機器(dnspod可以做負載均衡)
安裝java8
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
下載二進制文件壓縮包
wget https://archive.apache.org/dist/pulsar/pulsar-2.2.0/apache-pulsar-2.2.0-bin.tar.gz
tar xvfz apache-pulsar-2.2.0-bin.tar.gz
mv apache-pulsar-2.2.0 pulsar
下載connectors
wget https://archive.apache.org/dist/pulsar/pulsar-2.2.0/apache-pulsar-io-connectors-2.2.0-bin.tar.gz
tar xvfz apache-pulsar-io-connectors-2.2.0-bin.tar.gz
cp -r apache-pulsar-io-connectors-2.2.0/connectors pulsar
每臺機器進入到pulsar目錄開始配置
zookeeper
以第一臺機器為例
vim conf/zookeeper.conf#添加如下信息
本機的server要使用0.0.0.0
server.1=0.0.0.0:2888:3888
server.2=zk2.test.com:2888:3888
server.3=zk3.test.com:2888:3888
mkdir -p data/zookeeper
echo 1 > data/zookeeper/myid#其它兩臺分別添加2 3到myid
配置完三臺機器后啟動所有zookeeper
./pulsar-daemon start zookeeper#后臺方式啟動
#./pulsar zookeeper#前臺啟動
在任意一臺zookeeper機器上僅進行一次初始化元數(shù)據(jù)
./pulsar initialize-cluster-metadata \
--cluster cluster1 \#集群名稱
--zookeeper zk1.test.com:2181 \
--configuration-store zk1.test.com:2181 \
--web-service-url http://pulsar.test.com:8080 \
--web-service-url-tls https://pulsar.test.com:8443 \
--broker-service-url pulsar://pulsar.test.com:6650 \
--broker-service-url-tls pulsar+ssl://pulsar.test.com:6651
bookkeeper
vim conf/bookkeeper.conf#配置如下信息
advertisedAddress=自己的外網(wǎng)ip
zkServers=zk1.test.com:2181,zk2.test.com:2181,zk3.test.com:2181
#啟動所有bookkeeper節(jié)點
./pulsar-daemon start bookie#后臺
./bookkeeper bookie#前臺
./bookkeeper shell bookiesanity #測試
啟動過后會有緩存信息榴嗅,修改配置再次啟動會報錯,清除data目錄,并運行恢復(fù)命令
./bookkeeper autorecovery #恢復(fù)bookkeeper
broker
vim conf/broker.conf#配置如下信息
advertisedAddress=自己的外網(wǎng)ip
clusterName=cluster1 #上面zookeeper添加元數(shù)據(jù)時的名稱
zookeeperServers=zk1.test.com:2181,zk2.test.com:2181,zk3.test.com:2181
configurationStoreServers=zk1.test.com:2181,zk2.test.com:2181,zk3.test.com:2181
#啟動所有broker節(jié)點
./pulsar-daemon start broker#后臺
./pulsar broker#前臺
客戶端連接
客戶端連接的url是pulsar://pulsar.test.com:6650/
連接后可以使用默認主題收發(fā)消息
新建租戶(tenants)空間(namespaces)主題(topic)
./pulsar-admin tenants create yourname \
--allowed-clusters cluster1
./pulsar-admin namespaces create yourname/space
./pulsar-admin namespaces set-clusters yourname/space --clusters cluster1#為空間設(shè)置集群