编译 Pulsar Jar包
拉取开源代码
mkdir ~/dev/apachecd ~/dev/apachegit clone https://github.com/apache/pulsar.gitcd pulsar#从TAG v2.6.1 创立本地分支git checkout -b v2.6.1_build v2.6.1
编译Jar包,并打包成公布包
mvn install -DskipTests# 查看编译后的后果cd distribution/tree ./cd server/targettree ./
部署本地单机模式 Pulsar
解压下面编译打包好的公布包,并启动单机模式,可用于本地开发测试
cd ~/dev/apache/pulsar/distribution/server/target# 解压编译好的Jar包tar -zxvf apache-pulsar-2.6.1-bin.tar.gzcd apache-pulsar-2.6.1# 批改单机模式的配置文件vim conf/standalone.conf# 启动单机模式Pulsarbin/pulsar standalone# 敞开单机模式PulsarCtrl + c
单机模式开启 JWT认证 配置示例
# 生成secret和tokensmkdir -p /tmp/test-jwtbin/pulsar tokens create-secret-key --output /tmp/test-jwt/my-base64-secret.key --base64bin/pulsar tokens create --secret-key file:///tmp/test-jwt/my-base64-secret.key --subject my-jwt-user > /tmp/test-jwt/my-jwt-user.tokens# 批改认证相干的配置项vim conf/standalone.conf authenticationEnabled=true authenticationProviders=org.apache.pulsar.broker.authentication.AuthenticationProviderToken tokenSecretKey=file:///tmp/test-jwt/my-base64-secret.key brokerClientAuthenticationPlugin=org.apache.pulsar.client.impl.auth.AuthenticationToken brokerClientAuthenticationParameters=file:///tmp/test-jwt/my-jwt-user.tokens# 启动单机模式Pulsarbin/pulsar standalone
构建Docker镜像
将上述编译打包好的公布包构建成Docker镜像
# 构建镜像cd ~/dev/apache/pulsar/docker./build.sh# 查看构建的镜像docker images | grep pulsar
推送镜像到镜像仓库
docker tag apachepulsar/pulsar-all:2.6.1 registry.example.tabalt.net/pulsar-test/pulsar-all:2.6.1docker login --username=xxx --password=yyy registry.example.tabalt.netdocker push registry.example.tabalt.net/pulsar-test/pulsar-all:2.6.0
部署Pulsar到K8s集群
# 登陆K8s master机器ssh k8s-master.example.tabalt.net# 装置本地存储卷kubectl create namespace local-storagehelm repo add streamnative https://charts.streamnative.iohelm repo updatehelm install local-storage-provisioner streamnative/local-storage-provisioner \ --set namespace=local-storage -n local-storagekubectl get pods -n local-storage -o wide# 拉取pulsar helm chartmkdir pulsarcd pulsar/git clone https://github.com/apache/pulsar-helm-chart.gitcd pulsar-helm-chartgit checkout -b v2.6.1_deploy pulsar-2.6.1# 部署Pular./scripts/pulsar/prepare_helm_release.sh -c -n pulsar -k pulsarhelm upgrade --install pulsar charts/pulsar \ --set images.zookeeper.repository=registry.example.tabalt.net/pulsar-test/pulsar-all \ --set images.bookie.repository=registry.example.tabalt.net/pulsar-test/pulsar-all \ --set images.autorecovery.repository=registry.example.tabalt.net/pulsar-test/pulsar-all \ --set images.broker.repository=registry.example.tabalt.net/pulsar-test/pulsar-all \ --set images.proxy.repository=registry.example.tabalt.net/pulsar-test/pulsar-all \ --set images.functions.repository=registry.example.tabalt.net/pulsar-test/pulsar-all \ --set bookkeeper.metadata.image.repository=registry.example.tabalt.net/pulsar-test/pulsar-all \ --set pulsar_metadata.image.repository=registry.example.tabalt.net/pulsar-test/pulsar-all \ --set namespace=pulsar --set volumes.local_storage=true \ -n pulsarkubectl get pods -n pulsar -o wide# 查看是pod镜像版本是否匹配kubectl describe pod pulsar-bookie-0 -n pulsar | grep image# 删除原来的Pulsar(如有),请留神不要误删线上集群并确保别人未在应用helm uninstall pulsar -n pulsarkubectl delete namespace pulsar