Part I: MongoDB memo

Source: Internet
Author: User
Tags auth dba mongodb unix domain socket

I. A brief introduction of NoSQL

The full name of NoSQL is not-only Sql, a concept that has been raised early in the morning, compared to fire in the 09. NoSQL refers to a non-relational database, and we often use relational databases. Like our usual mysql,sqlserver,oracle, these databases are typically used to store important information, and there's no problem with normal business. However, with the rapid development of the Internet, the traditional relational database in dealing with ultra-large-scale, ultra-large traffic and high concurrency when the time is inadequate. And just at this time, NoSQL gets to tell the development.

Ii. MongoDB Memorandum

1, first say oneself in the use MongoDB process step over the pit, installation of time is very simple, decompression installation completed. I installed the version is v3.6.5, the use is also very simple

-dbpath/data/db--config/etc/mongod.conf

2, after starting to use MONGO into the shell interface, you can operate the database, the following list some I also remember the instructions, do not know the command area Runoob to check

<db_name> View Collection (table): Show Collections View a content: Db.school.findOne ()

3, the above mentioned the use of authentication mode to start MongoDB, then the premise of certification is of course need to have a user name and password, the following record how to increase the authentication user.

>Use adminswitched to DB admin>Db.createuser (... {... User:"DBA",... pwd:"DBA",... roles: [{role:"Useradminanydatabase"Db:"Admin" } ]...   } ... ) Successfully added User: {"User":"DBA",    "Roles" : [        {            "role":"Useradminanydatabase",            "DB":"Admin"        }    ]}
    • User: Username
    • PWD: Password
    • DB: Database name
    • Roles: Specifies the role of the user, an empty array can be used to set the null role for the new user; In the Roles field, you can specify built-in roles and user-defined roles.

Roles in role can be selected:

built-in Roles (built-in role):1. Database user role: Read, readWrite;2. Database management roles: DbAdmin, Dbowner, useradmin;3. Cluster Management roles: Clusteradmin, Clustermanager, Clustermonitor, Hostmanager;4Backup Recovery role: backups, restore;5. All database roles: Readanydatabase, Readwriteanydatabase, Useradminanydatabase, Dbadminanydatabase6. Super User role: Root//There are also several roles that indirectly or directly provide access to the system's Superuser (Dbowner, Useradmin, useradminanydatabase)7. Internal role: __system specific role: read: Allows the user to read the specified database ReadWrite: Allows the user to read and write to the specified database dbadmin: Allows the user to execute administrative functions in the specified database, such as index creation, deletion, View statistics or Access System.profileuseradmin: Allows the user to write to the System.users collection and can create, delete, and manage user clusteradmin in the specified database: Only available in the admin database. Gives the user administrative privileges on all shards and replica set related functions. Readanydatabase: Only available in the Admin database, giving the user read access to all databases Readwriteanydatabase: Only available in the admin database, Give users read and write access to all databases Useradminanydatabase: Available only in the admin database, giving the user useradmin permissions to all databases Dbadminanydatabase: Only available in the admin database, Gives the user dbadmin permissions for all databases. Root: Available only in the admin database. Super account, Super privilege
turn on user rights

Create a new mongodb.conf file and add "Auth=true"

Start the MongoDB service from the configuration file

./bin/mongod-f mongodb.conf

User authentication

[Email protected] mongodb3.2.10]$. /bin/3.6.1connecting to:test> Use adminswitched to db Caideyang> Db.auth (' admin ',' admin')1>

mongodb.conf configuration file

#数据库数据存放目录dbpath=/Usr/Local/mongodb304/data# Database Log storage directory LogPath=/Usr/Local/mongodb304/Logs/Mongodb.log#以追加的方式记录日志logappend=true#端口号 defaults to 27017port=27017#以后台方式运行进程fork=true#开启用户认证auth=true#关闭http接口, the HTTP port access Nohttpinterface is turned off by default=true#mongodb所绑定的ip地址bind_ip= 127.0.0.1,192.168.1.140#启用日志文件, journal is enabled by default=true#这个选项可以过滤掉一些无用的日志信息, if you need to debug use set to Falsequiet=true

Other configuration parameter Meanings

