Pulsar学习笔记之 编译Jar包、构建镜像、部署集群

编译 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

你可能感兴趣的:(Pulsar学习笔记之 编译Jar包、构建镜像、部署集群)