Master configuration
This machine: 192.168.100.23:27017
/etc/mongodb/mongo.conf
Port = 27017
DBPath =/data/mongodb_t
LogPath =/var/log/mongodb_t.log
Logappend = True
Journal = True
Fork = True
1. The above configuration single-machine open MONGO, the admin database to set
According to the data, must establish the global user root, the personal feeling is the Super administrator, must establish the REPL user to the local database.
Mongo–port 27017
> use admin> db.createuser ({User: "root", pwd: "123456", roles:[{role: "Root",  DB: "Admin"}]}) > db.createuser ({User: "Repl", pwd: "123456", roles:[{role: "Dbowner",  DB: "Local"}]}) > show users{ "_id" : "Admin.root", "User" : "root", "db" : "admin", "Roles" : [ { "Role" : "root", "DB" : "admin"         } ]}{ "_id" : "Admin.repl", " User " : " repl ", " db " : " admin ", " Roles " : [ { "Role"  : "Dbowner", "db" : " Local " } ]}> exit12345678910111213141516171819202122232425262728
2. Modify the configuration file
Add the following three items:
Port = 27017
DBPath =/data/mongodb_t
LogPath =/var/log/mongodb_t.log
Keyfile=/srv/mongodb/keyfile
Logappend = True
Journal = True
Fork = True
Keyfile=/srv/mongodb/keyfile #添加keyfile
Auth = True #打开认证
Master = True #打开主库配置
3. Add KeyFile
The main purpose is to verify between master and slave
cd/srv/mongodb/
OpenSSL rand-base64 741 >>keyfile
chmod keyfile
4. Restart the database Salve configuration
Native: No longer on the same device as the main library, the same LAN
/etc/mongodb/mongo.conf
Port = 27017
DBPath =/data/mongodb_t
LogPath =/logs/mongo/mongodb_t.log
Logappend = True
Journal = True
Fork = True
1. First step with Master 2. Modifying a configuration file
Port = 27017
DBPath =/data/mongodb_t
LogPath =/logs/mongo/mongodb_t.log
Logappend = True
Journal = True
Fork = True
Auth = True
Slave = True
Keyfile=/srv/mongodb/keyfile
Source = 192.168.100.23:27017
3. Add KeyFile
cd/srv/mongodb/
Copy the KeyFile from the main library device to this directory
chmod keyfile
4. Restart the database
After rebooting, log in to the database and you will be able to see the synchronization with the main library.
If the shell is logged in, you need
Rs.slaveok ()
MongoDB in the case of authentication (AUTH), configure master/slave (master & Slave)