rocketmq Lock failed,MQ already started -c参数
今天部署rocketmq集群时一台机器部署一个master 和slave,slave部署总是失败,通过查看日志显示下面的错误
java.lang.RuntimeException: Lock failed,MQ already started
at org.apache.rocketmq.store.DefaultMessageStore.start(DefaultMessageStore.java:214)
at org.apache.rocketmq.broker.BrokerController.start(BrokerController.java:654)
at org.apache.rocketmq.broker.BrokerStartup.start(BrokerStartup.java:62)
at org.apache.rocketmq.broker.BrokerStartup.main(BrokerStartup.java:56)
23:21:47.512 [main] ERROR RocketmqCommon - Failed to obtain the host name
java.net.UnknownHostException: slave02: slave02: unknown error
at java.net.InetAddress.getLocalHost(InetAddress.java:1505) ~[na:1.8.0_65]
at org.apache.rocketmq.common.BrokerConfig.localHostName(BrokerConfig.java:202) [rocketmq-common-4.2.0.jar:4.2.0]
at org.apache.rocketmq.common.BrokerConfig.<init>(BrokerConfig.java:39) [rocketmq-common-4.2.0.jar:4.2.0]
at org.apache.rocketmq.broker.BrokerStartup.createBrokerController(BrokerStartup.java:101) [rocketmq-broker-4.2.0.jar:4.2.0]
at org.apache.rocketmq.broker.BrokerStartup.main(BrokerStartup.java:56) [rocketmq-broker-4.2.0.jar:4.2.0]
Caused by: java.net.UnknownHostException: slave02: unknown error
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method) ~[na:1.8.0_65]
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928) ~[na:1.8.0_65]
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323) ~[na:1.8.0_65]
at java.net.InetAddress.getLocalHost(InetAddress.java:1500) ~[na:1.8.0_65]
... 4 common frames omitted
java.lang.RuntimeException: Lock failed,MQ already started
at org.apache.rocketmq.store.DefaultMessageStore.start(DefaultMessageStore.java:214)
at org.apache.rocketmq.broker.BrokerController.start(BrokerController.java:654)
at org.apache.rocketmq.broker.BrokerStartup.start(BrokerStartup.java:62)
at org.apache.rocketmq.broker.BrokerStartup.main(BrokerStartup.java:56)
23:22:32.218 [main] ERROR RocketmqCommon - Failed to obtain the host name
java.net.UnknownHostException: slave02: slave02: unknown error
at java.net.InetAddress.getLocalHost(InetAddress.java:1505) ~[na:1.8.0_65]
at org.apache.rocketmq.common.BrokerConfig.localHostName(BrokerConfig.java:202) [rocketmq-common-4.2.0.jar:4.2.0]
at org.apache.rocketmq.common.BrokerConfig.<init>(BrokerConfig.java:39) [rocketmq-common-4.2.0.jar:4.2.0]
at org.apache.rocketmq.broker.BrokerStartup.createBrokerController(BrokerStartup.java:101) [rocketmq-broker-4.2.0.jar:4.2.0]
at org.apache.rocketmq.broker.BrokerStartup.main(BrokerStartup.java:56) [rocketmq-broker-4.2.0.jar:4.2.0]
错误1. slave02: unknown error是由于我启动的时候启动命令没有-c走的默认的代码中的配置
public class BrokerConfig {
private static final Logger log = LoggerFactory.getLogger(LoggerName.COMMON_LOGGER_NAME); private String rocketmqHome = System.getProperty(MixAll.ROCKETMQ_HOME_PROPERTY, System.getenv(MixAll.ROCKETMQ_HOME_ENV));
@ImportantField
private String namesrvAddr = System.getProperty(MixAll.NAMESRV_ADDR_PROPERTY, System.getenv(MixAll.NAMESRV_ADDR_ENV));
@ImportantField
private String brokerIP1 = RemotingUtil.getLocalAddress();
private String brokerIP2 = RemotingUtil.getLocalAddress();
@ImportantField
private String brokerName = localHostName();
@ImportantField
private String brokerClusterName = "DefaultCluster";
@ImportantField
private long brokerId = MixAll.MASTER_ID;
private int brokerPermission = PermName.PERM_READ | PermName.PERM_WRITE;
错误2. Lock failed,MQ already started也是走的代码默认的配置
DefaultMessageStore.java
public void start() throws Exception { lock = lockFile.getChannel().tryLock(0, 1, false);
if (lock == null || lock.isShared() || !lock.isValid()) {
throw new RuntimeException("Lock failed,MQ already started");
} lockFile.getChannel().write(ByteBuffer.wrap("lock".getBytes()));
lockFile.getChannel().force(true); this.flushConsumeQueueService.start();
this.commitLog.start();
this.storeStatsService.start();
DefaultMessageStore.java
public DefaultMessageStore(final MessageStoreConfig messageStoreConfig, final BrokerStatsManager brokerStatsManager,
final MessageArrivingListener messageArrivingListener, final BrokerConfig brokerConfig) throws IOException {
this.messageArrivingListener = messageArrivingListener;
this.brokerConfig = brokerConfig;
this.messageStoreConfig = messageStoreConfig;
this.brokerStatsManager = brokerStatsManager;
this.allocateMappedFileService = new AllocateMappedFileService(this);
this.commitLog = new CommitLog(this);
this.consumeQueueTable = new ConcurrentHashMap<>(32); this.flushConsumeQueueService = new FlushConsumeQueueService();
this.cleanCommitLogService = new CleanCommitLogService();
this.cleanConsumeQueueService = new CleanConsumeQueueService();
this.storeStatsService = new StoreStatsService();
this.indexService = new IndexService(this);
this.haService = new HAService(this); this.reputMessageService = new ReputMessageService(); this.scheduleMessageService = new ScheduleMessageService(this); this.transientStorePool = new TransientStorePool(messageStoreConfig); if (messageStoreConfig.isTransientStorePoolEnable()) {
this.transientStorePool.init();
} this.allocateMappedFileService.start(); this.indexService.start(); this.dispatcherList = new LinkedList<>();
this.dispatcherList.addLast(new CommitLogDispatcherBuildConsumeQueue());
this.dispatcherList.addLast(new CommitLogDispatcherBuildIndex()); File file = new File(StorePathConfigHelper.getLockFile(messageStoreConfig.getStorePathRootDir()));
MappedFile.ensureDirOK(file.getParent());
lockFile = new RandomAccessFile(file, "rw");
}
BrokerController.java
public BrokerController(
final BrokerConfig brokerConfig,
final NettyServerConfig nettyServerConfig,
final NettyClientConfig nettyClientConfig,
final MessageStoreConfig messageStoreConfig
) {
this.brokerConfig = brokerConfig;
this.nettyServerConfig = nettyServerConfig;
this.nettyClientConfig = nettyClientConfig;
this.messageStoreConfig = messageStoreConfig;
.....剩余代码不贴了
MessageStoreConfig.java
public class MessageStoreConfig {
//The root directory in which the log data is kept
@ImportantField
private String storePathRootDir = System.getProperty("user.home") + File.separator + "store"; //The directory in which the commitlog is kept
@ImportantField
private String storePathCommitLog = System.getProperty("user.home") + File.separator + "store"
+ File.separator + "commitlog"; // CommitLog file size,default is 1G
private int mapedFileSizeCommitLog = 1024 * 1024 * 1024;
// ConsumeQueue file size,default is 30W
private int mapedFileSizeConsumeQueue = 300000 * ConsumeQueue.CQ_STORE_UNIT_SIZE;
// enable consume queue ext
private boolean enableConsumeQueueExt = false;
// ConsumeQueue extend file size, 48M
private int mappedFileSizeConsumeQueueExt = 48 * 1024 * 1024;
// Bit count of filter bit map.
// this will be set by pipe of calculate filter bit map.
private int bitMapLengthConsumeQueueExt = 64;
如果不加-c就是在默认路径下,自己可以去${user.dir}下去看看,肯定有这个目录
所以多次启动不加-c参数就会报上面错误
if (commandLine.hasOption('c')) {
String file = commandLine.getOptionValue('c');
if (file != null) {
configFile = file;
InputStream in = new BufferedInputStream(new FileInputStream(file));
properties = new Properties();
properties.load(in); properties2SystemEnv(properties);
MixAll.properties2Object(properties, brokerConfig);
MixAll.properties2Object(properties, nettyServerConfig);
MixAll.properties2Object(properties, nettyClientConfig);
MixAll.properties2Object(properties, messageStoreConfig); BrokerPathConfigHelper.setBrokerConfigPath(file);
in.close();
}
}
最后梳理一下启动流程
nohup sh mqbroker -c ${mqdir}/conf/2m-2s-sync/broker-a.properties &的启动流程
1.加载启动类BrokerStartup.java main方法
2.createBrokerController方法加载启动参数并确定使用默认配置还是读取对应的配置文件 主要是-c参数的作用
3.加载配置
有错误之处望指正。
rocketmq Lock failed,MQ already started -c参数的更多相关文章
- 通过rocketmq思考一下mq的设计取舍
1. RocketMQ路由中心NameServer 2. RocketMQ消息发送 3. RocketMQ消息存储 4. RocketMQ消息消费 5. 消息过滤FiterServer 6. Rock ...
- rocketmq安装部署过程(4.0.0版本)
准备工作 3个虚拟机节点的构成如下 : 安装步骤 操作过程 1.安装包已经上传至其中1个节点. 2.解压缩安装包 命令:unzip rocketmq-all-4.0.0-incubating-bin- ...
- Rocketmq 集群
写在前面 Rocketmq采用apache rockemq 4.2.0release版本. 源码路径(http://mirrors.shu.edu.cn/apache/rocketmq/4.2.0/r ...
- rocketmq 记
Rocketmq选型 Rocket是一个专业的队列服务,性能优于Rabbitmq,优势是性能和并发,源于Kafka的扩展版,增强了数据的可靠性. Rocketmq的队列类型 普通队列,广播队列.顺序队 ...
- RocketMQ中Broker的启动源码分析(二)
接着上一篇博客 [RocketMQ中Broker的启动源码分析(一)] 在完成准备工作后,调用start方法: public static BrokerController start(Broker ...
- MQ选型对比RabbitMQ RocketMQ ActiveMQ Kafka
几种MQ产品说明: ZeroMQ : 扩展性好,开发比较灵活,采用C语言实现,实际上他只是一个socket库的重新封装,如果我们做为消息队列使用,需要开发大量的代码 RabbitMQ :结合erla ...
- MQ选型对比RabbitMQ RocketMQ ActiveMQ
原文:MQ选型对比RabbitMQ RocketMQ ActiveMQ 几种MQ产品说明: ZeroMQ : 扩展性好,开发比较灵活,采用C语言实现,实际上他只是一个socket库的重新封装 ...
- MQ系列5:RocketMQ消息的发送模式
MQ系列1:消息中间件执行原理 MQ系列2:消息中间件的技术选型 MQ系列3:RocketMQ 架构分析 MQ系列4:NameServer 原理解析 在之前的篇章中,我们学习了RocketMQ的原理, ...
- RocketMQ源码 — 三、 Consumer 接收消息过程
Consumer pull message 订阅 在Consumer启动之前先将自己放到一个本地的集合中,再以后获取消费者的时候会用到,同时会将自己订阅的信息告诉broker 接收消息 consume ...
随机推荐
- ethereumjs/ethereumjs-block-2-api
https://github.com/ethereumjs/ethereumjs-block/blob/master/docs/index.md 详细的调用代码可见本博客的ethereumjs/eth ...
- java读写本地xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <confi ...
- windows安装PHP IIS MYSQL
https://www.cnblogs.com/huodong/p/4310425.html
- git 从远程仓克隆到本地新分支
克隆远程仓代码到本地 git clone http://******:8080/DEV1-WMALL_DQ/WMALL_DQ_Front.git // git 库地址 当前分支是master ...
- oracle安装程序异常终止解决办法
安装Oracle时总是会报程序异常终止,摸不着头脑,作为初学者一下就乱了分寸 工具/原料 Oracle软件包 win764位 方法/步骤 右击Oracle安装图标setup.exe,选 ...
- win 10 如何关闭自动更新
1.右键“此电脑”图标,点击“管理”,打开“计算机管理”窗口; 2.在“计算机管理”窗口中找到“服务和应用程序”,点击“服务”,打开“服务”窗口; 3.在“服务”中找到“Windows Update” ...
- #leetcode刷题之路23-合并K个排序链表
合并 k 个排序链表,返回合并后的排序链表.请分析和描述算法的复杂度. 示例:输入:[ 1->4->5, 1->3->4, 2->6]输出: 1->1->2- ...
- Homebrew(brew)安装MySQL成功后无法登录
Homebrew简称brew,OSX上的软件包管理工具,在Mac终端可以通过brew安装.更新.卸载各种软件,(简直就是神器级武器). 废话不多说,没安装brew自己去百度学习安装,这里就不多说了. ...
- 大数据调错系列之hadoop在开发工具控制台上打印不出日志的解决方法
(1)在windows环境上配置HADOOP_HOME环境变量 (2)在eclipse上运行程序 (3)注意:如果eclipse打印不出日志,在控制台上只显示 1.log4j:WARN No appe ...
- 《PHP基础全面总结》系列分享专栏
<PHP基础全面总结>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/201777.html 文章 PHP基础之运算符的使用方法 P ...