Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ cd stages/4.5.0

#### 3. Cluster on Kubernetes

##### Deployment
Run:

```
Expand All @@ -81,6 +82,14 @@ cd stages/4.5.0

```

##### StatefulSet
Run:

```
cd templates
./play-kubernetes-statefulset.sh
```

#### 4. Cluster of Dledger storage

Run: (Note: This feature needs RMQ version is 4.4.0 or above)
Expand Down
4 changes: 2 additions & 2 deletions image-build/Dockerfile-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ RUN set -eux; \
curl -L https://archive.apache.org/dist/rocketmq/${ROCKETMQ_VERSION}/rocketmq-all-${ROCKETMQ_VERSION}-bin-release.zip.asc -o rocketmq.zip.asc; \
#https://www.apache.org/dist/rocketmq/KEYS
curl -L https://www.apache.org/dist/rocketmq/KEYS -o KEYS; \
\
gpg --import KEYS; \
gpg --batch --verify rocketmq.zip.asc rocketmq.zip; \
unzip rocketmq.zip; \
Expand All @@ -56,6 +55,7 @@ RUN set -eux; \
rm rocketmq.zip rocketmq.zip.asc KEYS; \
apk del .build-deps ; \
rm -rf /var/cache/apk/* ; \
rm -rf bin/*.cmd bin/mqbroker.numanode* ; \
rm -rf /tmp/*

# Copy customized scripts
Expand All @@ -69,7 +69,7 @@ EXPOSE 9876
# Override customized scripts for namesrv
RUN mv ${ROCKETMQ_HOME}/bin/runserver-customize.sh ${ROCKETMQ_HOME}/bin/runserver.sh \
&& chmod a+x ${ROCKETMQ_HOME}/bin/runserver.sh \
&& chmod a+x ${ROCKETMQ_HOME}/bin/mqnamesrv
&& chmod a+x ${ROCKETMQ_HOME}/bin/mqnamesrv

# Expose broker ports
EXPOSE 10909 10911 10912
Expand Down
10 changes: 5 additions & 5 deletions image-build/scripts/runbroker-customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ calculate_heap_sizes()
calculate_heap_sizes

# Dynamically calculate parameters, for reference.
Xms=$MAX_HEAP_SIZE
Xmx=$MAX_HEAP_SIZE
Xmn=$HEAP_NEWSIZE
MaxDirectMemorySize=$MAX_HEAP_SIZE
Xms=${JVM_MIN_HEAP_SIZE:-$MAX_HEAP_SIZE}
Xmx=${JVM_MAX_HEAP_SIZE:-$MAX_HEAP_SIZE}
Xmn=${JVM_NEW_HEAP_SIZE:-$HEAP_NEWSIZE}
MaxDirectMemorySize=${Xmx:-$MAX_HEAP_SIZE}
# Set for `JAVA_OPT`.
JAVA_OPT="${JAVA_OPT} -server -Xms${Xms} -Xmx${Xmx} -Xmn${Xmn}"
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8"
Expand All @@ -153,4 +153,4 @@ then
fi
else
$JAVA ${JAVA_OPT} $@
fi
fi
8 changes: 4 additions & 4 deletions image-build/scripts/runserver-customize.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ calculate_heap_sizes()
calculate_heap_sizes

# Dynamically calculate parameters, for reference.
Xms=$MAX_HEAP_SIZE
Xmx=$MAX_HEAP_SIZE
Xmn=$HEAP_NEWSIZE
Xms=${JVM_MIN_HEAP_SIZE:-$MAX_HEAP_SIZE}
Xmx=${JVM_MAX_HEAP_SIZE:-$MAX_HEAP_SIZE}
Xmn=${JVM_NEW_HEAP_SIZE:-$HEAP_NEWSIZE}
# Set for `JAVA_OPT`.
JAVA_OPT="${JAVA_OPT} -server -Xms${Xms} -Xmx${Xmx} -Xmn${Xmn}"
JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:-UseParNewGC"
Expand All @@ -139,4 +139,4 @@ JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"

$JAVA ${JAVA_OPT} $@
$JAVA ${JAVA_OPT} $@
116 changes: 116 additions & 0 deletions templates/kubernetes/statefulset/rocketmq-broker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# RocketMQ run.sh for Kubernetes
#
# Created by Lin.Ru@DaoCloud.io, 2020-05-20

apiVersion: v1
kind: Service
metadata:
name: rocketmq-broker-svc
labels:
app: rocketmq-broker-svc
service: rocketmq
spec:
ports:
- port: 10909
name: vipchannel
- port: 10911
name: server
- port: 10912
name: ha
clusterIP: None
selector:
app: rocketmq-broker
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: rocketmq-broker
spec:
serviceName: rocketmq-broker-svc
replicas: 4
selector:
matchLabels:
app: rocketmq-broker
template:
metadata:
labels:
app: rocketmq-broker
service: rocketmq
spec:
initContainers:
- name: init-dir
image: busybox
command:
- /bin/sh
- -c
- mkdir -p /data/rocketmq/store && chown -v 3000. /data/rocketmq/store
volumeMounts:
- name: store
mountPath: /data/rocketmq
containers:
- name: rocketmq
image: apacherocketmq/rocketmq:4.4.0-alpine
imagePullPolicy: Always
command:
- /bin/sh
- -c
- /run.sh
env:
- name: JVM_MIN_HEAP_SIZE
value: 512M
- name: JVM_MAX_HEAP_SIZE
value: 512M
- name: JVM_NEW_HEAP_SIZE
value: 256M
- name: RMQ_RUN_MODE
value: 2m-2s-sync
- name: RMQ_NAMESERVERS
value: rocketmq-ns-0.rocketmq-ns-svc:9876;rocketmq-ns-1.rocketmq-ns-svc:9876;rocketmq-ns-2.rocketmq-ns-svc:9876
securityContext:
runAsUser: 3000
resources:
requests:
memory: 1Gi
cpu: 300m
limits:
memory: 1Gi
cpu: 300m
ports:
- containerPort: 10909
name: vipchannel
- containerPort: 10911
name: server
- containerPort: 10912
name: ha
livenessProbe:
tcpSocket:
port: 10911
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
readinessProbe:
tcpSocket:
port: 10911
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
volumeMounts:
- name: store
mountPath: /data/rocketmq
- name: runsh
mountPath: /run.sh
subPath: run.sh
volumes:
- name: runsh
configMap:
defaultMode: 0755
name: rocketmq-run
volumeClaimTemplates:
- metadata:
name: store
spec:
storageClassName: data
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 50Gi
57 changes: 57 additions & 0 deletions templates/kubernetes/statefulset/rocketmq-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# RocketMQ run.sh for Kubernetes
#
# Created by Lin.Ru@DaoCloud.io, 2020-05-20

apiVersion: v1
kind: ConfigMap
metadata:
name: rocketmq-run
labels:
app: rocketmq-broker
data:
run.sh: |
#! /bin/sh

# RocketMQ run.sh for Kubernetes
#
# Created by Lin.Ru@DaoCloud.io, 2020-05-20

config=$ROCKETMQ_HOME/conf/broker.properties

GenProperties(){
host_id=${HOSTNAME##*-}
result=$(( $host_id % 2 ))

case $result in
0) # MASTER
# Set brokerRole for '2m-2s-async' & '2m-noslave' default to 'ASYNC_MASTER'
test "$RMQ_RUN_MODE" = "2m-2s-sync" && RMQ_BROKER_ROLE="SYNC_MASTER"
RMQ_BROKER_NAME=broker-$host_id
;;
1) # SLAVE
RMQ_BROKER_ROLE=SLAVE
RMQ_BROKER_NAME=broker-$(($host_id - 1))
;;
esac

RMQ_BROKER_ID=$host_id

echo "Generate Broker Properties"
{
echo "brokerClusterName=${RMQ_CLUSTER_NAME:-DefaultCluster}"
echo "brokerName=${RMQ_BROKER_NAME:-broker-a}"
echo "brokerId=${RMQ_BROKER_ID:-0}"
echo "deleteWhen=${RMQ_DELETE_WHEN:-40}"
echo "fileReservedTime=${RMQ_FILE_REV_TIME:-48}"
echo "brokerRole=${RMQ_BROKER_ROLE:-ASYNC_MASTER}"
echo "flushDiskType=${RMQ_FLUSH_DISKTYPE:-ASYNC_FLUSH}"
echo "storePathRootDir=/data/rocketmq/store"
} > $config
}

# Generate Config
GenProperties

# Startup
echo "Start Broker with id $RMQ_BROKER_ID"
sh mqbroker -n $RMQ_NAMESERVERS -c $config
74 changes: 74 additions & 0 deletions templates/kubernetes/statefulset/rocketmq-nameserver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# RocketMQ run.sh for Kubernetes
#
# Created by Lin.Ru@DaoCloud.io, 2020-05-20

apiVersion: v1
kind: Service
metadata:
name: rocketmq-ns-svc
labels:
app: rocketmq-ns-svc
service: rocketmq
spec:
ports:
- port: 9876
name: server
clusterIP: None
selector:
app: rocketmq-ns
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: rocketmq-ns
spec:
serviceName: rocketmq-ns-svc
replicas: 3
selector:
matchLabels:
app: rocketmq-ns
template:
metadata:
labels:
app: rocketmq-ns
service: rocketmq
spec:
containers:
- name: rocketmq
image: apacherocketmq/rocketmq:4.4.0-alpine
imagePullPolicy: Always
command:
- /bin/sh
- -c
- mqnamesrv
env:
- name: RMQ_MIN_HEAP_SIZE
value: 256M
- name: RMQ_MAX_HEAP_SIZE
value: 256M
- name: RMQ_NEW_HEAP_SIZE
value: 256M
securityContext:
runAsUser: 3000
resources:
requests:
memory: 512Mi
cpu: 200m
limits:
memory: 512Mi
cpu: 200m
ports:
- containerPort: 9876
name: server
livenessProbe:
tcpSocket:
port: 9876
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
readinessProbe:
tcpSocket:
port: 9876
initialDelaySeconds: 15
timeoutSeconds: 5
periodSeconds: 20
23 changes: 23 additions & 0 deletions templates/play-kubernetes-statefulset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Run nameserver and broker on your Kubernetes cluster
kubectl apply -f kubernetes/statefulset/rocketmq-nameserver.yaml

kubectl apply -f kubernetes/statefulset/rocketmq-configmap.yaml

kubectl apply -f kubernetes/statefulset/rocketmq-broker.yaml