The blog.chinaunix.netuid-24086995-id-1754660.html uses two different ports on the same machine to start mongodb and create two new directories under the database directory [root @ localhost ~] # Mkdirdatadbmaster [root @ localhost ~] # Mkdirdatadbslave master: only required
The http://blog.chinaunix.net/uid-24086995-id-1754660.html uses two different ports on the same machine to start mongodb and create two new directories under the database directory [root @ localhost ~ ] # Mkdir/data/db/master [root @ localhost ~ ] # Mkdir/data/db/slave master: only required
Http://blog.chinaunix.net/uid-24086995-id-1754660.html
Start mongodb with two different ports on the same machine
Create two new directories under the database directory
- [Root @ localhost ~] # Mkdir/data/db/master
[Root @ localhost ~] # Mkdir/data/db/slave
Master: only the -- master parameter needs to be included, indicating that this is a master, which is quite convenient.
- [Root @ localhost ~] #/Usr/local/bin/mongod -- master-dbpath =/data/db/master-port = 11536 &
- [1] 10939
- [Root @ localhost ~] # Mon Jul 25 20:21:59 [initandlisten] MongoDB starting: pid = 10939 port = 11536 dbpath =/data/db/master = 1 32-bit
From: Take the -- slave parameter to specify the slave, specify the -- source, Master Address and port, it is much more convenient than MYSQL.
- [Root @ localhost bin] #/usr/local/bin/mongod-port 11537 -- slave-dbpath =/data/db/slave -- source 127.0.0.1: 11536
- Mon Jul 25 20:25:52 [initandlisten] MongoDB starting: pid = 11158 port = 11537 dbpath =/data/db/slave = 1 32-bit
Open a new terminal, log on to 11536 (master), and write a record
- [Root @ localhost ~] #/Usr/local/bin/mongo -- port = 11536
- MongoDB shell version: 1.8.2
- Connecting to: 127.0.0.1: 11536/test
- > Use brucezuo
- Switched to db brucezuo
- > Db. createCollection ("table1 ")
- {"OK": 1}
- > Db. table1.insert ({id: 1, name: "zxy", age: 29 })
- >
Open a new terminal and log on to 11537 (slave) to check whether the data is consistent.
- [Root @ localhost ~] #/Usr/local/bin/mongo -- port = 11537
- MongoDB shell version: 1.8.2
- Connecting to: 127.0.0.1: 11537/test
- > Show dbs
- Admin (empty)
- Brucezuo 0.0625 GB
- Local 0.0625 GB
- > Use brucezuo
- Switched to db brucezuo
- > Db. table1.find ()
- {"_ Id": ObjectId ("4e2e348ed502dbae1aee469e"), "id": 1, "name": "zxy", "age": 29}
- >
The data on both ends is completely consistent.
From the test above, mongodb has much easier configuration for master-slave replication than MYSQL.