你好,游客 登录 注册 搜索
背景:
阅读新闻

MongoDB 副本集+分片 架构部署

[日期:2016-04-10] 来源:Linux社区  作者:lichangzai [字体: ]

Replica Set + Sharding  配置部署

准备工作

架构设计

 

需要三台机器(racdb,host8,host9)

  • 数据节点,sharding2
  • 每个shardingReplic Set方式,冗余度为3(主、从、延迟从)
  • mongos(路由节点),数量为3
  • config  server(配置服务器节点),数量为3
  • arbiter server(表决节点),数量为6

 

Mongodb ReplicaSET+Sharding架构如下:

 

系统配置

软件环境:

OSOracle Linux 6.5

MongoDB:mongodb3.2.3

 

下载地址:

mongodb-linux-x86_64-rhel62-3.2.3.tgz

 

更多MongoDB相关教程见以下内容

 

CentOS 编译安装 MongoDB与mongoDB的php扩展 http://www.linuxidc.com/Linux/2012-02/53833.htm

 

CentOS 6 使用 yum 安装MongoDB及服务器端配置 http://www.linuxidc.com/Linux/2012-08/68196.htm

 

Ubuntu 13.04下安装MongoDB2.4.3 http://www.linuxidc.com/Linux/2013-05/84227.htm

 

MongoDB入门必读(概念与实战并重) http://www.linuxidc.com/Linux/2013-07/87105.htm

 

Ubunu 14.04下MongoDB的安装指南 http://www.linuxidc.com/Linux/2014-08/105364.htm

 

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF] http://www.linuxidc.com/Linux/2012-07/66735.htm

 

Nagios监控MongoDB分片集群服务实战 http://www.linuxidc.com/Linux/2014-10/107826.htm

 

基于CentOS 6.5操作系统搭建MongoDB服务 http://www.linuxidc.com/Linux/2014-11/108900.htm

 

 

创建用户:

# groupadd mongod

# useradd -g mongod mongod

 

配置hosts

# vi /etc/hosts

10.1.5.x1     racdb                    racdb.localdomain

10.1.5.x2     host8       host8.localdomain

10.1.5.x3    host9       host9.localdomain

 

解压文件:

# tar zxvf mongodb-linux-x86_64-rhel62-3.2.3.tgz

# mv mongodb-linux-x86_64-3.x.x/ /home/mongod/mongodb

 

安装部署

1.     自动部署脚本

在三个机器分别配置shard1shard2arbiterconfig servermongos需要的参数文件

 

机器1racdb

# 数据节点

mkdir -p /home/mongod/mongodb/shard11

cat > /home/mongod/mongodb/shard11/shard11.conf <<EOF

shardsvr=true

replSet=shard1

port=28017

dbpath=/home/mongod/mongodb/shard11

oplogSize=2048

logpath=/home/mongod/mongodb/shard11/shard11.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

mkdir -p /home/mongod/mongodb/shard21

cat > /home/mongod/mongodb/shard21/shard21.conf <<EOF

shardsvr=true

replSet=shard2

port=28018

dbpath=/home/mongod/mongodb/shard21

oplogSize=2048

logpath=/home/mongod/mongodb/shard21/shard21.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

#表决节点

mkdir -p /home/mongod/mongodb/arbiter1

cat  >  /home/mongod/mongodb/arbiter1/arbiter1.conf <<EOF

shardsvr=true

replSet=shard1

port=28031

dbpath=/home/mongod/mongodb/arbiter1

oplogSize=100

logpath=/home/mongod/mongodb/arbiter1/arbiter1.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

mkdir -p /home/mongod/mongodb/arbiter2

cat > /home/mongod/mongodb/arbiter2/arbiter2.conf <<EOF

shardsvr=true

replSet=shard2

port=28032

dbpath=/home/mongod/mongodb/arbiter2

oplogSize=100

logpath=/home/mongod/mongodb/arbiter2/arbiter2.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

#配置节点

mkdir -p /home/mongod/mongodb/config/

cat > /home/mongod/mongodb/config/config1.conf <<EOF

configsvr=true

dbpath=/home/mongod/mongodb/config/

port=20000

logpath=/home/mongod/mongodb/config/config1.log

logappend=true

fork=true

httpinterface=true

#nojournal=true

EOF

 

#路由节点

mkdir -p /home/mongod/mongodb/mongos

cat > /home/mongod/mongodb/mongos/mongos1.conf <<EOF

configdb=racdb:20000,host8:20000,host9:20000

port=28885

chunkSize=100

logpath=/home/mongod/mongodb/mongos/mongos1.log

logappend=true

fork=true

EOF

 

 

机器2host8

#数据节点

mkdir -p /home/mongod/mongodb/shard12

cat > /home/mongod/mongodb/shard12/shard12.conf <<EOF

shardsvr=true

replSet=shard1

port=28017

dbpath=/home/mongod/mongodb/shard12

oplogSize=2048

logpath=/home/mongod/mongodb/shard12/shard12.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

 

mkdir -p /home/mongod/mongodb/shard22

cat > /home/mongod/mongodb/shard22/shard22.conf <<EOF

shardsvr=true

replSet=shard2

port=28018

dbpath=/home/mongod/mongodb/shard22

oplogSize=2048

logpath=/home/mongod/mongodb/shard22/shard22.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

 

#表决节点

mkdir -p /home/mongod/mongodb/arbiter1

