MongoDB in the case of authentication (AUTH), configure master/slave (master & Slave)

Source: Internet
Author: User
Tags chmod

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.