浅看rabbitmq的mnesia部署

RabbitMQ修改数据目录MNESIA数据目录 Mnesia作为数据库存储引擎。Mnesia是一个基于Erlang语言开发的分布式数据库,其默认情况下将数据存储在节点的本地磁盘上。Mnesia提供了一个基于事务的存储系统,支持ACID属性(原子性、一致性、隔离性和持久性),可以保证数据的完整性和可靠性。Mnesia可以将数据存储在节点的本地磁盘上,也可以将数据存储在多个节点之间,从而实现数据的分布式存储和管理。在RabbitMQ中,Mnesia用于存储所有队列、交换器、绑定和节点的元数据信息。 阅读详情

转载:http://www.iteye.com/topic/643187

 

伸缩性:根据系统负载,可以在运行中过程中添加或者删除服务节点,改变系统处理规模。
mnesia是一个分布式数据库模块,由多个节点构成的数据库cluster,数据表的位置对应用是透明的。透过该特性,很容易构建出一个具有高伸缩性的系统。
rabbitmq是一个分布式的消息中间件,在mnesia-cluster的机制上可由多个节点共同构建。

rabbitmq在一个节点上初始化mnesia的过程概况如下:
1.启动mnesia,尝试连接到系统的其他节点上;
2.若无法连接到任何节点,表示该节点是系统中第一个启动的节点;
    2.1.在这种情况下可以检查数据库的老表,然后等待其他节点的连接;
3.若连接到一些节点,则这些节点会同步并合并schema表;
    3.1.在当前节点上创建schema表和其他数据表的副本后,该节点就和所连接的节点数据将保持同步和一致;

 

Java代码 
%%rabbit_mnesia.erl 
init_db(ClusterNodes) -> 
    case mnesia:change_config(extra_db_nodes, ClusterNodes -- [node()]) of 
    end 
%%rabbit_mnesia.erl
init_db(ClusterNodes) ->
    case mnesia:change_config(extra_db_nodes, ClusterNodes -- [node()]) of
    end
 启动mnesia后连接到其他节点。

 

Java代码 
%%rabbit_mnesia.erl 
    case mnesia:change_config(extra_db_nodes, ClusterNodes -- [node()]) of 
        {ok, []} ->  
%%rabbit_mnesia.erl
    case mnesia:change_config(extra_db_nodes, ClusterNodes -- [node()]) of
        {ok, []} ->
 无法连接到任何节点,则检查当前数据库目录下的老表是否正确。(数据库目录为空则建立新表)

 