cat  >  /home/mongod/mongodb/arbiter1/arbiter1.conf<<EOF

shardsvr=true

replSet=shard1

port=28031

dbpath=/home/mongod/mongodb/arbiter1

oplogSize=100

logpath=/home/mongod/mongodb/arbiter1/arbiter1.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

 

mkdir -p /home/mongod/mongodb/arbiter2

cat > /home/mongod/mongodb/arbiter2/arbiter2.conf <<EOF

shardsvr=true

replSet=shard2

port=28032

dbpath=/home/mongod/mongodb/arbiter2

oplogSize=100

logpath=/home/mongod/mongodb/arbiter2/arbiter2.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

 

#配置节点

mkdir -p /home/mongod/mongodb/config/

cat > /home/mongod/mongodb/config/config2.conf <<EOF

configsvr=true

dbpath=/home/mongod/mongodb/config/

port=20000

logpath=/home/mongod/mongodb/config/config2.log

logappend=true

fork=true

#nojournal = true

EOF

 

 

#路由节点

mkdir -p /home/mongod/mongodb/mongos

cat >/home/mongod/mongodb/mongos/mongos2.conf <<EOF

configdb=racdb:20000,host8:20000,host9:20000

port=28885

chunkSize=100

logpath=/home/mongod/mongodb/mongos/mongos2.log

logappend=true

fork=true

EOF

 

 

机器3host9

#数据节点

mkdir -p /home/mongod/mongodb/shard13

cat > /home/mongod/mongodb/shard13/shard13.conf <<EOF

shardsvr=true

replSet=shard1

port=28017

dbpath=/home/mongod/mongodb/shard13

oplogSize=2048

logpath=/home/mongod/mongodb/shard13/shard13.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

 

mkdir -p /home/mongod/mongodb/shard23

cat > /home/mongod/mongodb/shard23/shard23.conf <<EOF

shardsvr=true

replSet=shard2

port=28018

dbpath=/home/mongod/mongodb/shard23

oplogSize=2048

logpath=/home/mongod/mongodb/shard23/shard23.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

 

#表决节点

mkdir -p /home/mongod/mongodb/arbiter1

cat  >  /home/mongod/mongodb/arbiter1/arbiter1.conf<<EOF

shardsvr=true

replSet=shard1

port=28031

dbpath=/home/mongod/mongodb/arbiter1

oplogSize=100

logpath=/home/mongod/mongodb/arbiter1/arbiter1.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

mkdir -p /home/mongod/mongodb/arbiter2

cat > /home/mongod/mongodb/arbiter2/arbiter2.conf <<EOF

shardsvr=true

replSet=shard2

port=28032

dbpath=/home/mongod/mongodb/arbiter2

oplogSize=100

logpath=/home/mongod/mongodb/arbiter2/arbiter2.log

logappend=true

fork=true

rest=true

httpinterface=true

nojournal = true

EOF

 

 

#配置节点

mkdir -p /home/mongod/mongodb/config/

cat > /home/mongod/mongodb/config/config3.conf <<EOF

configsvr=true

dbpath=/home/mongod/mongodb/config/

port=20000

logpath=/home/mongod/mongodb/config/config3.log

logappend=true

fork=true

#nojournal = true

EOF

 

 

#路由节点

mkdir -p/home/mongod/mongodb/mongos

cat >/home/mongod/mongodb/mongos/mongos3.conf <<EOF

configdb=racdb:20000,host8:20000,host9:20000

port=28885

chunkSize=100

logpath=/home/mongod/mongodb/mongos/mongos3.log

logappend=true

fork=true

EOF

 

 

2. 启动服务

 

--Server1启动shard1shard2arbiter1arbiter2服务

# server 1

mongod --config /home/mongod/mongodb/shard11/shard11.conf

mongod --config /home/mongod/mongodb/shard21/shard21.conf

mongod --config /home/mongod/mongodb/arbiter1/arbiter1.conf

mongod --config /home/mongod/mongodb/arbiter2/arbiter2.conf

mongod --config /home/mongod/mongodb/config/config1.conf

 

--Server2启动shard1shard2arbiter1arbiter2服务

# server 2

mongod --config /home/mongod/mongodb/shard12/shard12.conf

mongod --config /home/mongod/mongodb/shard22/shard22.conf

mongod --config /home/mongod/mongodb/arbiter1/arbiter1.conf

mongod --config /home/mongod/mongodb/arbiter2/arbiter2.conf

mongod --config /home/mongod/mongodb/config/config2.conf

 

--Server3启动shard1shard2arbiter1arbiter2服务

# server 3

mongod --config /home/mongod/mongodb/shard13/shard13.conf

mongod --config /home/mongod/mongodb/shard23/shard23.conf

mongod --config /home/mongod/mongodb/arbiter1/arbiter1.conf

mongod --config /home/mongod/mongodb/arbiter2/arbiter2.conf

mongod --config /home/mongod/mongodb/config/config3.conf

 

然后在server1server2server3上分别启动mongos服务

# server1

mongos --config /home/mongod/mongodb/mongos/mongos1.conf

# server2

mongos --config /home/mongod/mongodb/mongos/mongos2.conf

# server2

mongos --config /home/mongod/mongodb/mongos/mongos3.conf

更多详情见请继续阅读下一页的精彩内容http://www.linuxidc.com/Linux/2016-04/130009p2.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款