Home >Database >Mysql Tutorial >MongoDB主从复制实验 master/slave

MongoDB主从复制实验 master/slave

WBOY
WBOYOriginal
2016-06-07 16:47:18812browse

MongoDB部署实验系列文章,MongoDB做为NoSQL数据库,最近几年持续升温,越来越多的企业都开始尝试用MongoDB代替原有Database做一

MongoDB部署实验系列文章,MongoDB做为NoSQL数据库,最近几年持续升温,,越来越多的企业都开始尝试用MongoDB代替原有Database做一些事情。MongoDB也在集群,分片,复制上也有相当不错的的表现。我通过将做各种MongoDB的部署实验进行介绍。

第一篇 MongoDB主从复制实验 master/slave,分为5个部分

系统环境介绍:

Ubuntu 12.04. LTS 64bit Server

简单安装MongoDB

在source.list文件中,增加10gen的源

~ vi /etc/apt/source.list
deb dist 10gen
~ sudo apt-get update
~ sudo apt-get install mongodb-10gen

初始化文件目录(MongoDB存储)

~ pwd
/home/conan/dbs

~ mkdir master slave
~ ls -l
drwxrwxr-x 2 conan conan 4096 May 31 13:54 master/
drwxrwxr-x 2 conan conan 4096 May 31 14:04 slave/

启动master

~ mongod --dbpath /home/conan/dbs/master --port 10000 --master --rest --nojournal --fork --logpath /home/conan/dbs/master.log
about to fork child process, waiting until server is ready for connections.
forked process: 4827
all output going to: /home/conan/dbs/master.log
child process started successfully, parent exiting

m2

启动slave

~ mongod --dbpath /home/conan/dbs/slave --port 10001 --slave --source localhost:10000 --rest --nojournal --fork --logpath /home/conan/dbs/slave.log
about to fork child process, waiting until server is ready for connections.
forked process: 5062
all output going to: /home/conan/dbs/slave.log
child process started successfully, parent exiting

m3

 

向master插入数据测试

~ mongo localhost:10000
MongoDB shell version: 2.4.3
connecting to: localhost:10000/test
> db.master.insert({uid:1000})
> db.master.find()
{ "_id" : ObjectId("51a83e979d113ea810e6ddbd"), "uid" : 1000 }

在slave中查询数据

~ mongo localhost:10001
MongoDB shell version: 2.4.3
connecting to: localhost:10001/test
> db.master.find()
{ "_id" : ObjectId("51a83e979d113ea810e6ddbd"), "uid" : 1000 }

 

在slave中,我们找了到数据,是从master同步过来的。实验完成!

主从实验是MongoDB最简单的部署实验了。

MongoDB 的详细介绍:请点这里
MongoDB 的下载地址:请点这里

相关阅读:

MongoDB备份与恢复

CentOS编译安装MongoDB

CentOS 编译安装 MongoDB与mongoDB的php扩展

CentOS 6 使用 yum 安装MongoDB及服务器端配置

Ubuntu 13.04下安装MongoDB2.4.3

如何在MongoDB中建立新数据库和集合

MongoDB入门必读(概念与实战并重)

《MongoDB 权威指南》(MongoDB: The Definitive Guide)英文文字版[PDF]

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn