One, MongoDB installation
1. Download Mongodblinux version https://www.mongodb.com/download-center#community
2. Unzip
Tar xvf mongodb-linux-x86_64-2.0.7.tgz
Mkdir/usr/local/mongodb
MV mongodb-linux-x86_64-2.0.7/*/usr/local/mongodb
3. Create a database file directory
Mkdir-p/mongo/db
Create a MongoDB log file
Mkdir/var/log/mongodb
Touch/var/log/mongodb/mongodb.log
4. Create a soft connection to the MONGO command
The script file in the MONGO Bin directory can be used directly
Ln-s/usr/local/mongodb/bin/*/usr/sbin
5. Configure Startup Parameters
Mkdir/usr/local/mongodb/conf
Cd/usr/local/mongodb/conf
VI mongod.conf
port=27017 #端口号
Fork=true #以守护进程的方式运行, creating a server process
Logpath=/var/log/mongodb/mongodb.log #日志输出文件路径
Logappend=true #日志输出方式
dbpath=/mongo/db #数据库路径
maxconns=600 #数据库的最大连接数
Start: Mongod-f/usr/local/mongodb/conf/mongod.conf
6. Verification
Whether Port 27017 is open
Netstat-nultp
MONGO command into MONGO Shell
7, set the Master and slave:
Assume:
master:10.20.115.185
slave:10.20.115.44
A. Apply the above installation process to MongoDB two hosts, the configuration file changes slightly
On Mongodb-master, the configuration file is incremented
Master=true
oplogsize=2048 #类似于mysql的日志滚动, Unit m
B. On Mongodb-slave, the configuration file is incremented:
Slave=true
source=10.48.100.1:27017 #指定主mongodb Server
slavedelay=10 #延迟复制, unit of seconds
Autoresync=true #当发现从服务器的数据不是最新时, request synchronization of data to the primary server
Third, test master-Slave usability
Start the Mongodb:mongod-f/usr/local/mongodb/conf/mongod.conf on both hosts
1. Below we create the database in our Lord and insert the collection document to see if it is synchronized
On the primary server:
# MONGO
MongoDB Shell version:2.0.7
Connecting To:test
> Show DBS
Local4.201171875gb
> Use Xin
Switched to DB Xin
> Db.test.save ({title: "Just Test"})
> Db.test.find ()
{"_id": ObjectId ("502D3643C5664CA66103A7CF"), "title": "Just Test"}
> Show DBS
Local4.201171875gb
Xin0.203125gb
>
Note: Xin is the database name, test is the collection name, {title: "Just Test"} is a document
MongoDB using use to create a database of course, you can switch the database, and MySQL is a big difference.
2. Execute Rs.slaveok () on the slave node;
3. We enter the MongoDB shell from the server and confirm
# MONGO
MongoDB Shell version:2.0.7
Connecting To:test
> Show DBS
Local0.203125gb
Xin0.203125gb
>
> Use Xin
Switched to DB Xin
> Db.test.find ()
{"_id": ObjectId ("502D3643C5664CA66103A7CF"), "title": "Just Test"}
MongoDB installation and master-slave configuration