Build MongoDB replica set under Linux
1. Build three MongoDB servers
Cd/usr/local
mkdir MongoDB
TAR-ZXVF mongodb-linux-x86_64-2.6.7.tgz
CD MONGODB-LINUX-X86_64-2.6.7MV */usr/local/mongodb
Cd/usr/local/mongodbmkdir Datatouch Logs
CD Bin./mongod-dbpath=/usr/local/mongodb/data-logpath=/usr/local/mongodb/logs booting and testing
2. Setting up the boot configuration file
cd/usr/local/mongodb/
Mkdir-p mongodb_data/mongodb_db
mkdir Mongodb_data/mongodb_logs
Vi/etc/mongodb.conf
Fork = True
Quiet = True
BIND_IP = 192.168.30.112
Port = 27017
DBPath =/usr/local/mongodb/mongodb_data/mongodb_db
LogPath =/usr/local/mongodb/mongodb_data/mongodb_logs/server1.log
Logappend = True
Journal = True
Rest = True
Replset = Test
Above 3 servers, the same installation steps
3. Start MongoDB
Cd/usr/local/mongodb/bin
./mongod-f/etc/mongodb.conf
We connect to one of the nodes and initialize with the Replsetinitiate command. This command requires a configuration object that specifies the name of each member set
./mongo 192.168.30.112: 3306/admin
Use admin
Rs.initiate ()
Confirm Settings
Rs.conf ()
添加第一个从库rs0:PRIMARY> rs.add(
‘IP:27017‘
)
添加第二个从库
以通过priority来调整主库,选举的时候,priority大的优先被选举为主库
rs.add({host:
"IP:27017"
, priority: 5})
确认设定
rs0:PRIMARY> rs.conf()
查看状态rs0:SECONDARY> rs.status()
Remove from library
First close the MongoDB from the library, and then remove the library from the main library
rs0:PRIMARY> rs.remove(
‘IP:27017‘
)
Build MongoDB replica set under Linux