MongoDB集群配置(一)

本文档详细介绍了MongoDB集群的配置过程,包括Config Server、Shard Server和mongos的原理,以及如何在CentOS 7.2环境下搭建MongoDB 3.4.2集群。配置步骤涉及创建用户和目录、配置服务、关闭防火墙和selinux、启动各组件等,确保集群正常运行。
摘要由CSDN通过智能技术生成

MongoDB集群配置(一)

本实验环境是:mongodb v3.4.2, 三台 CentOS v7.2,mongodb不同版本可能配置略有差异。

mongodb原理

mongodb可以通过命令行配置参数,也可以通过配置文件进行参数配置。

包括:mongos、config server、shard server几个部分。

Sharded Cluster

router

Connecting to a sharded cluster

Config Server

这里写图片描述

Shard Server

这里写图片描述

mongos

mongos

params of mongos

mongodb环境搭建

Servers

Create user and directories

directories

配置服务

**1. shard1 .conf**

[mongo@localhost config]$ pwd
/data/mongo/config
[mongo@localhost config]$ cat shard1.conf
systemLog:
  destination: file
  path: /data/mongo/logs/shard1.log
  logAppend: true
processManagement:
  fork: true
  pidFilePath: "/data/mongo/shard1/shard1.pid"
net:
  port: 10001
storage:
  dbPath: "/data/mongo/shard1"
  engine: wiredTiger
  journal:
    enabled: true
  directoryPerDB: true
operationProfiling:
  slowOpThresholdMs: 10
  mode: "slowOp"
replication:
  oplogSizeMB: 50
  replSetName: "shard1"
  secondaryIndexPrefetch: "all"
sharding:
  clusterRole: shardsvr

**2. shard2 .conf**

[mongo@localhost config]$ cat shard2.conf
systemLog:
  destination: file
  path: /data/mongo/logs/shard2.log
  logAppend: true
processManagement:
  fork: true
  pidFilePath: "/data/mongo/shard1/shard2.pid"
net:
  port: 10002
storage:
  dbPath: "/data/mongo/shard2"
  engine: wiredTiger
  journal:
    enabled: true
  directoryPerDB: true
operationProfiling:
  slowOpThresholdMs: 10
  mode: "slowOp"
replication:
  oplogSizeMB: 50
  replSetName: "shard2"
  secondaryIndexPrefetch: "all"
sharding:
  clusterRole: shardsvr

**3. shard3 .conf**

[mongo@localhost config]$ cat shard3.conf
systemLog:
  destination: file
  path: /data/mongo/logs/shard3.log
  logAppend: true
processManagement:
  fork: true
  pidFilePath: "/data/mongo/shard1/shard3.pid"
net:
  port: 10003
storage:
  dbPath: "/data/mongo/shard3"
  engine: wiredTiger
  journal:
    enabled: true
  directoryPerDB: true
operationProfiling:
  slowOpThresholdMs: 10
  mode: "slowOp"
replication:
  oplogSizeMB: 50
  replSetName: "shard3"
  secondaryIndexPrefetch: "all"
sharding:
  clusterRole: shardsvr

**4.  configsvr.conf**

[mongo@localhost config]$ cat configsvr.conf
systemLog:
  destination: file
  path: /data/mongo/logs/configsvr.log
  logAppend: true
processManagement:
  fork: true
  pidFilePath: "/data/mongo/configsvr/configsvr.pid"
net:
  port: 10004
storage:
  dbPath: "/data/mongo/configsvr"
  engine: wiredTiger
  journal:
    enabled: true
replication:
   replSetName: cfgRepSet
sharding:
  clusterRole: configsvr

**5. mongos.conf**

[mongo@localhost config]$ cat mongos.conf
systemLog:
  destination: file
  path: /data/mongo/logs/mongos.log
  logAppend: true
processManagement:
  fork: true
  pidFilePath: /data/mongo/mongos/mongos.pid
net:
  port: 10005
sharding:
  configDB: cfgRepSet/192.168.198.20:10004,192.168.198.21:10004,192.168.198.25:10004

在一台服务器上配置完后,直接把整个目录复制到另外两台服务器上。

关闭防火墙和selinux

启动sharded server

[mongo@localhost bin]$ ./mongod -f /data/mongo/config/shard1.conf
about to fork child process, waiting until server is ready for connections.
forked process: 20817
child process started successfully, parent exiting
[mongo@localhost bin]$ ./mongod -f /data/mongo/config/shard2.conf
about to fork child process, waiting until server is ready for connections.
forked process: 20912
child process started successfully, parent exiting
[mongo@localhost bin]$ ./mongod -f /data/mongo/config/shard3.conf
about to fork child process, waiting until server is ready for connections.
forked process: 20938
child process started successfully, parent exiting
[mongo@localhost bin]$ ./mongo --port 10001
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:10001/
MongoDB server version: 3.4.2
Server has startup warnings: 
2017-03-07T18:47:57.764+0800 I CONTROL  [initandlisten] 
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] 
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] 
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] 
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-03-07T18:47:57.765+0800 I CONTROL  [initandlisten] 
shard1:SECONDARY> 

根据提示需要在所有服务器上都关闭‘transparent_hugepage’服务。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值