1,配置环境变量
MY_POD_NAME:当前Pod的名称
RABBITMQ_ERLANG_COOKIE:设置Erlang Cookie用于节点间通信安全验证,值来自/nfs/rabbitmq/lib/.erlang.cookie文件内容
RABBITMQ_NODENAME:根据Pod名称动态生成了RabbitMQ节点的名称
2,配置postStart函数,在Pod容器启动后执行的命令:脚本主要用于在RabbitMQ容器启动后,配置DNS,然后等待RabbitMQ服务启动并健康检查,最后判断并处理节点是否已加入集群的情况
lifecycle:
``postStart:
``exec``:
``command``:
``- ``/bin/sh
``- -c
``- >
``if
[ -z ``"$(grep rabbitmq /etc/resolv.conf)"
]; ``then
``sed
"s/^search \([^ ]\+\)/search rabbitmq.\1 \1/"
/etc/resolv``.conf > ``/etc/resolv``.conf.new;
``cat
/etc/resolv``.conf.new > ``/etc/resolv``.conf;
``rm
/etc/resolv``.conf.new;
``fi``;
``until
rabbitmqctl node_health_check; ``do
sleep
1; ``done``;
``if
[ -z ``"$(rabbitmqctl cluster_status | grep rabbitmq-0)"
]; ``then
``touch
/gotit
``rabbitmqctl stop_app;
``rabbitmqctl reset;
``rabbitmqctl join_cluster rabbit@rabbitmq-0;
``rabbitmqctl start_app;
``else
``touch
/notget
``fi``;
特别注意:``rabbitmq是服务名称,这个服务包含4369和25672端口号
3,配置service
端口号4369:Erlang Port Mapping Daemon (epmd)端口,用于Erlang节点之间的发现。
端口号25672:Erlang分布服务间通信端口,在RabbitMQ集群配置中用于节点间的通信。
以上配置完成后,可启用多个pods实例