关于消息队列:Pulsar学习笔记之-编译Jar包构建镜像部署集群

17次阅读

共计 2997 个字符,预计需要花费 8 分钟才能阅读完成。

编译 Pulsar Jar 包

拉取开源代码

mkdir ~/dev/apache
cd ~/dev/apache
git clone https://github.com/apache/pulsar.git
cd pulsar

#从 TAG v2.6.1 创立本地分支
git checkout -b v2.6.1_build v2.6.1 

编译 Jar 包,并打包成公布包

mvn install -DskipTests

# 查看编译后的后果
cd distribution/
tree ./

cd server/target
tree ./

部署本地单机模式 Pulsar

解压下面编译打包好的公布包,并启动单机模式,可用于本地开发测试

cd ~/dev/apache/pulsar/distribution/server/target

# 解压编译好的 Jar 包
tar -zxvf apache-pulsar-2.6.1-bin.tar.gz
cd apache-pulsar-2.6.1

# 批改单机模式的配置文件
vim conf/standalone.conf

# 启动单机模式 Pulsar
bin/pulsar standalone

# 敞开单机模式 Pulsar
Ctrl + c

单机模式开启 JWT 认证 配置示例

# 生成 secret 和 tokens
mkdir -p /tmp/test-jwt
bin/pulsar tokens create-secret-key --output /tmp/test-jwt/my-base64-secret.key --base64
bin/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

# 启动单机模式 Pulsar
bin/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.1
docker login --username=xxx --password=yyy registry.example.tabalt.net
docker 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-storage
helm repo add streamnative https://charts.streamnative.io
helm repo update
helm install local-storage-provisioner streamnative/local-storage-provisioner \
    --set namespace=local-storage -n local-storage
kubectl get pods -n local-storage -o wide

# 拉取 pulsar helm chart
mkdir pulsar
cd pulsar/
git clone https://github.com/apache/pulsar-helm-chart.git
cd pulsar-helm-chart
git checkout -b v2.6.1_deploy pulsar-2.6.1

# 部署 Pular
./scripts/pulsar/prepare_helm_release.sh -c -n pulsar -k pulsar
helm 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 pulsar

kubectl get pods -n pulsar -o wide

# 查看是 pod 镜像版本是否匹配
kubectl describe pod pulsar-bookie-0 -n pulsar | grep image

# 删除原来的 Pulsar(如有),请留神不要误删线上集群并确保别人未在应用
helm uninstall pulsar -n pulsar
kubectl delete namespace pulsar

正文完
 0