Install via yum
D /mongodb-org-3.4.repo /etc/ymp.repos
Then copy the following configuration, save and exit
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
Copy the code
Install yum
Yum install -y mongodb-org Modify the configuration file by running the vi /etc/mongod.conf command
Change the bind_IP of the configuration file from 127.0.0.1 to 0.0.0.0 to allow remote connections and enable the firewall
3. Basic operation commands
Start: service mongod start
Stop: service mongod stop
Restart: service mongod restart
See if directing a startup success: the cat/var/log/mongo/mongod log; [initandListen] waiting for connections on port
You can also run the chkconfig mongod on command to check whether the startup is successful
Chown -r mongod:mongod /var/lib/mongo: chown -r mongod:mongod /var/lib/mongo: chown -r mongod:mongod /var/lib/mongo: chown -r mongod:mongod /var/lib/mongo: chown -r mongod:mongod /var/lib/mongo
Four, the use of
mongo show dbs; Db.version (); Db.help (); Uninstall to remove mongo yum erase $(RPM - qa | grep mongo - org) to remove the database file and log files rm - r/var/log/mongo rm - r/var/lib/mongo mongo password set Run the mongo command to go to the mongodb environment. Mongo Switch to the admin database. Use admin Set a password for the admin user. Db. CreateUser ({user: 'root', PWD: 'admin_mima', roles: Db. Auth ('root', 'mima') db. Auth ('root', 'mima') if '1 'is returned, authentication is successful; if' 0 'is returned, authentication fails. Db. CreateUser ({user: 'CCCC ', PWD:' CCCC ', db. CreateUser ({user: 'CCCC ', PWD:' CCCC ', db. Roles: [{role: 'readWrite', db: 'demo', roles: [{role: 'readWrite', db: 'demo'}]}) ReadWrite: allows users to Read and write data from the specified database. DbAdmin: allows users to perform management functions in the specified database, such as creating and deleting indexes, viewing statistics, and accessing system.profile userAdmin: Allows users to write to the System. users collection, create, delete, and manage users in the specified database clusterAdmin: Only available in the Admin database, giving users management rights to all sharding and replication set related functions. ReadAnyDatabase: only available in the Admin database, granting the user read and write permissions on all databases readWriteAnyDatabase: Only available in the admin database, granting the user read and write permissions on all databases userAdminAnyDatabase: DbAdminAnyDatabase: This parameter is available only in the admin database and is granted to the user with the dbAdmin permission for all databases. Root: available only in the admin database. Mongod --auth mongod --auth --config /etc/mongod. Conf I changed the mongodb configuration file to 0.0.0.0 to allow external access. Mongodb mongod -f /etc/mongod. Conf --fork --authCopy the code