MongoDB a master a bundle with user-certified build

Source: Internet
Author: User
Tags auth install mongodb mkdir

Prepare two test servers.
Main 10.0.0.3
From 10.0.0.4

One, two servers install MongoDB database

First step: Create a good directory
Mkdir-p/data_master/tools/
cd/data_master/tools/

Step two: Download the installation package and unzip it
#下载
Curl-o https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
#解压
TAR-ZXVF mongodb-linux-x86_64-3.0.6.tgz

Step three: Copy the unpacking package to the specified directory
MV mongodb-linux-x86_64-3.0.6//usr/local/mongodb

Fourth step: Add environment variables and restart environment variables
echo "Export path=/usr/local/mongodb/bin: $PATH" >>/etc/profile
Source/etc/profile

Fifth step: Create a database directory
#MongoDB的数据存储在data目录的db目录下, but this directory is not created automatically during the installation process, so you need to create the data directory manually and create the DB directory in the data directory.
#以下实例中我们将data目录创建于根目录下 (/).
#注意:/data/db is the default startup database path for MongoDB (--dbpath).
Mkdir-p/data_master/db
Mkdir-p/data_master/mongdb/log
Mkdir-p/data_master/db_slave

Second, the main server to start MongoDB
Sixth step: Run MongoDB service on the command line
Cd/usr/local/mongodb/bin
./mongod-dbpath/data_master/db-master

Third, start MongoDB from the server
Sixth step: Run MongoDB service on the command line
Cd/usr/local/mongodb/bin
./mongod-dbpath/data_master/db_slave-slave-source 10.0.0.3:27017

Execute the Rs.slaveok () method on the error slave machine.

Rs.slaveok ()
Show DBS
Local 0.078GB
Test 0.078GB
Use test
Switched to DB test
Show collections
System.indexes
Users
Db.users.find ()
{"_id": ObjectId ("55763d98db85929bb8addedf"), "username": "LWB"}
{"_id": ObjectId ("55764a694b24187a7a3c6693"), "username": "MongoDB Master-sla

Iv. master-slave replication with account verification

OpenSSL rand-base64 741 >/root/mongo-keyfile
The main library generates this configuration file
Make the permissions smaller after the build is complete
SCP sent to Slave library
Privilege to 400 Best
(Late due to permissions issues may be error)

Then the user is provisioned with the Advanced Master Library and the MongoDB from the library without setting up user authentication.
Set the authenticated user and password

Use admin
Switched to DB admin
Db.createuser ({User: ' DbAdmin ', pwd: ' AQMKDUYBRAVFGJK ', roles:["root"});
Successfully added User: {"user": "DbAdmin", "Roles": ["Root"]}
Use JHPICDB
Switched to DB jhpicdb
Db.createuser ({User: ' jhpicdb ', pwd: ' AQMKDUYBRAVFGJK ', roles:[' ReadWrite ']});
Successfully added User: {"user": "admin", "Roles": ["ReadWrite"]}

Then download the command line login to verify the user
[Email protected] log]# MONGO
MongoDB Shell version:3.0.6
Connecting To:test

Use admin
Switched to DB admin
Db.auth ("DbAdmin", "AQMKDUYBRAVFGJK");
1
Show DBS
Admin 0.078GB
JHPICDB 49.930GB
Local 0.078GB

Note that the operation of the two libraries should be consistent.

Configuration files above the main library
[Email protected] backup]# cd/usr/local/mongodb/bin/
[email protected] bin]# cat mongodb.conf

Idae-mongodb Config start-20180203

master = On

Setting the data file's storage directory

DBPath =/data_master/db

Set the directory where the log files are stored and their log file names

LogPath =/data_master/mongdb/log/mongo.log

Set the port number (the default port number is 27017)

Port = 27017

Set to run as Daemon, which runs in the background

Fork = True

Nohttpinterface = True

Nohttpinterface = True
#打开认证
Auth = On
#主库
#master = On
#密钥
KeyFile =/root/mongo-keyfile

From the configuration file above the library
[Email protected] ~]# cd/usr/local/mongodb/bin/
[email protected] bin]# cat mongodb.conf

Idae-mongodb config start-20180203 settings data file storage directory

DBPath =/data_master/db_slave

Set the directory where the log files are stored and their log file names

LogPath =/data_master/mongdb/log/mongo.log

Set the port number (the default port number is 27017)

Port = 27017
#从库
Slave = On
Source = 10.0.0.3:27017

Set to run as Daemon, which runs in the background

Fork = True

Nohttpinterface = True

Nohttpinterface = True
#打开认证
Auth = On
#密钥
KeyFile =/root/mongo-keyfile
#repair = On

MongoDB a master a bundle with user-certified build

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.