There are many ways to install MongoDB, you can install the source code, and you can use the Yum source installation method in CentOS.
1. Preparatory work
Run the Yum command to view the MongoDB package information (normal is no information prompted, I have already pressed the installation here)
[[email protected]~]# yum info mongodb-orgloaded plugins:fastestmirrorloading mirror speeds from cached Hostfileinstalled packagesname:mongodb-orgarch:x86_64version:3.4.10release:1.el6size : 0.0 repo:installedfrom repo:mongodb-org-3.4summary:mongodb Open source document-oriented database sy Stem (metapackage) URL:HTTP://WWW.MONGODB.ORGLICENSE:AGPL 3.0description:mongodb is built for scalability , performance and availability, scaling from single server deployments to large, complex multi-site architectures. By leveraging In-memory:computing, MongoDB provides-performance for both reads and writes. MongoDB ' s native replication and automated failover enable enterprise-grade reliability and Operational:flexi Bility. :: MongoDB is an Open-source database used by companies of all sizes, across all industries and for a wide VA Riety of applications. It's anAgile database that allows schemas To:change quickly as applications evolve while still providing the FUNCTI Onality developers expect from traditional databases, such as secondary indexes, a full query Language:and St Rict consistency. :: MongoDB have a rich client ecosystem including Hadoop integration, officially supported drivers for ten prog Ramming languages and environments, as well as drivers supported:by the user community. :: MongoDB Features:: * JSON Data Model with Dynamic Schemas: * auto-sharding for Hor Izontal Scalability: * Built-in Replication for high availability: * Rich secondary Indexes, inclu Ding Geospatial: * TTL Indexes: * Text Search: * Aggregation Framework & Native Ma Preduce:: This metapackage would install the MONGO shell, Import/export tools, other client Utilit Ies, Server software, default configuration, and INIT.D scripts.
(If there is no indication of the relevant matching information,) the Yum source in your CentOS system does not contain MONGODB related resources,
2. Increase the source
Vim/etc/yum.repos.d/mongodb-3.4.repo
Enter the following statement:
[Mongodb-org-3.4]name=mongodb repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4 /x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
3. Installation
Yum Install-y mongodb-org
4. Start MongoDB
Service Mongod Start
There is a later update to perform yum update mongodb-org .
5. Server Configuration
# Mongod.conf#where to Loglogpath=/data/logs/mongodb/mongod.loglogappend=true #以追加方式写入日志 # Fork and run in Backgroundfork=true#port=27017dbpath=/data/mongo #数据库文件保存位置 # Location of pidfilepidfilepath=/var/run/mongodb/ mongod.pid# Listen to local interface only. Comment out to listen on all interfaces. bind_ip=10.81.85.229# disables Write-ahead journaling# nojournal=true# enable periodic logging of CPU utilization and I/O wait # enables periodic logging of Whether the CPU utilization and I/O wait#cpu=true# are running in a secure authentication mode, the default is an unauthenticated non-secure way # Turn on/off security. OFF is currently the default#noauth=trueauth=true# Verbose logging output. #verbose =true# Inspect All client data for valid ity on receipt (useful for# developing drivers) #objcheck =true# Enable DB quota management enables database quota management, with a default of 8 files per db, which can be used with quot Afiles parameter Settings #quota =true# set oplogging level where n is# 0=off (default) # 1=w# 2=r# 3=both# 7=w+some reads#diag log=0# Ignore Query hints#nohints=true# Enable the HTTP interface (Defaults to Port 28017). #httpinterface =true# Turns ofF server-side Scripting. This would result in greatly limited# functionality#noscripting=true# Turns off table scans. Any query this would do a table scan fails. #notablescan =true# Disable data file preallocation. #noprealloc =true# specify. N s file size for new databases.# nssize=<size># Replication options# in replicated MONGO databases, specify the Repli CA Set name here#replset=setname# maximum size in megabytes for replication operation log#oplogsize=1024# Path to a key fi Le storing authentication info for connections# between replica set Members#keyfile=/path/to/keyfile
Configure authorized Logins
> Use admin> db.createuser ({User: "root", pwd: "123456", Roles:[{role: "Root", DB: "Admin"}]})
log in to database
MONGO 127.0.0.1:27017/admin-u Root-p
Enquiry
> Db.comlogs.find (). Count () 326466
PHP test Code
<?php$mongo = new MONGO ("Mongodb://root:[email protected]:27017/admin"); Authenticated Users, the database here, only the authentication function $db = $mongo->selectdb (' admin '); Select database $users = $db->selectcollection ("test"), $cursor = $users->find (); foreach ($cursor as $id = + $value) { echo "$id:"; Print_r ($value); echo "<br>";} $document = Array ( "title" = "MongoDB", "description" = "Database", "likes" = "=", " url" = > "Http://www.cnblogs.com/chenpingzhao"); $users->insert ($document);
6. MongoDB role
Built-in roles
Database user role: Read, readWrite;
Database management roles: DbAdmin, Dbowner, useradmin;
Cluster Management role: Clusteradmin, Clustermanager, Clustermonitor, Hostmanager;
Backup recovery role: backups, restore;
All database roles: Readanydatabase, Readwriteanydatabase, Useradminanydatabase, dbadminanydatabase
Superuser role: Root, where there are several roles that indirectly or directly provide access to the system's Superuser (Dbowner, Useradmin, Useradminanydatabase)
Internal role: __system
Specific roles
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 perform administrative functions in the specified database, such as index creation, deletion, viewing statistics, or accessing System.profile
Useradmin: Allows the user to write to the System.users collection to create, delete, and manage users in the specified database
Clusteradmin: Available only in the admin database, giving the user administrative privileges on all shards and replica set related functions.
Readanydatabase: Only available in the Admin database, giving users read access to all databases
Readwriteanydatabase: Only available in the Admin database, giving users read and write access to all databases
Useradminanydatabase: Only available in the Admin database, giving the user useradmin permissions for all databases
Dbadminanydatabase: Only available in the Admin database, giving the user dbadmin permissions for all databases.
Root: Available only in the admin database. Super account, Super privilege
Installation and configuration of MongoDB under CentOS