Java代码 
%%rabbit_mnesia.erl 
    case mnesia:change_config(extra_db_nodes, ClusterNodes -- [node()]) of 
        {ok, [_|_]} -> 
            IsDiskNode = ClusterNodes == [] orelse %%ClusterNodes==[]主节点 
                lists:member(node(), ClusterNodes), 
            ok = wait_for_replicated_tables(), 
            ok = create_local_table_copy(schema, disc_copies), 
            ok = create_local_table_copies(case IsDiskNode of 
%%rabbit_mnesia.erl
    case mnesia:change_config(extra_db_nodes, ClusterNodes -- [node()]) of
        {ok, [_|_]} ->
            IsDiskNode = ClusterNodes == [] orelse %%ClusterNodes==[]主节点
                lists:member(node(), ClusterNodes),
            ok = wait_for_replicated_tables(),
            ok = create_local_table_copy(schema, disc_copies),
            ok = create_local_table_copies(case IsDiskNode of
成功连接到一些节点后,mnesia之间交换数据库元信息,并等待在当前节点上有磁盘副本(disc_copies)的表和cluster完成同步。
            ok = wait_for_replicated_tables(),
如果当前节点是数据存储节点,还要在该节点上建立一些表格的磁盘副本
            ok = create_local_table_copies(case IsDiskNode of

 

我做了些简单的实验来观察mnesia相互连接时的特性。

Java代码 
(a@localhost)1> mnesia:create_schema([node()]). 
ok 
(a@localhost)2> mnesia:start(). 
ok 
(a@localhost)3> mnesia:create_table(user, [{disc_copies, [node()]}]). 
{atomic,ok} 
(a@localhost)4> mnesia:info(). 
---> Processes holding locks <---  
---> Processes waiting for locks <---  
---> Participant transactions <---  
---> Coordinator transactions <--- 
---> Uncertain transactions <---  
---> Active tables <---  
user           : with 0        records occupying 304      words of mem 
schema         : with 2        records occupying 524      words of mem 
===> System info in version "4.4.10", debug level = none <=== 
opt_disc. Directory "/home/hwh/a" is used. 
use fallback at restart = false 
running db nodes   = [a@localhost] 
stopped db nodes   = []  
master node tables = [] 
remote             = [] 
ram_copies         = [] 
disc_copies        = [schema,user] 
disc_only_copies   = [] 
[{a@localhost,disc_copies}] = [schema,user] 
3 transactions committed, 0 aborted, 0 restarted, 1 logged to disc 
0 held locks, 0 in queue; 0 local transactions, 0 remote 
0 transactions waits for other nodes: [] 
ok 
(a@localhost)1> mnesia:create_schema([node()]).
ok
(a@localhost)2> mnesia:start().
ok
(a@localhost)3> mnesia:create_table(user, [{disc_copies, [node()]}]).
{atomic,ok}
(a@localhost)4> mnesia:info().
---> Processes holding locks <---
---> Processes waiting for locks <---
---> Participant transactions <---
---> Coordinator transactions <---
---> Uncertain transactions <---
---> Active tables <---
user           : with 0        records occupying 304      words of mem
schema         : with 2        records occupying 524      words of mem
===> System info in version "4.4.10", debug level = none <===
opt_disc. Directory "/home/hwh/a" is used.
use fallback at restart = false
running db nodes   = [a@localhost]
stopped db nodes   = []
master node tables = []
remote             = []
ram_copies         = []
disc_copies        = [schema,user]
disc_only_copies   = []
[{a@localhost,disc_copies}] = [schema,user]
3 transactions committed, 0 aborted, 0 restarted, 1 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
ok
 a节点上有两个磁盘表,分别是schema和user。

 

Java代码 
(b@localhost)1> mnesia:start(). 
ok 
(b@localhost)2> mnesia:change_config(extra_db_nodes, ['a@localhost', 'b@localhost', 'c@localhost']--[node()]). 
{ok,[a@localhost]} 
(b@localhost)1> mnesia:start().
ok
(b@localhost)2> mnesia:change_config(extra_db_nodes, ['a@localhost', 'b@localhost', 'c@localhost']--[node()]).
{ok,[a@localhost]}
 b节点尝试连接a,c节点,最终连接上了正在运行的a节点。连接之后b节点是什么状态呢?

 

Java代码 
(b@localhost)3> mnesia:info(). 
---> Processes holding locks <---  
---> Processes waiting for locks <---  
---> Participant transactions <---  
---> Coordinator transactions <--- 
---> Uncertain transactions <---  
---> Active tables <---  
schema         : with 2        records occupying 533      words of mem 
===> System info in version "4.4.10", debug level = none <=== 
opt_disc. Directory "/home/hwh/b" is NOT used. 
use fallback at restart = false 
running db nodes   = [a@localhost,b@localhost] 
stopped db nodes   = []  
master node tables = [] 
remote             = [user] 
ram_copies         = [schema] 
disc_copies        = [] 
disc_only_copies   = [] 
[{a@localhost,disc_copies}] = [user] 
[{a@localhost,disc_copies},{b@localhost,ram_copies}] = [schema] 
4 transactions committed, 0 aborted, 0 restarted, 0 logged to disc 
0 held locks, 0 in queue; 0 local transactions, 0 remote 
0 transactions waits for other nodes: [] 
ok 
(b@localhost)3> mnesia:info().
---> Processes holding locks <---
---> Processes waiting for locks <---
---> Participant transactions <---
---> Coordinator transactions <---
---> Uncertain transactions <---
---> Active tables <---
schema         : with 2        records occupying 533      words of mem
===> System info in version "4.4.10", debug level = none <===
opt_disc. Directory "/home/hwh/b" is NOT used.
use fallback at restart = false
running db nodes   = [a@localhost,b@localhost]
stopped db nodes   = []
master node tables = []
remote             = [user]
ram_copies         = [schema]
disc_copies        = []
disc_only_copies   = []
[{a@localhost,disc_copies}] = [user]
[{a@localhost,disc_copies},{b@localhost,ram_copies}] = [schema]
4 transactions committed, 0 aborted, 0 restarted, 0 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
ok
可以看到user表是remote的,在a节点上有磁盘副本,在b节点上没有任何类型的副本。schema表已经合并,分别存储在a,b节点上。
此时在b节点上就可操作user表,表的位置是透明的。

 

Java代码 
(b@localhost)4> mnesia:change_table_copy_type(schema, node(), disc_copies). 
{atomic,ok} 
(b@localhost)5> mnesia:add_table_copy(user, node(), disc_copies). 
{atomic,ok} 
(b@localhost)6> mnesia:info(). 
---> Processes holding locks <---  
---> Processes waiting for locks <---  
---> Participant transactions <---  
---> Coordinator transactions <--- 
---> Uncertain transactions <---  
---> Active tables <---  
user           : with 0        records occupying 304      words of mem 
schema         : with 2        records occupying 542      words of mem 
===> System info in version "4.4.10", debug level = none <=== 
opt_disc. Directory "/home/hwh/b" is used. 
use fallback at restart = false 
running db nodes   = [a@localhost,b@localhost] 
stopped db nodes   = []  
master node tables = [] 
remote             = [] 
ram_copies         = [] 
disc_copies        = [schema,user] 
disc_only_copies   = [] 
[{a@localhost,disc_copies},{b@localhost,disc_copies}] = [schema,user] 
6 transactions committed, 0 aborted, 0 restarted, 2 logged to disc 
0 held locks, 0 in queue; 0 local transactions, 0 remote 
0 transactions waits for other nodes: [] 
ok 
(b@localhost)4> mnesia:change_table_copy_type(schema, node(), disc_copies).
{atomic,ok}
(b@localhost)5> mnesia:add_table_copy(user, node(), disc_copies).
{atomic,ok}
(b@localhost)6> mnesia:info().
---> Processes holding locks <---
---> Processes waiting for locks <---
---> Participant transactions <---
---> Coordinator transactions <---
---> Uncertain transactions <---
---> Active tables <---
user           : with 0        records occupying 304      words of mem
schema         : with 2        records occupying 542      words of mem
===> System info in version "4.4.10", debug level = none <===
opt_disc. Directory "/home/hwh/b" is used.
use fallback at restart = false
running db nodes   = [a@localhost,b@localhost]
stopped db nodes   = []
master node tables = []
remote             = []
ram_copies         = []
disc_copies        = [schema,user]
disc_only_copies   = []
[{a@localhost,disc_copies},{b@localhost,disc_copies}] = [schema,user]
6 transactions committed, 0 aborted, 0 restarted, 2 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
ok
在b节点上建立schema表和user表的磁盘副本后,发现user表不再是remote属性了,可从本地直接读取。

 

先退出b节点,再退出a节点,然后只重启b节点。

Java代码 
(b@localhost)1> mnesia:start(). 
ok 
(b@localhost)2> mnesia:info(). 
---> Processes holding locks <---  
---> Processes waiting for locks <---  
---> Participant transactions <---  
---> Coordinator transactions <--- 
---> Uncertain transactions <---  
---> Active tables <---  
schema         : with 2        records occupying 542      words of mem 
===> System info in version "4.4.10", debug level = none <=== 
opt_disc. Directory "/home/hwh/b" is used. 
use fallback at restart = false 
running db nodes   = [b@localhost] 
stopped db nodes   = [a@localhost]  
master node tables = [] 
remote             = [] 
ram_copies         = [] 
disc_copies        = [schema,user] 
disc_only_copies   = [] 
[] = [user] 
[{b@localhost,disc_copies}] = [schema] 
2 transactions committed, 0 aborted, 0 restarted, 0 logged to disc 
0 held locks, 0 in queue; 0 local transactions, 0 remote 
0 transactions waits for other nodes: [] 
ok 
(b@localhost)3> mnesia:dirty_read(user, key). 
** exception exit: {aborted,{no_exists,[user,key]}} 
     in function  mnesia:abort/1 
(b@localhost)1> mnesia:start().
ok
(b@localhost)2> mnesia:info().
---> Processes holding locks <---
---> Processes waiting for locks <---
---> Participant transactions <---
---> Coordinator transactions <---
---> Uncertain transactions <---
---> Active tables <---
schema         : with 2        records occupying 542      words of mem
===> System info in version "4.4.10", debug level = none <===
opt_disc. Directory "/home/hwh/b" is used.
use fallback at restart = false
running db nodes   = [b@localhost]
stopped db nodes   = [a@localhost]
master node tables = []
remote             = []
ram_copies         = []
disc_copies        = [schema,user]
disc_only_copies   = []
[] = [user]
[{b@localhost,disc_copies}] = [schema]
2 transactions committed, 0 aborted, 0 restarted, 0 logged to disc
0 held locks, 0 in queue; 0 local transactions, 0 remote
0 transactions waits for other nodes: []
ok
(b@localhost)3> mnesia:dirty_read(user, key).
** exception exit: {aborted,{no_exists,[user,key]}}
     in function  mnesia:abort/1
 这时看到user表此时是不可用的,因为a,b节点共同维护user表的一致性,但是b节点先退出,所以user表的最终状态由a节点决定。
启动a节点之后,user表就变成可用状态了。

Java代码 
(a@localhost)1> mnesia:start(). 
(a@localhost)1> mnesia:start().
Java代码 
(b@localhost)4> mnesia:info().                
---> Processes holding locks <---  
---> Processes waiting for locks <---  
---> Participant transactions <---  
---> Coordinator transactions <--- 
---> Uncertain transactions <---  
---> Active tables <---  
user           : with 0        records occupying 304      words of mem 
schema         : with 2        records occupying 542      words of mem 
===> System info in version "4.4.10", debug level = none <=== 
opt_disc. Directory "/home/hwh/b" is used. 
use fallback at restart = false 
running db nodes   = [a@localhost,b@localhost] 
stopped db nodes   = []  
master node tables = [] 
remote             = [] 
ram_copies         = [] 
disc_copies        = [schema,user] 
disc_only_copies   = [] 
[{a@localhost,disc_copies},{b@localhost,disc_copies}] = [schema,user] 
3 transactions committed, 0 aborted, 0 restarted, 0 logged to disc 
0 held locks, 0 in queue; 0 local transactions, 0 remote 
0 transactions waits for other nodes: [] 
ok 

Rabbitmq启动失败--报错Mnesia is overloaded 文章目录1. 环境信息2. 发现问题3. 问题排查3.1 排查主机服务环境3.2 排查日志信息4. 问题解决 1. 环境信息 单节点rabbitmqRabbitMQ 3.7.0 on Erlang 19.3.6.4 2. 发现问题 主机意外断电后重启,发现启动rabbitmq时,命令超时报错 3. 问题排查 3.1 排查主机服务环境 查看到erlang的rabbitmq进程存在但是5672和15672端口没有拉起 3.2 排查日志信息 发现在启动之初就有告警信息,与文件句柄相关 大量Mnesia is 阅读详情

相关推荐

Mnesia: Erlang数据库(一)(学习笔记)

在下载和安装Erlang后,在磁盘上的数千个文件之中,已经内置了一个相当完备的数据库管理系统,它的名字叫做Mnesia。它非常快,而且,更妙的是可以直接存储任意的Erlang数据结构Mnesia可以根据需要灵活配置。比如说,既可以把数据表存储在内存中(数据的访问速度),也可以存储在磁盘上(数据的持久性),甚至还可以在不同的机器上建立同一份数据的多个副。

m0_62961827的博客 852

rabbitmq中的mnesia是什么

Mnesia 是一个分布式数据库,RabbitMQ 使用它来存储有关用户、交换器、队列和绑定的信息。 但是,消息不存储在数据库中。

出发之前永远是梦想,上路之后永远是挑战。 2124

Rabbitmq服务部署

摘要: 本文详细介绍了RabbitMQ的容器化部署方案,涵盖单节点与集群架构。部署前需规划端口资源(5672/15672)和目录结构(数据、配置、日志分离)。基础部署采用rabbitmq:3.13-management镜像,通过Docker Compose配置环境变量、持久化卷和健康检查。生产环境需强化安全(SSL加密、Erlang Cookie保护)、优化性能(内存/磁盘阈值)并启用高可用策略(镜像队列)。集群部署要求奇数节点,通过共享Cookie实现节点发现,配合负载均衡和Prometheus监控。

White Chuan 479

RabbitMQ集群部署

1.rabbitmq组建集群 1)安装rabbitmq-server yum install rabbitmq-server 2)在一个节点上面启动 service rabbitmq-server start 3)拷贝/var/lib/rabbitmq/.erlang.cookie  到其他节点的/var/lib/rabbitmq/目录下,注意保持权限一致。 所有节点重

