mongodb集群搭建花费比较长的时间,在此记录下过程,方便以后使用

一 软件环境

系统:ubuntu 18.04,mongodb 社区版4.2 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

二 准备工作

在第一台电脑上的配置:

“sudo vim /etc/mongod.conf ”(无vim请自行配置)将127.0.0.1修改为0.0.0.0,重启“sudo service mongod restart”,绑定“ip sudo mongod --bind_ip localhost,192.168.3.17”,输出的结果如下:

dow@dow-ubuntu:/etc$ sudo mongod --bind_ip localhost,192.168.3.17

2019-10-15T15:01:49.108+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] MongoDB starting : pid=2331 port=27017 dbpath=/data/db 64-bit host=dow-ubuntu

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] db version v4.2.0

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] git version: a4b751dcf51dd249c5865812b390cfd1c0129c30

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.1 11 Sep 2018

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] allocator: tcmalloc

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] modules: none

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] build environment:

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] distmod: ubuntu1804

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] distarch: x86_64

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] target_arch: x86_64

2019-10-15T15:01:49.110+0800 I CONTROL [initandlisten] options: { net: { bindIp: "localhost,192.168.3.17" } }

2019-10-15T15:01:49.112+0800 I STORAGE [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.

2019-10-15T15:01:49.112+0800 I STORAGE [initandlisten]

2019-10-15T15:01:49.112+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine

2019-10-15T15:01:49.112+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem

2019-10-15T15:01:49.112+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3370M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],

2019-10-15T15:01:49.599+0800 I STORAGE [initandlisten] WiredTiger message [1571122909:599292][2331:0x7fa1ea155b00], txn-recover: Recovering log 2 through 3

2019-10-15T15:01:49.648+0800 I STORAGE [initandlisten] WiredTiger message [1571122909:648302][2331:0x7fa1ea155b00], txn-recover: Recovering log 3 through 3

2019-10-15T15:01:49.690+0800 I STORAGE [initandlisten] WiredTiger message [1571122909:690912][2331:0x7fa1ea155b00], txn-recover: Main recovery loop: starting at 2/24832 to 3/256

2019-10-15T15:01:49.752+0800 I STORAGE [initandlisten] WiredTiger message [1571122909:752130][2331:0x7fa1ea155b00], txn-recover: Recovering log 2 through 3

2019-10-15T15:01:49.792+0800 I STORAGE [initandlisten] WiredTiger message [1571122909:792466][2331:0x7fa1ea155b00], txn-recover: Recovering log 3 through 3

2019-10-15T15:01:49.824+0800 I STORAGE [initandlisten] WiredTiger message [1571122909:824030][2331:0x7fa1ea155b00], txn-recover: Set global recovery timestamp: (0,0)

2019-10-15T15:01:49.850+0800 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)

2019-10-15T15:01:49.876+0800 I STORAGE [initandlisten] Timestamp monitor starting

2019-10-15T15:01:49.880+0800 I CONTROL [initandlisten]

2019-10-15T15:01:49.880+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.

2019-10-15T15:01:49.880+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.

2019-10-15T15:01:49.880+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.

2019-10-15T15:01:49.880+0800 I CONTROL [initandlisten]

2019-10-15T15:01:49.924+0800 I SHARDING [initandlisten] Marking collection local.system.replset as collection version:

2019-10-15T15:01:49.926+0800 I STORAGE [initandlisten] Flow Control is enabled on this deployment.

2019-10-15T15:01:49.927+0800 I SHARDING [initandlisten] Marking collection admin.system.roles as collection version:

2019-10-15T15:01:49.927+0800 I SHARDING [initandlisten] Marking collection admin.system.version as collection version:

2019-10-15T15:01:49.929+0800 I SHARDING [initandlisten] Marking collection local.startup_log as collection version:

2019-10-15T15:01:49.929+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'

2019-10-15T15:01:49.930+0800 I SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version:

2019-10-15T15:01:49.930+0800 I NETWORK [initandlisten] Listening on /tmp/mongodb-27017.sock

2019-10-15T15:01:49.930+0800 I NETWORK [initandlisten] Listening on 127.0.0.1

2019-10-15T15:01:49.930+0800 I NETWORK [initandlisten] Listening on 192.168.3.17

2019-10-15T15:01:49.930+0800 I NETWORK [initandlisten] waiting for connections on port 27017

2019-10-15T15:01:49.930+0800 I SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version:

2019-10-15T15:01:58.232+0800 I NETWORK [listener] connection accepted from 192.168.3.16:42538 #1 (1 connection now open)

2019-10-15T15:01:58.232+0800 I NETWORK [conn1] received client metadata from 192.168.3.16:42538 conn1: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "4.2.0" }, os: { type: "Linux", name: "Ubuntu", architecture: "x86_64", version: "18.04" } }

