---------------------------------Mongo Single-----------------------------------------------------------
Mongo Installation:
1. cd/usr/local/webserver/&& tar zxpf mongodb-linux-x86_64-2.0.6.tgz && mv mongodb-linux-x86_64-2.0.6 Mongodb
2. Write the configuration file as follows (single MONGO configuration)
Vim/usr/local/webserver/mongodb/conf/mongodb.conf_back
DBPATH=/DATA/DB Data Storage Path
Logpath=/mongodb_data1log/mongodb_data1.log Log Path
Fork=true Background Boot
port=27019 Boot Port
Logappend=true does not overwrite log files
3. Start
/usr/local/webserver/mongodb/bin/mongod-f/usr/local/webserver/mongodb/conf/mongodb.conf
4. Enter the database:
/usr/local/webserver/mongodb/bin/mongo 192.168.4.188:27017
---------------------------------Mongo Cluster-----------------------------------------------------------
MONGO cluster:
1. Master-slave mode (master/slave), two-node, once the master hangs, the data will not be written
2. Replica set mode (replica set), at least three nodes, one master, one auxiliary, one control
The following is a replica set configuration
1.192.168.4.188 (Master)
Mkdir-p/mongodb/data/master && mkdir-p/mongodb/log/
192.168.4.31 (slaver)
Mkdir-p/mongodb/data/slaver && mkdir-p/mongodb/log/
192.168.4.32 (Arbiter)
Mkdir-p/mongodb/data/arbiter && mkdir-p/mongodb/log/
2. Write the configuration file separately as follows:
#master. conf
Dbpath=/mongodb/data/master
Logpath=/mongodb/log/master.log
Pidfilepath=/mongodb/master.pid
Directoryperdb=true
Logappend=true
Replset=testrs
bind_ip=10.10.148.130
port=27017
oplogsize=10000
Fork=true
Noprealloc=true
#slaver. conf
Dbpath=/mongodb/data/slaver
Logpath=/mongodb/log/slaver.log
Pidfilepath=/mongodb/slaver.pid
Directoryperdb=true
Logappend=true
Replset=testrs
bind_ip=10.10.148.131
port=27017
oplogsize=10000
Fork=true
Noprealloc=true
#arbiter. conf
Dbpath=/mongodb/data/arbiter
Logpath=/mongodb/log/arbiter.log
Pidfilepath=/mongodb/arbiter.pid
Directoryperdb=true
Logappend=true
Replset=testrs
bind_ip=10.10.148.132
port=27017
oplogsize=10000
Fork=true
Noprealloc=true
Parameter explanation:
DBPath: Data Storage Directory
LogPath: Log Storage path
Pidfilepath: Process files, easy to stop MongoDB
Directoryperdb: Set up a folder for each database according to the database name
Logappend: Logging in Append mode
Replset:replica Set's name
IP address that is bound by Bind_ip:mongodb
The port number used by the PORT:MONGODB process, which defaults to 27017
Oplogsize:mongodb the maximum size of the operation log file. MB, default to 5% of the hard disk's remaining space
Fork: Run the process in the next stage mode
Noprealloc: No pre-allocated storage
3. Start separately:
/usr/local/webserver/mongodb/bin/mongod-f/usr/local/webserver/mongodb/conf/master.conf
/usr/local/webserver/mongodb/bin/mongod-f/usr/local/webserver/mongodb/conf/slaver.conf
/usr/local/webserver/mongodb/bin/mongod-f/usr/local/webserver/mongodb/conf/arbiter.conf
4. Connecting the main library 192.168.4.188
1./usr/local/webserver/mongodb/bin/mongo 192.168.4.188:27017
2. Use admin
3. cfg={_id: "Testrs", members:[{_id:0,host: ' 192.168.4.188:27017 ', priority:2}, {_id:1,host: ' 192.168.4.31:27017 ', Priority:1},{_id:2,host: ' 192.168.4.32 ', Arbiteronly:true}]};
4. Rs.initiate (CFG) initialization settings
5. Rs.status () detects if the configuration is in effect
Note: CFG can be arbitrary name, of course, it is best not to be mongodb keyword, conf,config can. The outermost _id represents the name of the replica set, and the members contain the address and priority of all nodes. The highest priority becomes the master node, the 10.10.148.130:27017 here. It is particularly important to note that there is a special configuration--arbiteronly:true for the quorum node. This must not be less, or the main standby mode will not be effective.
The configuration of the effective time according to the different machine configuration will be long and short, the configuration is good, basically in more than 10 seconds can be effective, and some configuration takes two minutes. If it takes effect, the Execute rs.status () command will see the following information
Primary> Rs.status ()
{
"Set": "Testrs",
"Date": Isodate ("2015-08-17t15:56:09z"),
"MyState": 1,
"Syncingto": "192.168.4.31:27017",
"Members": [
{
"_id": 0,
"Name": "192.168.4.188:27017",
"Health": 1,
"State": 1,
"Statestr": "PRIMARY",
"Optime": {
"T": 1439825218000,
"I": 1
},
"Optimedate": Isodate ("2015-08-17t15:26:58z"),
"Self": true
},
{
"_id": 2,
"Name": "192.168.4.32:27017",
"Health": 1,
"State": 7,
"Statestr": "Arbiter",
"Uptime": 2007,
"Optime": {
"T": 0,
"I": 0
},
"Optimedate": Isodate ("1970-01-01t00:00:00z"),
"Lastheartbeat": Isodate ("2015-08-17t15:56:09z"),
"Pingms": 0
},
{
"_id": 3,
"Name": "192.168.4.31:27017",
"Health": 1,
"State": 2,
"Statestr": "Secondary",
"Uptime": 1459,
"Optime": {
"T": 1439825218000,
"I": 1
},
"Optimedate": Isodate ("2015-08-17t15:26:58z"),
"Lastheartbeat": Isodate ("2015-08-17t15:56:08z"),
"Pingms": 0
}
],
"OK": 1
5. Test:
Master: Db.t.insert ({uid:12345})
Db.t.find ()
{"_id": ObjectId ("55d1f1e3abe1ab56e12281a5"), "UID": 12345}
Auxiliary: Db.t.find ()
{"_id": ObjectId ("55d1f1e3abe1ab56e12281a5"), "UID": 12345}
Data synchronization is successful
Node Removal:
Execute on Main Library: Rs.remove ("192.168.4.31:27017") where "192.168.4.188:27017" is the "name" of the node queried in Rs.status (): "192.168.4.188:27017" ,
Node Additions:
1. Execute on Main Library: primary> rs.add ("192.168.4.31:27017")
{"OK": 1}
2. The MONGO database needs to be restarted, otherwise the status error is as follows:
[Email protected] bin]#/mongo 192.168.4.31:27017
MongoDB Shell version:2.0.6
Connecting To:192.168.4.31:27017/test
Fatal> FATAL Deadly different points
The correct status is as follows:
[Email protected] bin]#/mongo 192.168.4.31:27017
MongoDB Shell version:2.0.6
Connecting To:192.168.4.31:27017/test
Secondary> different points
Common commands for MONGO
The DB display is currently the database
Rs.status () Viewing node information
Show DBS; View Database
Show Collections view the table under the current database, and the index
Use test to enter test library
Db.stats () View the status of the database
Db.help () View DB command Help
Reference URL:
http://blog.csdn.net/luonanqin/article/details/8497860
Http://developer.51cto.com/art/201403/434054_all.htm
http://snowolf.iteye.com/blog/1974747
Linux MONGO build + cluster