倚南而立的专栏 2051

RabbitMQ集群架构终极指南:从Mnesia到Khepri的演进之路 [特殊字符]

RabbitMQ作为业界领先的开源消息中间件,其集群架构经历了从经典Mnesia到现代Khepri的重大变革。本文深度解析RabbitMQ集群架构的核心技术演进,帮助你全面理解这一重要转变。RabbitMQ集群架构的演进不仅提升了系统性能,更为企业级应用提供了更强的可靠性和扩展性。 ## 为什么RabbitMQ集群架构如此重要? RabbitMQ集群架构是支撑高可用消息系统的基石。在分布式系统

gitblog_00340的博客 949

ాలు步掌握RabbitMQ 4RR.0RR的蓝绿部署自动化与Khepri元数据引擎

你是否曾因消息队列集群升级而彻夜难眠?面对业务高峰期不敢停机,手动迁移又担心数据丢失?RabbitMQ 4.2.0带来了革命性的解决方案:**90%迁移时间减少**的蓝绿部署自动化工具链,以及**42%元数据操作性能提升**的全新Khepri引擎。本文将带你从零到一掌握这套生产级升级方案。 ## 为什么你需要关注RabbitMQ 4.2.0? 在微服务架构中,消息队列如同神经系统,连接着各个服

gitblog_00465的博客 1085

