gznz12345 发表于 2018-10-27 08:39:32

安装及配置MONGODB CLUSTER

  主服务器:master 10.1.1.3
  从服务器:slave 10.1.1.4
  因为我是在VPS上安装的mongodb所以使用axel 来加速yum下载速度!
  添加安装mongodb yum源:
  # vim /etc/yum.repos.d/mongodb.repo
  
  name=MongoDB Repository
  baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
  gpgcheck=0
  enabled=1
  在主、从上都执行以下命令:
  # yum -y install mongo-10gen mongo-10gen-server
  安装完成后!
  配置主服务器:10.1.1.3 master
  # cat /etc/mongod.conf
  logpath = /var/log/mongo/mongod.log
  logappend = true
  fork = true
  port = 27017
  dbpath = /var/lib/mongo
  pidfilepath = /var/run/mongodb/mongod.pid
  master = true
  source = 10.1.1.4 #从服务器ip
  配置从服务器:10.1.1.4 slave1
  # cat /etc/mongod.conf
  logpath = /var/log/mongo/mongod.log
  logappend = true
  fork = true
  port = 27017
  dbpath = /var/lib/mongo
  pidfilepath = /var/run/mongodb/mongod.pid
  slave = true
  source = 10.1.1.3 #主服务器ip
  启动主数据库
  # service mongod start
  # chkconfig mongod on
  启动从数据库
  # service mongod start
  # chkconfig mongod on
  查看一下主服务器,日志数据库是否同步成功!
  # tail -f /var/log/mongo/mongod.log

  Mon Dec 16 15:01:11.572 creating replication oplog of>  Mon Dec 16 15:01:11.574 allocating new datafile /var/lib/mongo/local.1, filling with zeroes…
  Mon Dec 16 15:01:11.574 creating directory /var/lib/mongo/_tmp

  Mon Dec 16 15:01:11.603 done allocating datafile /var/lib/mongo/local.1,>  Mon Dec 16 15:01:11.604 ******
  Mon Dec 16 15:01:11.605 admin web console waiting for connections on port 28017
  Mon Dec 16 15:01:11.605 waiting for connections on port 27017
  Mon Dec 16 15:01:21.326 connection accepted from 10.1.1.4:49948 #1 (1 connection now open)
  Mon Dec 16 15:01:22.343 build index local.slaves { _id: 1 }
  Mon Dec 16 15:01:22.344 build index done. scanned 0 total records. 0.001 secs
  查看一下从服务器,日志数据库是否同步成功!
  # tail /var/log/mongo/mongod.log

  Mon Dec 16 15:01:20.069 done allocating datafile /var/lib/mongo/local.ns,>  Mon Dec 16 15:01:20.070 allocating new datafile /var/lib/mongo/local.0, filling with zeroes…

  Mon Dec 16 15:01:20.072 done allocating datafile /var/lib/mongo/local.0,>  Mon Dec 16 15:01:20.076 waiting for connections on port 27017
  Mon Dec 16 15:01:20.076 admin web console waiting for connections on port 28017
  Mon Dec 16 15:01:21.079 build index local.sources { _id: 1 }
  Mon Dec 16 15:01:21.081 build index done. scanned 0 total records. 0.001 secs
  Mon Dec 16 15:01:21.081 repl: syncing from host:10.1.1.3
  Mon Dec 16 15:01:21.097 build index local.me { _id: 1 }
  Mon Dec 16 15:01:21.099 build index done. scanned 0 total records. 0.001 secs
  登陆数据库创建一个数据库看是否能同步成功!
  # mongo
  MongoDB shell version: 2.4.8
  connecting to: test
  Welcome to the MongoDB shell.
  For interactive help, type “help”.
  For more comprehensive documentation, see
  http://docs.mongodb.org/
  Questions? Try the support group
  http://groups.google.com/group/mongodb-user
  > show dbs;
  local 1.078125GB
  > use kernal #这个命令就是create DB
  switched to db kernal
  > db.blog.save({title:”kernal”})
  > show dbs;
  kernal 0.203125GB
  local 1.078125GB
  > exit
  bye
  到从服务器上查看是否有数据同步过来!
  # mongo
  MongoDB shell version: 2.4.8
  connecting to: test
  Welcome to the MongoDB shell.
  For interactive help, type “help”.
  For more comprehensive documentation, see
  http://docs.mongodb.org/
  Questions? Try the support group
  http://groups.google.com/group/mongodb-user
  > show dbs;
  kernal 0.203125GB
  local 0.078125GB
  > exit
  bye
  到此MongoDB Cluster 安装完成!后续补上分片、聚合!

页: [1]
查看完整版本: 安装及配置MONGODB CLUSTER