2019-10-15T15:02:01.302+0800 I NETWORK [conn1] end connection 192.168.3.16:42538 (0 connections now open)

^C2019-10-15T15:02:03.220+0800 I CONTROL [signalProcessingThread] got signal 2 (Interrupt), will terminate after current cmd ends

2019-10-15T15:02:03.221+0800 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...

2019-10-15T15:02:03.221+0800 I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock

2019-10-15T15:02:03.221+0800 I - [signalProcessingThread] Stopping further Flow Control ticket acquisitions.

2019-10-15T15:02:03.222+0800 I CONTROL [signalProcessingThread] Shutting down free monitoring

2019-10-15T15:02:03.222+0800 I FTDC [signalProcessingThread] Shutting down full-time diagnostic data capture

2019-10-15T15:02:03.227+0800 I STORAGE [signalProcessingThread] Deregistering all the collections

2019-10-15T15:02:03.227+0800 I STORAGE [signalProcessingThread] Timestamp monitor shutting down

2019-10-15T15:02:03.227+0800 I STORAGE [signalProcessingThread] WiredTigerKVEngine shutting down

2019-10-15T15:02:03.233+0800 I STORAGE [signalProcessingThread] Shutting down session sweeper thread

2019-10-15T15:02:03.233+0800 I STORAGE [signalProcessingThread] Finished shutting down session sweeper thread

2019-10-15T15:02:03.233+0800 I STORAGE [signalProcessingThread] Shutting down journal flusher thread

2019-10-15T15:02:03.302+0800 I STORAGE [signalProcessingThread] Finished shutting down journal flusher thread

2019-10-15T15:02:03.302+0800 I STORAGE [signalProcessingThread] Shutting down checkpoint thread

2019-10-15T15:02:03.302+0800 I STORAGE [signalProcessingThread] Finished shutting down checkpoint thread

2019-10-15T15:02:03.335+0800 I STORAGE [signalProcessingThread] shutdown: removing fs lock...

2019-10-15T15:02:03.335+0800 I CONTROL [signalProcessingThread] now exiting

2019-10-15T15:02:03.335+0800 I CONTROL [signalProcessingThread] shutting down with code:0

三 再配置复制集(service mongod 未启动时才能配置副本集成功)

sudo mongod --replSet pointeye -f mongod.conf --fork



关于fork的解释:

fork: 以守护进程的方式运行MongoDB。指定日志输出路径,而不是输出到命令行。如果对文件夹有写权限的话,系统会在文件不存在时创建它。它会将已有文件覆盖掉,清除所有原来的日志记录。如果想保留原来的日志,还需要使用--logappend选项。如:

/> mongod --logpath=D:\logdata\mylog.log

all output going to: D:\logdata\mylog.log

需要说明的是,对于上例,logdata目录必须被提前手工创建,否则mongod将执行启动失败。

(对mongod参数的解释请参见文献3)

  1. 要注意的是,mongod服务应该要未启动时配置,否则会报错:
  2. ERRORchild process failed,exited with error number 48

  1. 如果连sudo 都不加,就会出现:
  2. ERRORchild process failed,exited with error number 1

  1. 这个错误的原因,可以在终端去掉--fork,就会出现错误提示。“/etc/mongo.conf”里配置的日志文件是"/var/log/mongodb/mongd.log"



实际上是一般用户无法访问系统目录下的日志文件。所以必须要加上"sudo"



四 重复二和三,以配置另外两台电脑(192.168.3.16,192.168.3.27)

五 进入一台电脑的mongodb shell ,并创建副本集配置文档 “config = {"_id":"pointeye","members":[{"_id":0,"host":"192.168.3.17:27017"},{"_id":1,"host":"192.168.3.16:27017"},{"_id":2,"host":"192.168.3.27:27017"}]}”





六 将config发送给其中一台副本集成员,使用config对象对副本集进行初始化:

  1. 192.168.3.17会解析这个配置对象,然后向其他成员发送消息,提醒它们使用新的配置。所有成员配置完成之后,它们会自动选出一个主节点,然后就可以正常地处理读写请求了

七 测试数据读写

插入post,并读取(请注意观察primary和secondary之间的变化)

参考文献:

  1. Kristina Chodorow,《MongoDB权威指南/第二版》,人民邮电出版社
  2. https://docs.mongodb.com/manual/tutorial/deploy-replica-set/
  3. https://www.cnblogs.com/sunhan/p/3646302.html