Honeydew生产环境部署Mnesia配置与故障恢复策略终极指南 [特殊字符]

Honeydew是Elixir生态系统中一个强大的分布式作业队列系统,专为生产环境设计。本文将深入探讨如何在生产环境中配置Mnesia队列并实施有效的故障恢复策略,确保您的作业队列系统稳定可靠运行。 ## 为什么选择Honeydew的Mnesia队列? 🤔 Honeydew的Mnesia队列提供了独特的优势,使其成为生产环境的理想选择: - **内置分布式支持**:原生支持多节点集群部署

gitblog_00578的博客 720

RabbitMQ普通集群部署+镜像

第二个地方就是/var/lib/rabbitmq/.erlang.cookie。各节点是通过⼀个magic cookie来实现的,这个cookie存放在/var/lib/rabbitmq/.erlang.cookie中,⽂件是400的权限。在RabbitMQ集群集群中,必须⾄少有⼀个磁盘节点,否则队列元数据⽆法写⼊到集群中,当磁盘节点宕掉时,集群将⽆法写⼊新的队列元数据信息。(1)默认rabbitmq启动后是磁盘节点,在这个cluster命令下,mq-2和mq-3是内存节点,mq-1是磁盘节点。

wjuey的博客 2070

深入理解OTP源码及其在RabbitMQ部署中的应用

