首页
nfs做storageclass 参考
镜像下载
1、里面包含console页面
docker pull lhcre/rocketmq:4.8.0
2、推送到自己镜像仓库
docker tag lhcre/rocketmq:4.8.0 172.16.15.250/rocketmq:4.8.0
docker push 172.16.15.250/rocketmq:4.8.0
部署namesrv
1、namesrv.yml
---
kind: Service
apiVersion: v1
metadata:
name: service-rocketmq-namesrv-prod
labels:
app: service-rocketmq-namesrv-prod
spec:
ports:
- protocol: TCP
port: 9876
targetPort: 9876
selector:
app: pod-rocketmq-namesrv-prod
type: ClusterIP
clusterIP: None
sessionAffinity: ClientIP
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: statefulset-rocketmq-namesrv-prod
labels:
app: statefulset-rocketmq-namesrv-prod
spec:
replicas: 1
serviceName: service-rocketmq-namesrv-prod
selector:
matchLabels:
app: pod-rocketmq-namesrv-prod
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: pod-rocketmq-namesrv-prod
spec:
containers:
- image: 172.16.15.250/rocketmq:4.8.0
imagePullPolicy: Always
name: container-rocketmq-namesrv-prod
command:
- sh
args:
- mqnamesrv
ports:
- protocol: TCP
containerPort: 9876
resources:
requests:
cpu: 1
memory: 2Gi
limits:
cpu: 1
memory: 2Gi
readinessProbe:
tcpSocket:
port: 9876
initialDelaySeconds: 10
periodSeconds: 5
livenessProbe:
tcpSocket:
port: 9876
initialDelaySeconds: 120
periodSeconds: 10
dnsPolicy: ClusterFirst
restartPolicy: Always
部署broker-master
1、broker-master-configmap.yml
apiVersion: v1
data:
broker.conf: |-
#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,名字可重复,为了管理,每个master起一个名字,他的slave同他,eg:Amaster叫broker-a,他的slave也叫broker-a
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割,也可以在broker启动的时候用-n参数指定 -n namesrvip:port
#namesrvAddr=172.16.207.2:9876;172.16.207.3:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口,
listenPort=10911
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=95
#存储路径
storePathRootDir=/home/rocketmq/store/broker-a
#commitLog 存储路径
storePathCommitLog=/home/rocketmq/store/broker-a/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq/store/broker-a/consumequeue
#消息索引存储路径
storePathIndex=/home/software/rocketmq/store/broker-a/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
flushDiskType=ASYNC_FLUSH
kind: ConfigMap
metadata:
name: broker-master
2、broker-master.yml
---
kind: Service
apiVersion: v1
metadata:
name: service-rocketmq-broker-master-prod
labels:
app: service-rocketmq-broker-master-prod
spec:
ports:
- name: rocketmq-port-10909
protocol: TCP
port: 10909
targetPort: 10909
- name: rocketmq-port-10911
protocol: TCP
port: 10911
targetPort: 10911
selector:
app: pod-rocketmq-broker-master-prod
type: ClusterIP
clusterIP: None
sessionAffinity: ClientIP
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: statefulset-rocketmq-broker-master-prod
labels:
app: statefulset-rocketmq-broker-master-prod
spec:
replicas: 1
serviceName: service-rocketmq-broker-master-prod
selector:
matchLabels:
app: pod-rocketmq-broker-master-prod
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: pod-rocketmq-broker-master-prod
spec:
imagePullSecrets:
- name: rocketmq-secret-key
containers:
- image: 172.16.15.250/rocketmq:4.8.0
securityContext:
privileged: true
imagePullPolicy: Always
name: container-rocketmq-broker-master-prod
command:
- sh
args:
- mqbroker
- '-n'
- 'statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq:9876'
- '-c'
- '/opt/soft/rocketmq/conf/2m-ws-async/broker-a.properties'
ports:
- protocol: TCP
containerPort: 10909
- protocol: TCP
containerPort: 10911
- protocol: TCP
containerPort: 10912
resources:
requests:
cpu: 1
memory: 2Gi
limits:
cpu: 1
memory: 2Gi
volumeMounts:
- name: rocket-broke-master
mountPath: /opt/soft/rocketmq/conf/2m-ws-async/broker-a.properties
subPath: broker-a.properties
- name: broker-master-pvc
mountPath: /home
readinessProbe:
tcpSocket:
port: 10909
initialDelaySeconds: 10
periodSeconds: 5
livenessProbe:
tcpSocket:
port: 10909
initialDelaySeconds: 120
periodSeconds: 10
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- name: rocket-broke-master
configMap:
name: broker-master
items:
- key: broker.conf
path: broker-a.properties
volumeClaimTemplates:
- metadata:
name: broker-master-pvc
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: "nfsone"
resources:
requests:
storage: 10Gi
部署broker-slave(主要是配置文件的区别)
1、broker-slave-configmap.yml
apiVersion: v1
data:
broker.conf: |-
#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,名字可重复,为了管理,每个master起一个名字,他的slav他,eg:Amaster叫broker-a,他的slave也叫broker-a
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=1
#nameServer地址,分号分割,也可以在broker启动的时候用-n参数指定 -n namesrvip:port
#namesrvAddr=172.16.207.2:9876;172.16.207.3:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口,
listenPort=10911
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=95
#存储路径
storePathRootDir=/home/rocketmq/store/broker-a
#commitLog 存储路径
storePathCommitLog=/home/rocketmq/store/broker-a/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq/store/broker-a/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq/store/broker-a/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq/store/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SLAVE
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
flushDiskType=ASYNC_FLUSH
kind: ConfigMap
metadata:
name: broker-slave
2、broker-slave.yml
---
kind: Service
apiVersion: v1
metadata:
name: service-rocketmq-broker-slave-prod
labels:
app: service-rocketmq-broker-slave-prod
spec:
ports:
- name: rocketmq-port-10909
protocol: TCP
port: 10909
targetPort: 10909
- name: rocketmq-port-10911
protocol: TCP
port: 10911
targetPort: 10911
selector:
app: pod-rocketmq-broker-slave-prod
type: ClusterIP
clusterIP: None
sessionAffinity: ClientIP
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: statefulset-rocketmq-broker-slave-prod
labels:
app: statefulset-rocketmq-broker-slave-prod
spec:
replicas: 1
serviceName: service-rocketmq-broker-slave-prod
selector:
matchLabels:
app: pod-rocketmq-broker-slave-prod
updateStrategy:
type: RollingUpdate
template:
metadata:
labels:
app: pod-rocketmq-broker-slave-prod
spec:
imagePullSecrets:
- name: rocketmq-secret-key
containers:
- image: 172.16.15.250/rocketmq:4.8.0
securityContext:
privileged: true
imagePullPolicy: Always
name: container-rocketmq-broker-slave-prod
command:
- sh
args:
- mqbroker
- '-n'
- 'statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq:9876'
- '-c'
- '/opt/soft/rocketmq/conf/2m-ws-async/broker-a-s.properties'
ports:
- protocol: TCP
containerPort: 10909
- protocol: TCP
containerPort: 10911
- protocol: TCP
containerPort: 10912
resources:
requests:
cpu: 1
memory: 2Gi
limits:
cpu: 1
memory: 2Gi
volumeMounts:
- name: rocket-broke-slave
mountPath: /opt/soft/rocketmq/conf/2m-ws-async/broker-a-s.properties
subPath: broker-a-s.properties
- name: broker-slave-pvc
mountPath: /home
readinessProbe:
tcpSocket:
port: 10909
initialDelaySeconds: 10
periodSeconds: 5
livenessProbe:
tcpSocket:
port: 10909
initialDelaySeconds: 120
periodSeconds: 10
dnsPolicy: ClusterFirst
restartPolicy: Always
volumes:
- name: rocket-broke-slave
configMap:
name: broker-slave
items:
- key: broker.conf
path: broker-a-s.properties
volumeClaimTemplates:
- metadata:
name: broker-slave-pvc
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: "nfsone"
resources:
requests:
storage: 10Gi
部署broker-console
1、broker-console.yaml
---
kind: Service
apiVersion: v1
metadata:
name: service-rocketmq-console-ng-prod
labels:
app: service-rocketmq-console-ng-prod
spec:
ports:
- protocol: TCP
port: 8080
targetPort: 8080
selector:
app: pod-rocketmq-console-ng-prod
type: ClusterIP
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: deployment-rocketmq-console-ng-prod
labels:
app: deployment-rocketmq-console-ng-prod
spec:
replicas: 1
selector:
matchLabels:
app: pod-rocketmq-console-ng-prod
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: pod-rocketmq-console-ng-prod
spec:
containers:
- image: 172.16.15.250/rocketmq:4.8.0
securityContext:
privileged: true
imagePullPolicy: IfNotPresent
workingDir: /opt/soft/rocketmq/lib
args:
- -jar
- rocketmq-console-ng-2.0.0.jar
- --rocketmq.config.namesrvAddr=statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocket:9876
command:
- java
name: container-rocketmq-console-ng-prod
ports:
- protocol: TCP
containerPort: 8080
resources:
requests:
cpu: 1
memory: 2Gi
limits:
cpu: 1
memory: 2Gi
readinessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 60
periodSeconds: 5
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 120
periodSeconds: 15
dnsPolicy: ClusterFirst
restartPolicy: Always
部署ingress
1、rocket-console-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: rocketmq-console-test
spec:
rules:
- host: rocketmq-console-test.cmbyc.com
http:
paths:
- path: /
backend:
serviceName: service-rocketmq-console-ng-prod
servicePort: 8080
所有文件准备好后部署
1、创建命名空间
kubectl create ns rocketmq-test
2、如果命名空间不是rocketmq,则执行
下面的命名方式podname:service:namespace,需要把namespace替换成 rocketmq-test
sed -i 's/statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq/statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq-test/g' broker-console.yml
sed -i 's/statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq/statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq-test/g' broker-master.yml
sed -i 's/statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq/statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq-test/g' broker-slave.yml
3、部署应用
for i in `ls`;do kubectl apply -f $i -n rocketmq-test;done
4、查看应用是否正常启动
kubectl get pod -n rocketmq-test
5、配置hosts
ip rocketmq-console-test.cmbyc.com
6、访问rocketmq-console
消息测试
1、进入容器发送消息
查找容器
[root@master1 rocket-test]# kubectl get pod -n rocketmq-test| grep broker-master
statefulset-rocketmq-broker-master-prod-0 1/1 Running 0 27m
进入容器
[root@master1 rocket-test]# kubectl exec -it statefulset-rocketmq-broker-master-prod-0 bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl kubectl exec [POD] -- [COMMAND] instead.
查看目录
bash-5.1# pwd
/opt/soft/rocketmq/bin
设置参数
bash-5.1# export NAMESRV_ADDR=statefulset-rocketmq-namesrv-prod-0.service-rocketmq-namesrv-prod.rocketmq-test:9876
生产信息
bash-5.1# sh tools.sh org.apache.rocketmq.example.quickstart.Producer
消费信息
bash-5.1#sh tools.sh org.apache.rocketmq.example.quickstart.Consumer
2、查看console界面