CentOS 6 安裝mongodb https://docs.mongodb.com/manual/installation/#tutorial-installation
安裝MongoDB專業版
# 建立 /etc/yum.repos.d/mongodb-enterprise.repo[mongodb-enterprise]name=MongoDB Enterprise Repositorybaseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/3.4/$basearch/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.4.ascsudo yum install -y mongodb-enterprisesudo service mongod startsudo chkconfig mongod on sudo yum erase $(rpm -qa | grep mongodb-enterprise) # 卸載
安裝mongodb社區版
#配置包管理系統建立 /etc/yum.repos.d/mongodb-org-3.6.repo [mongodb-org-3.6]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.6/x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.6.asc
安裝MongoDB
sudo yum install -y mongodb-org#sudo yum install -y mongodb-org-3.6.3 mongodb-org-server-3.6.3 mongodb-org-shell-3.6.3 mongodb-org-mongos-3.6.3 mongodb-org-tools-3.6.3
啟動MongoDB
sudo service mongod startsudo chkconfig mongod onsudo service mongod stop
使用MongoDB
mongo --host 127.0.0.1:27017
卸載刪除MongoDB
sudo service mongod stopsudo yum erase $(rpm -qa | grep mongodb-org)sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongo
MongoDB建立使用者使用
https://www.mongodb.com/
https://www.mongodb.com/download-center#community mongodb loginin
mongo --port 27017help # 查看協助use admin # 切換到管理員db.createUser( { user: "Aniumongodb", pwd: "Aniumongodb123.", roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })# [root@mongodb ~]# mongo --port 27017MongoDB shell version v3.6.3connecting to: mongodb://127.0.0.1:27017/MongoDB server version: 3.6.3Server has startup warnings: 2018-04-02T17:12:06.214+0800 I STORAGE [initandlisten] 2018-04-02T17:12:06.214+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine2018-04-02T17:12:06.214+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem2018-04-02T17:12:07.413+0800 I CONTROL [initandlisten] 2018-04-02T17:12:07.413+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.2018-04-02T17:12:07.413+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.2018-04-02T17:12:07.414+0800 I CONTROL [initandlisten] MongoDB Enterprise > use adminswitched to db adminMongoDB Enterprise > db.createUser(... {... user: "Aniumongodb",... pwd: "Aniumongodb123.",... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]... }... )Successfully added user: { "user" : "Aniumongodb", "roles" : [ { "role" : "userAdminAnyDatabase", "db" : "admin" } ]}MongoDB Enterprise > exitbye
MongoDB使用者簡介
Built-In Roles(內建角色): 1. 資料庫使用者角色:read、readWrite; 2. 資料庫管理角色:dbAdmin、dbOwner、userAdmin; 3. 叢集管理角色:clusterAdmin、clusterManager、clusterMonitor、hostManager; 4. 備份恢複角色:backup、restore; 5. 所有資料庫角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase 6. 超級使用者角色:root // 這裡還有幾個角色間接或直接提供了系統超級使用者的訪問(dbOwner 、userAdmin、userAdminAnyDatabase) 7. 內部角色:__system# 使用者角色許可權Read:允許使用者讀取指定資料庫readWrite:允許使用者讀寫指定資料庫dbAdmin:允許使用者在指定資料庫中執行管理函數,如索引建立、刪除,查看統計或訪問system.profileuserAdmin:允許使用者向system.users集合寫入,可以找指定資料庫裡建立、刪除和系統管理使用者clusterAdmin:只在admin資料庫中可用,賦予使用者所有分區和複製集相關函數的系統管理權限。readAnyDatabase:只在admin資料庫中可用,賦予使用者所有資料庫的讀許可權readWriteAnyDatabase:只在admin資料庫中可用,賦予使用者所有資料庫的讀寫權限userAdminAnyDatabase:只在admin資料庫中可用,賦予使用者所有資料庫的userAdmin許可權dbAdminAnyDatabase:只在admin資料庫中可用,賦予使用者所有資料庫的dbAdmin許可權。root:只在admin資料庫中可用。超級帳號,超級許可權
建立超級管理員賬戶
db.createUser(... {... user: "Aniudba",... pwd: "Aniudba123.",... roles: [... { role: "root", db: "admin" }... ]... }... )Successfully added user: { "user" : "Aniudba", "roles" : [ { "role" : "root", "db" : "admin" } ]}
MongoDB啟動錯誤 WARNING: soft rlimits too low. rlimits set to 1024 processes, 16392 files. Number of processes should be at least 8196
修改 /etc/security/limits.d/90-nproc.conf* soft nproc 16392 # 1024改為16392root soft nproc unlimited重啟MongoDB服務 /etc/init.d/mongod restart
MongoDB 串連工具
WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
WARNING: Access control is not enabled for the database.Read and write access to data and configuration is unrestricted.
參考:http://www.cnblogs.com/zhoujinyi/p/4610050.html