Chinaunix首页 | 论坛 | 博客

OPS

  • 博客访问: 489851
  • 博文数量: 117
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1210
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-05 14:50
个人简介

hellow 运维

文章分类

全部博文(117)

文章存档

2019年(1)

2018年(1)

2017年(45)

2016年(38)

2015年(32)

我的朋友

分类: 系统运维

2016-03-16 10:01:28

1 mongdb的下载
       选择自己的版本
2:配置安装
$ tar zxvf mongodb-linux-x86_64-3.2.4.tgz
$ cd  cd mongodb-linux-x86_64-3.2.4

详细步骤

  1. 通过下列方式为每个节点建立必要的数据文件夹:

    mkdir -p /srv/mongodb/rs0-0 /srv/mongodb/rs0-1 /srv/mongodb/rs0-2
    

    将建立名为 “rs0-0”, “rs0-1”, 和 “rs0-2” 的文件夹,每个文件夹中将存储数据文件。

  2. 通过下述命令来启动 实例:

    第一个节点:

    mongod --port 27017 --dbpath /srv/mongodb/rs0-0 --replSet rs0 --smallfiles --oplogSize 128 或者         ./bin/mongod  --port 27017 --fork --logpath=/usr/local/mongodb/logs/mongoDB.log  --logappend --dbpath=./data/
    

    第二个节点:

    mongod --port 27018 --dbpath /srv/mongodb/rs0-1 --replSet rs0 --smallfiles --oplogSize 128
    

    第三个节点:

    mongod --port 27019 --dbpath /srv/mongodb/rs0-2 --replSet rs0 --smallfiles --oplogSize 128
    

    这些命令将启动复制集 rs0 中的各个节点,每个节点通过有着不同的端口,并通过 --dbpath 参数来设置不同数据文件夹。如果我们已经用了默认端口,其余的节点应该用其他的端口。

    The --smallfiles and --oplogSize settings reduce the disk space that each instance uses. This is ideal for testing and development deployments as it prevents overloading your machine. For more information on these and other configuration options, see .

  3. 我们需要指明所需连接的端口,来通过 命令连接到某个 实例。为了简单方便,我们可以通过下列命令来连接到第一个实例:

    mongo --port 27017
    
  4. 在 中使用 来初始化复制集。我们可以通过下列方式来设定复制集配置对象:

    rsconf = { _id: "rs0", members: [ { _id: 0, host: ":27017" } ] } 

    替换为我们的主机名,通过``rsconf`` 文件来 :

    rs.initiate( rsconf ) 
  5. 通过下述命令可以展示现有的:doc:复制集配置 :

    rs.conf() 

    复制集配置对象大致如下:

    { "_id" : "rs0", "version" : 4, "members" : [ { "_id" : 1, "host" : "localhost:27017" } ] } 
  6. 使用 连接到 ,并用过 命令来添加第二个和第三个 实例到复制集中。 将 替换为我们的主机名:

    rs.add(":27018") rs.add(":27019") 

    当完成后,一个完整的复制集便完成了。这个新的复制集将选举出一个 。

通过 命令来检查复制集的状态。
   7.在从服务器上上要设置

否则报错如下:not master and slaveok=false
阅读(3108) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~