Replica setAuthority authentication
A keyfile file is to be used for authentication of permissions between nodes.
Mkdir-p/mnt/mongodb/rs/config
Cd/mnt/mongodb/rs/config
OpenSSL rand-base64 741 > Mongodb-keyfile
chmod mongodb-keyfile
official online is a , must be changed to a, if not, will be at the start of the mongodb.log Write permission is too open cause of the start MongoDB failed! (Make sure you've installed OpenSSL here , and if it's not, Yum installs OpenSSL)
Copy the Mongodb-keyfile to each node corresponding to the directory, if before the start of MongoDB, with MONGO into the terminal, First look at that node is the primary node,rs.status (); go to the main node to execute:
Use admin # Select the data you want to certify
Db.adduser (' name ', ' Password ');
Of course, you can also have a self-built library for permission authentication
Use Test1
Db.adduser (' Test ', ' 123456 ');
prompt to add success, all stop, each node executes db.shutdownserver (); Then add the following two lines to the mongod.conf file:
Auth=true
Keyfile=/mnt/mongodb/rs/confile/mongodb-keyfile
All the last reboots!
Enter the main node terminal
Db.runcommand ({getlasterror:1, w:n});
if not n 2 N equals 2 n local.slaves
when specified "W" option, you can also use " Wtimeout " getlasterror can be copied to N ( The command is not timed out by default )
Blocking replication can cause write operations to become noticeably slower, especially if "W" 2 3
MongoDB REPL Set Permissions authentication configuration steps