ubuntu搭建pulsar单集群

准备:

3台内存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机器上仅进行一次初始化元数据

./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=自己的外网ip
zkServers=zk1.test.com:2181,zk2.test.com:2181,zk3.test.com:2181
#启动所有bookkeeper节点
./pulsar-daemon start bookie#后台
./bookkeeper bookie#前台
./bookkeeper shell bookiesanity #测试

启动过后会有缓存信息,修改配置再次启动会报错,清除data目录,并运行恢复命令

./bookkeeper autorecovery  #恢复bookkeeper
broker
vim conf/broker.conf#配置如下信息
advertisedAddress=自己的外网ip
clusterName=cluster1 #上面zookeeper添加元数据时的名称
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节点
./pulsar-daemon start broker#后台
./pulsar broker#前台

客户端连接

客户端连接的url是pulsar://pulsar.test.com:6650/
连接后可以使用默认主题收发消息

新建租户(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#为空间设置集群

你可能感兴趣的:(ubuntu搭建pulsar单集群)