--quiet # Quiet output--Port ARG # Specifies the service port number, default port 27017--BIND_IP ARG # Binds the service IP, if bound 127.0.0.1, you can only have native access and do not specify the default local all IP--LogPath arg # Specifies the MongoDB log file, note that the specified file is not a directory--Logappend # Write a log using an Append method--Pidfilepath Arg # The full path of the PID file, if not set, there are no PID files--keyfile Arg # The full path of the private key of the cluster, valid only for the replica Set schema--unixsocketprefix arg # UNIX domain socket Alternative directory, (default =/TMP)--Fork # Run MongoDB as a daemon, creating a server process--Auth # Enable validation--CPU # Periodically shows CPU utilization and iowait--DBPath ARG # Specifies the database path--diaglog arg # diaglog option 0=off 1=w 2=r 3=both 7=w+some reads--DIRECTORYPERDB # Set each database to be saved in a separate directory--Journal # Enable logging option, MONGODB data operations will be written to the files in the Journal folder--journaloptions arg # Enable log diagnostics option--IPv6 # enable IPV6 option--Jsonp # allows JSONP form to be accessed via HTTP (with security implications)--Maxconns arg # maximum simultaneous connections default of--Noauth # Do not enable validation--nohttpinterface # Turn off HTTP interface, turn off 27018 port access by default--Noprealloc # Disabling data file pre-allocation (often impacting performance)--noscripting # Disabling the scripting engine--Notablescan # Do not allow table scans--nounixsocket # Disabling UNIX socket snooping--nssize Arg (=16# Set the message database. ns File Size (MB)--Objcheck # in the receipt of customer data, check the validity of--profile arg # file parameter 0=off 1=slow, 2 = All--Quota # Limit the number of files per database, set default to 8--quotafiles Arg # Numberof files Allower per db, requires--Quota--Rest # Open a simple rest API--Repair # Repair all databases run repair on all DBS--repairpath arg # Fix directory of files generated by the library, default to directory name DBPath--slowms Arg (=100) # Value of Slow forProfile and console log--Smallfiles # Using a smaller default file--syncdelay Arg (=60) # Number of seconds data written to disk (0=never, not recommended)--SysInfo # Print Some diagnostic system Information--upgrade # If you need to upgrade your database *Replicaton Parameters----------------------------------------------------------------------------------Fastsync # from a dbpath to enable the Copy service from the library, the DBPath database is a snapshot of the main library and can be used to quickly enable synchronization--Autoresync # If synchronizing data from the library to the main library is much worse, automatic resynchronization--oplogsize ARG # Sets the size of Oplog (MB) * Primary/From the parameter----------------------------------------------------------------------------------Master # Main Library mode--slave # from library mode--Source Arg # from the Library port number--Only arg # Specifies a single database copy--slavedelay ARG # Sets the delay time for synchronizing the main library from the library * ReplicaSet(Replica set) option:----------------------------------------------------------------------------------Replset Arg # Sets the replica set name *sharding (shard) Option----------------------------------------------------------------------------------Configsvr # declares that this is a clustered config service, Default port 27019, default directory/Data/configdb--Shardsvr # declares that this is a clustered shard, the default port 27018--nomoveparanoia # Turn off paranoid for movechunk data save
Backup RESTORE Database Backup
[Email protected] mongodb3.2.10]$./Bin/Mongodump--port=27017-ucdy-ppasswd--db=caideyang-o/Home/Caideyang/Backup/2016-10-30t15:58:58.082+0800writing Caideyang.score to2016-10-30t15:58:58.083+0800writing Caideyang.user to2016-10-30t15:58:58.084+0800 Done Dumping Caideyang.score (4documents)2016-10-30t15:58:58.085+0800 done Dumping Caideyang.user (2documents) [[Email protected]~]$ Tree backup/Backup/└──caideyang├──score.bson├──score.metadata.json├──user.bson└──user.metadata.json1 directory, 4files

Restores

[Email protected] mongodb3.2.10]$./Bin/Mongorestore--port=27017-ucdy-ppasswd--db=caideyang./Backup/caideyang/2016-10-30t16:04:43.914+0800 building a list of collections to restore from:/Backup/Caideyang dir2016-10-30t16:04:43.918+0800 reading metadata forCaideyang.score from../Backup/Caideyang/score.metadata.json2016-10-30t16:04:43.918+0800 reading metadata forCaideyang.user from../Backup/Caideyang/user.metadata.json2016-10-30t16:04:43.918+0800 restoring Caideyang.score from:/Backup/Caideyang/score.bson2016-10-30t16:04:43.918+0800 restoring Caideyang.user from:/Backup/Caideyang/user.bson2016-10-30t16:04:43.930+0800 error:multiple ErrorsinchBulk Operation:-E11000 Duplicate key error Collection:caideyang.user index: _id_ dup key: {: ObjectId (' 5815a5fa5fee222be4c321c9 ') }  -E11000 Duplicate key error Collection:caideyang.user index: _id_ dup key: {: ObjectId (' 5815a63a5fee222be4c321ca ') }2016-10-30t16:04:43.930+0800 Restoring Indexes forcollection Caideyang.user from metadata2016-10-30t16:04:43.936+0800 finished restoring Caideyang.user (2documents)2016-10-30t16:04:43.988+0800 Restoring Indexes forcollection Caideyang.score from metadata2016-10-30t16:04:43.989+0800 finished restoring Caideyang.score (4documents)2016-10-30t16:04:43.989+0800Done[[email protected] mongodb3.2.10]$

Note: Some of the content is referenced from https://www.jianshu.com/p/5844fdfa9511

Part I: MongoDB memo

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.