installation :
1 Download Linux installation package 2 on the official website in Linux decompression 3 will unzip the directory MV to the specified installation directory
MV mongodb-linux-x86_64-rhel70-3.6. 5//usr/local/mongodb
4 CD to the bin directory, execute the following command to add the environment variable:
Export path= $PATH:/usr/local/mongodb/bin/
5 Creating a Database storage directory
mkdir -p/data/db
mongodb data is stored in the DB directory in the database directory, 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. in the following example we create the data directory under the root directory (/). Note:/data/db is the default startup database path for MongoDB (--dbpath). 6 Execute the./mongod file in the bin directory, the server that started MongoDB 7 execute MONGO file is the start client service two scripts were written, one is start_mongodb.sh; one is stop_mongodb.sh
Open mongod Server servicestart_mongodb.sh
/usr/local/mongodb/bin/mongod--logpath=/usr/local/mongodb/bin/log/mongodb_run.log--logappend--port=27017 --auth--fork--maxconns=20000
Start the Mongod service and set the log path, port, enable user authentication, fork is daemon, and maximum number of connections
Close Mongod Servicestop_mongodb.sh
PS -ef | grep awk ' {print $} ' Xargs Kill -9 {}
Create userMongoDB create users need to first use DB, the user's permissions for a certain db, even the superuser also need to specify, although it can operate all the db ...
1 > db.createUser({user:"username",pwd:"password",roles:[{role:"root",db:"admin"}]});
2 Successfully added user: {
3 "user" : "admin",
4 "roles" : [
5 {
6 "role" : "root",
7 "db" : "admin"
8 }
9 ]
10 }
The above is the creation User: username, password: password, the role is the role of the root, the specified db is the admin library. Other built-in roles:
Read: Allows the user to read the specified database
readWrite: allows the user to read and write the specified database
dbAdmin: allows users to perform management functions in the specified database, such as index creation, deletion, viewing statistics or accessing system.profile
userAdmin: allows users to write to the system.users collection, and can create, delete, and manage users in the specified database
clusterAdmin: Available only in the admin database, giving users administrative rights to all shard and replication set related functions.
readAnyDatabase: only available in the admin database, giving users read permissions to all databases
readWriteAnyDatabase: only available in the admin database, giving users read and write permissions to all databases
userAdminAnyDatabase: only available in the admin database, giving users userAdmin permissions for all databases
dbAdminAnyDatabase: Available only in the admin database, giving users dbAdmin permissions for all databases.
root: Available only in the admin database. Super account
You can turn on Auth authentication when you create a user and then start the Mongod service.
Login:
" username " " Password " " Admin "
Execute the Client Service command through the MONGO file, specifying that the validation database is admin, consistent with creating the user.
Install MongoDB, turn on MONGO service, create MongoDB user, login MongoDB