mongodb集群搭建过程记录的更多相关文章

  1. Linux下kafka集群搭建过程记录

    环境准备 zookeeper集群环境kafka是依赖于zookeeper注册中心的一款分布式消息对列,所以需要有zookeeper单机或者集群环境. 三台服务器: 172.16.18.198 k8s- ...

  2. Mongodb集群搭建过程及常见错误

    Replica Sets MongoDB 支持在多个机器中通过异步复制达到故障转移和实现冗余.多机器中同一时刻只 有一台是用于写操作.正是由于这个情况,为 MongoDB 提供了数据一致性的保障.担当 ...

  3. 懒人记录 Hadoop2.7.1 集群搭建过程

    懒人记录 Hadoop2.7.1 集群搭建过程 2016-07-02 13:15:45 总结 除了配置hosts ,和免密码互连之外,先在一台机器上装好所有东西 配置好之后,拷贝虚拟机,配置hosts ...

  4. 分布式实时日志系统(一)环境搭建之 Jstorm 集群搭建过程/Jstorm集群一键安装部署

    最近公司业务数据量越来越大,以前的基于消息队列的日志系统越来越难以满足目前的业务量,表现为消息积压,日志延迟,日志存储日期过短,所以,我们开始着手要重新设计这块,业界已经有了比较成熟的流程,即基于流式 ...

  5. Linux下MySQL/MariaDB Galera集群搭建过程【转】

    MariaDB介绍 MariaDB是开源社区维护的一个MySQL分支,由MySQL的创始人Michael Widenius主导开发,采用GPL授权许可证. MariaDB的目的是完全兼容MySQL,包 ...

  6. ZooKeeper集群搭建过程

    ZooKeeper集群搭建过程 提纲 1.ZooKeeper简介 2.ZooKeeper的下载和安装 3.部署3个节点的ZK伪分布式集群 3.1.解压ZooKeeper安装包 3.2.为每个节点建立d ...

  7. Mongodb 集群搭建以及常见错误

    Mongodb 集群搭建以及常见错误 1 关于Replica Sets +Sharding(主从复制加分片)搭建,不这详细去说,网上有很多,大部分的例子就三台服务器之间做主从复制,分2个shard,架 ...

  8. MongoDB集群搭建-副本集

    MongoDB集群搭建-副本集 概念性的知识,可以参考本人博客地址: 一.Master-Slave方案: 主从: 二.Replica Set方案: 副本集: 步骤:(只要按步骤操作,100%成功) 1 ...

  9. Mongodb集群搭建之 Replica Set

    Mongodb集群搭建之 Replica Set Replica Set 中文翻译叫做副本集,不过我并不喜欢把英文翻译成中文,总是感觉怪怪的.其实简单来说就是集群当中包含了多份数据,保证主节点挂掉了, ...

随机推荐

  1. sparkStreaming入门

    1.环境 jdk : 1.8 scala : 2.11.7 hadoop:2.7 spark : 2.2.0 2. 开发工具 idea 2017.2 3.maven的pom文件 <depende ...

  2. SpringCloud学习笔记《---01 概念 ---》篇

  3. Linux开机、重启和用户登录注销(2)

    1.关机&重启命令 1.1基本介绍 shutdown shutdown -h now :表示立即关机 shutdown -h 1:     表示1分钟后关机 shutdown -r now : ...

  4. (转)NodeJS - 第一个应用程序Hello World

    安装NodeJs 在创建实际的“Hello,World!”应用之前,我们应该先安装NodeJS,安装NodeJS可以访问NodeJS官网,下载相应系统的NodeJS的安装包,进行安装. 程序组件 关于 ...

  5. 小程序swiper-item内容过多显示不全的解决方案

    最近在项目遇到swiper高度不能自适应,导致swiper-item 里面的内容过多时只能显示一部分,最终解决方案:<swiper current="{{currentTab}}&qu ...

  6. art-template官方文档

    http://aui.github.io/art-template/zh-cn/docs/

  7. CentOS7配置Docker镜像加速器

    1. 将默认的配置文件复制出来 cp -n /lib/systemd/system/docker.service /etc/systemd/system/docker.service 2. 将加速器地 ...

  8. 2016.10.4初中部下午NOIP普及组比赛总结

    2016.10.4初中部下午NOIP普及组比赛总结 这次的题有些水,只是第四题有点坑. 题目: 比赛:AC+0+AC+50=250 改题:AC+AC+AC+50=350 一.Bill 满地都是水 题目 ...

  9. [Ynoi2012]D1T1

    题目 套路的根号分治啊 我们设置一个值\(S\) 对于\(S\leq x\)的操作,我们直接暴力修改,显然这样只会修改\(\frac{n}{S}\)次,所以我们需要一个能够\(O(1)\)修改的数据结 ...

  10. Reflections框架,类扫描工具

    Reflections是一个能提供一站式服务的对象. 巧用Reflections库实现包扫描(扫描某个包中某个接口实现.注解等) 它扫描工程的classpath,为元数据建索引,允许你运行时查询元数据 ...