First, CentOS installation MongoDB
Opt directory, download MongoDB, unzip
#wget HTTPS://FASTDL.MONGODB.ORG/LINUX/MONGODB-LINUX-X86_64-3.0.6.TG
#tar-ZXVF mongodb-linux-x86_64-3.0.6.gz
Renaming mongodb-linux-x86_64-3.0.6 to MongoDB
#mv mongodb-linux-x86_64-3.0.6.gz MongoDB
Go to MongoDB New database folder, log folder, and Configuration folder
#cd mongodb#mkdir db#mkdir Log#mkdir conf
Under the MongoDB Directory command start:
Bin/mongod --dbpath db--port 27000--logpath Log/mongod.log--fork True
(Personal habits Write these parameters to the configuration file) go to the Configuration folder, create a new profile mongod.conf, edit the content
Port = 27000 #数据库端口dbpath = db #数据库路径logpath = Log/mongod.log #日志输入fork = True #linux后台进程
New startup file startmongod.sh in MongoDB directory, writing content
Bin/mongod-f conf/mongod.conf
The MongoDB basic directory structure after configuration:
Start SH startmongod.sh
Second, MongoDB master-slave replication
Test environment: 192.168.199.199 master, 192.168.199.200 from, 192.168.199.201 from
In the installation configuration mongodb,mongod.conf the boot configuration contents are as follows
199
Port = 27000 #数据库端口dbpath = db #数据库路径logpath = Log/mongod.log #日志输入fork = True #linux后台进程master = #主数据库
200
Port = 27000 #数据库端口dbpath = db #数据库路径logpath = Log/mongod.log #日志输入fork = True #linux后台进程slave = #从数据库标识source = 192.168.1 99.199:27,000
201
Port = 27000 #数据库端口dbpath = db #数据库路径logpath = Log/mongod.log #日志输入fork = True #linux后台进程slave = #从数据库标识source = 192.168.1 99.199:27,000
! (Three machine firewalls must open 27000 ports: iptables-i input-p TCP--dport 27000-j ACCEPT)
199 Main Library startup and log information
200 Startup and log information
199 Inserting data
200 Test Query synchronization data
201 The main library was not synchronized before, and now 201 synchronizes data as a new server database 199 Master Library
201 Log Display Synchronization
199 Main Library synchronization log information
Read and Write permissions are not opened from the database at this time
Which is the realization of read and write separation
MongoDB installation and master-slave replication