Installation
First, the TAR package to install
1. Baidu Network disk http://pan.baidu.com/s/1FOH2m
2.https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz
Second, the Yum source for installation
Configure the Package management system (yum). Change
Create a /etc/yum.repos.d/mongodb-org-3.0.repo file so you can install MongoDB directly with Yum.
Change to version 3.0: MongoDB Linux Packages for 3.0 is in a new repository.
Recent stable version of MongoDB
Use the following repo file
[Mongodb-org-3.0]name=mongodb repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0 /x86_64/gpgcheck=0enabled=1
Install the latest stable version of MongoDB to install the latest stable version of MongoDB, issue the following command:
sudo yum install-y mongodb-org
To install a specific (special) release of MongoDB, specify each component package individually and append the version number to The package name, as in the following example:
sudo yum install-y mongodb-org-3.0.6 mongodb-org-server-3.0.6 mongodb-org-shell-3.0.6 mongodb-org-mongos-3.0.6 mongodb-org-tools-3.0.6
To install the latest MongoDB version.
Configuration
Ii. configuration of the TAR package during installation
1.
Mkdir-p/MongoDB/export/mongodb
CP mongodb-linux-x86_64-3.0.6.tgz /mongodb/export/mongodb
Tar zxvf mongodb-linux-x86_64-3.0.6.tgz
Vim/etc/profile (configuring MONGODB environment variables)
Export path=/mongodb/export/mongodb/mongodb-linux-x86_64-3.0.6/bin: $PATH
CD /mongodb/export/mongodb
mkdir conf
mkdir Log
mkdir keyfile
mkdir data
Vim conf/master.conf
#dbpath =/mnt/export/mongodb/data/master01
#logpath =/mnt/export/mongodb/log/master01.log
#logappend =true
#replSet =mas
#port =10001
#fork =true
#journal =true
#auth =true
#keyFile =/mnt/export/mongodb/keyfile/keyfile01
Storage
DbPath:/mongodb/export/mongodb/data/master
Directoryperdb:true
Engine:wiredtiger
Journal
Enabled:true
Systemlog:
Path:/mongodb/export/mongodb/log/master.log
Logappend:true
Logrotate:rename
Destination:file
Replication
#oplogSizeMB: <int>
Replsetname:mongodb
Processmanagement:
Fork:true
Net
#bindIp: 127.0.0.1
port:27017
#security:
# keyfile:/mongodb/export/mongodb/keyfile/keyfile00
# authorization:enabled
# Vim Conf/slave.conf
#dbpath =/mnt/export/mongodb/data/master01
#logpath =/mnt/export/mongodb/log/master01.log
#logappend =true
#replSet =mas
#port =10001
#fork =true
#journal =true
#auth =true
#keyFile =/mnt/export/mongodb/keyfile/keyfile01
Storage
DbPath:/mongodb/export/mongodb/data/slave
Directoryperdb:true
Engine:wiredtiger
Journal
Enabled:true
Systemlog:
Path:/mongodb/export/mongodb/log/slave.log
Logappend:true
Logrotate:rename
Destination:file
Replication
#oplogSizeMB: <int>
Replsetname:mongodb
Processmanagement:
Fork:true
Net
#bindIp: 127.0.0.1
port:27018
#security:
# keyfile:/mongodb/export/mongodb/keyfile/keyfile00
# authorization:enabled
This time without adding arbiter, no quorum set
Start MongoDB, but be aware that you need to create a database folder in /mongodb/export/mongodb/data master slave
Otherwise MongoDB may not start normally
Start command
Cd/mongodb/export/mongodb/mongodb-linux-x86_64-3.0.6/bin
./mongod-f/mongodb/export/mongodb/conf/master.conf
./mongod-f/mongodb/export/mongodb/conf/slave.conf
(This boot does not turn on validation if you want to turn on authentication)
Start MONGO
./mongo--port 27017
>use Admin
>cfg1={_id: "MongoDB", members:[{_id:0,host: ' 192.168.1.87:27017 ', priority:2}, {_id:1,host: ' 192.168.1.87:27018 ', priority:1}]};
{
"_id": "MongoDB",
"Members": [
{
"_id": 0,
"Host": "192.168.1.87:27017",
"Priority": 2
},
{
"_id": 1,
"Host": "192.168.1.87:27018",
"Priority": 1
}
]
}
> rs.initiate (CFG1)
{"OK": 1}
Mongodb:other> rs.status ()
{
"Set": "MongoDB",
"Date": Isodate ("2015-09-27t00:36:13.929z"),
"MyState": 1,
"Members": [
{
"_id": 0,
"Name": "192.168.1.87:27017",
"Health": 1,
"State": 1,
"Statestr": "PRIMARY",
"Uptime": 1031,
"Optime": Timestamp (1443314165, 1),
"Optimedate": Isodate ("2015-09-27t00:36:05z"),
"Electiontime": Timestamp (1443314169, 1),
"Electiondate": Isodate ("2015-09-27t00:36:09z"),
"ConfigVersion": 1,
"Self": true
},
{
"_id": 1,
"Name": "192.168.1.87:27018",
"Health": 1,
"State": 2,
"Statestr": "Secondary",
"Uptime": 8,
"Optime": Timestamp (1443314165, 1),
"Optimedate": Isodate ("2015-09-27t00:36:05z"),
"Lastheartbeat": Isodate ("2015-09-27t00:36:13.634z"),
"Lastheartbeatrecv": Isodate ("2015-09-27t00:36:13.725z"),
"Pingms": 0,
"Syncingto": "192.168.1.87:27017",
"ConfigVersion": 1
}
],
"OK": 1
Add MongoDB's Super User name password
mongodb:primary> Use admin
Switched to DB admin
Mongodb:primary> db.adduser (' root ', ' 123456 '); (Wrong way)
V3 version MongoDB no longer uses adduser, but uses the Db.createuser
2015-09-27t09:10:34.491+0800 E QUERY typeerror:property ' addUser ' of object admin is not a function
at (Shell): 1:4
mongodb:primary> Use admin
Switched to DB admin
Mongodb:primary> Db.createuser (
... {
... User: "Admin",
... pwd: "admin",
... roles: [{role: ' Useradminanydatabase ', db: ' admin '}]
... }
... )
Successfully added User: {
"User": "admin",
"Roles": [
{
"Role": "Useradminanydatabase",
"DB": "admin"
}
]
}
Add authentication, restart MongoDB and sign in
Close the MongoDB database
Enter the master of MongoDB
./mongo--port 27017
>use Admin
>db.shutdownserver ()
Enter the slave of MongoDB
./mongo--port 27017
>use Admin
>db.shutdownserver ()
Master-slave Safety
This master-slave security in the MongoDB official website said very clearly. cannot be verified with normal Mongod permissions. In addition to the need to join-auth also need to add-keyfile validation.
First, we generate our keyfile, according to the official website to provide the instructions, this keyfile can be arbitrary content, as long as all the machines in the cluster have the same files. In the Linux environment, we
OpenSSL rand-base64 741 >/mongodb/export/mongodb/keyfile/keyfile00
This command is to generate our keyfile. After the build, you can specify it when you start Mongod.
The configured file is
Storage
DbPath:/mongodb/export/mongodb/data/master
Directoryperdb:true
Engine:wiredtiger
Journal
Enabled:true
Systemlog:
Path:/mongodb/export/mongodb/log/master.log
Logappend:true
Logrotate:rename
Destination:file
Replication
#oplogSizeMB: <int>
Replsetname:mongodb
Processmanagement:
Fork:true
Net
#bindIp: 127.0.0.1
port:27017
Security
KeyFile:/mongodb/export/mongodb/keyfile/keyfile00
Authorization:enabled
Add post-Certification test results
[[email protected]bin]#./mongo--port 27017
MongoDB Shell version:3.0.6
Connecting To:127.0.0.1:27017/test
mongodb:primary>Show DBS
2015-10-08t19:37:29.881+0800 E QUERY error:listdatabases failed:{
"OK": 0,
"errmsg": "Not authorized in Admin to execute command {listdatabases:1.0}",
"Code":
}
At Error (<anonymous>)
At Mongo.getdbs (src/mongo/shell/mongo.js:47:15)
At shellhelper.show (src/mongo/shell/utils.js:630:33)
At Shellhelper (src/mongo/shell/utils.js:524:36)
At (SHELLHELP2): 1:1 at src/mongo/shell/mongo.js:47
mongodb:primary>Use admin
switched to DB admin
mongodb:primary>Db.auth ("admin", "admin")
1
mongodb:primary> Show DBS
Admin 0.000GB
Local 0.000GB
MongoDB installation and user name password management