本文还有配套的精品资源,点击获取 简介:OTP是Erlang的核心组件,用于构建高并发、分布式和容错系统。 otp_src_20.1.tar 是OTP的一个源码版本,通常用于手动编译安装。RabbitMQ依赖于Erlang的运行时系统,因此在部署RabbitMQ前必须安装Erlang OTP环境。文章详细介绍了OTP的关键特性,包括Erlang语言、进程模型、...

weixin_33256096的博客 1739

基于Linux系统rabbitmq集群部署

消息中间件rabbitmq单机模式部署、集群模式部署

qq_38697495的博客 1033

RabbitMQ Windows Server R2部署问题总结(三)

安装部署版本为:Microsoft Windows [版本 6.3.9600]保留所有权利。{error,{'SetConsoleMode','虏脦脢媒麓铆脦贸隆拢\r\n'}}}crasher:{error,{'SetConsoleMode','虏脦脢媒麓铆脦贸隆拢\r\n'}}links: []crasher:{id,user},crasher:该文提到erlang/OTP 26需要windows10以上内核。不在支持windows 2012 R2 更新了。

MAI44的博客 2082

mnesia部署

转载自:http://darkdestiny.iteye.com/blog/643187 伸缩性:根据系统负载,可以在运行中过程中添加或者删除服务节点,改变系统处理规模。 mnesia是一个分布式数据库模块,由多个节点构成的数据库cluster,数据表的位置对应用是透明的。透过该特性,很容易构建出一个具有高伸缩性的系统。 rabbitmq是一个分布式的消息中间件,在mnesi

mituan1234567的专栏 419

rabbitmq单机和集群部署

注意,替换后需检查该文件权限是否正确,若有变化需重新赋权。将三台mq的.erlang.cookie文件内容设置相同,该文件一般在用户目录下。RabbitMQ的安装需要Erlang环境,需要先安装ERlang环境并添加到系统环境变量中。需要注意的是版本对应关系,如下图。需要注意的是,以上步骤的顺序很重要,注意这边的停止mq节点并非停止mq进程,不可以直接kill掉mq进程!验证是否安装成功,执行下面的命令,若看到版本号则说明安装成功,如下图。先给该文件赋权为400,该文件必须为只读才可创建集群,即。

编程不良人 1475

RabbitMQ 4.2.0架构重构:企业级消息队列的零停机升级与性能突破

RabbitMQ 4.2.0版本标志着消息队列技术栈的重大范式迁移,通过Khepri元数据引擎的默认启用和蓝绿部署自动化工具链,为企业级应用提供了前所未有的可靠性和运维效率。本次升级不仅解决了传统Mnesia在网络分区时的数据一致性问题,更通过SQL流过滤和跨协议Direct Reply-To等创新特性,将消息处理能力提升到新的高度。 ## 元数据存储范式迁移:从Mnesia到Khepri的架构

gitblog_00101的博客 1072
上一篇: Linux系统中使用SystemTap调试内核
下一篇: Erlang shell debug调试
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值