Next blog post:
Http://www.cnblogs.com/xiaoit/p/4479066.html
1: First create 3 virtual machines as configuration environment
ip1:192.168.91.128
ip2:192.168.91.129
ip3:192.168.91.130
2: Download MongoDB 2.6 version
Https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.6.9.zip
3: Unzip
TAR-ZXVF Mongodb-linux-x86_64-2.6.9.zip
MV mongodb-linux-x86_64-2.6.9 MongoDB
4: Create data directory and log directory and conf configuration file in MongoDB directory
Both data and log directories are guaranteed to have read and write access
Configure on 3 servers as above
5: Edit config file vi mongo.conf
On the ip1:192.168.91.128.
Add logappend=true# to the =/root/software/mongodb/log/mongod# Data Catalog dbpath=/root/software/mongodb/data# log in Append mode #日志目录logpath Turn on background process run fork = true# Port = 27017# Replica set name replset=gechongrepl/192.168.91.129:27017
On the ip2:192.168.91.129:
Add logappend=true# to the =/root/software/mongodb/log/mongod# Data Catalog dbpath=/root/software/mongodb/data# log in Append mode #日志目录logpath Turn on background process run fork = true# Port = 27017# Replica set name #192.168.91.128#replset=gechongrepl/192.168.91.129:27017replset= gechongrepl/192.168.91.128:27017
On the ip3:192.168.91.130.
Add logappend=true# to the =/root/software/mongodb/log/mongod# Data Catalog dbpath=/root/software/mongodb/data# log in Append mode #日志目录logpath Turn on background process run fork = true# Port = 27017# Replica set name #192.168.91.128#replset=gechongrepl/192.168.91.129:27017#192.168.91.129# replset=gechongrepl/192.168.91.128:27017replset=gechongrepl/192.168.91.129:27017, 192.168.91.128:27017
6: Start Mongod separately with the configuration file as above
Start Mongod on the ip1:192.168.91.128
> config_repl={_id: ' gechongrepl ', members:[... {_id:0,host: ' 192.168.91.128:27017 ', priority:10},... {_id:1,host: ' 192.168.91.129:27017 ', priority:9},... {_id:2,host: ' 192.168.91.130:27017 ', Priority:9}]} {"_id": "Gechongrepl", "members": [{"_id": 0, "host": "192.168.91.128:27017", "Priority": 10},{"_id": 1, "host": "192.1 68.91.129:27017 "," Priority ": 9},{" _id ": 2," host ":" 192.168.91.130:27017 "," Priority ": 9}]}
> rs.initiate (CONFIG_REPL); {' Startupstatus ': 4, ' info ': ' gechongrepl/192.168.91.129:27017 ', ' OK ': 0, ' errmsg ': ' All ' and seeds must be reacha ble to initiate set "}
An error has been made. Try on IP1: Telnet 192.168.91.130 27017 is not found. Turn off the iptables of these servers to perform the above command again.
> rs.initiate (CONFIG_REPL); {"Info": "Config now saved locally. Should come online in about a minute. "," OK ": 1}
At this point, initialization is OK. All of the above 3 machines can be initialized at any one stage.
7: Verify the configured replica set.
> Rs.status () {"Set": "Gechongrepl", "date": Isodate ("2015-05-05t05:54:20z"), "MyState": 1, "members": [{"_id": 0, "NA Me ":" 192.168.91.128:27017 "," Health ": 1," state ": 1," Statestr ":" PRIMARY "," Uptime ": 1936," Optime ": Timestamp (14308038 1), "Optimedate": Isodate ("2015-05-05t05:30:01z"), "Electiontime": Timestamp (1430803801, 2), "Electiondate": Isodate ("2015-05-05t05:30:01z"), "Self": true},{"_id": 1, "name": "192.168.91.129:27017", "Health": 1, "state": 2, " Statestr ":" Secondary "," uptime ": 1459," Optime ": Timestamp (1430803801, 1)," Optimedate ": Isodate (" 2015-05-05t05 : 30:01z ")," Lastheartbeat ": Isodate (" 2015-05-05t05:54:19z ")," Lastheartbeatrecv ": Isodate (" 2015-05-05t05:54:19z "), "Pingms": 1, "syncingto": "192.168.91.128:27017"},{"_id": 2, "name": "192.168.91.130:27017", "Health": 1, "state": 2, "St Atestr ":" Secondary "," uptime ": 1459," Optime ": Timestamp (1430803801, 1)," Optimedate ": Isodate (" 2015-05-05t05:30:01z " ), "Lastheartbeat": Isodate ("2015-05-05t05:54:19z"), "LastheaRtbeatrecv ": Isodate (" 2015-05-05t05:54:20z ")," Pingms ": 1," syncingto ":" 192.168.91.128:27017 "}]," OK ": 1}
Configuration is OK.
MongoDB Replica Set Configuration series two: Configure MongoDB replica set