Centos下mongodb的安裝與配置

來源:互聯網
上載者:User

標籤:restore   horizon   from   tab   family   default   127.0.0.1   sharding   list   

安裝MongoDB的方法有很多種,可以原始碼安裝,在Centos也可以用yum源安裝的方法。

1、準備工作

運行yum命令查看MongoDB的包資訊(正常是沒有資訊提示的,我這裡已經按安裝好了)

[[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 system (metapackage)URL         : http://www.mongodb.orgLicense     : AGPL 3.0Description : MongoDB is built for scalability, performance and high availability, scaling from single server deployments to large, complex multi-site architectures. By leveraging in-memory            : computing, MongoDB provides high performance for both reads and writes. MongoDB’s native replication and automated failover enable enterprise-grade reliability and operational            : flexibility.            :             : MongoDB is an open-source database used by companies of all sizes, across all industries and for a wide variety of applications. It is an agile database that allows schemas to            : change quickly as applications evolve, while still providing the functionality developers expect from traditional databases, such as secondary indexes, a full query language            : and strict consistency.            :             : MongoDB has a rich client ecosystem including hadoop integration, officially supported drivers for 10 programming languages and environments, as well as 40 drivers supported            : by the user community.            :             : MongoDB features:            : * JSON Data Model with Dynamic Schemas            : * Auto-Sharding for Horizontal Scalability            : * Built-In Replication for High Availability            : * Rich Secondary Indexes, including geospatial            : * TTL indexes            : * Text Search            : * Aggregation Framework & Native MapReduce            :             : This metapackage will install the mongo shell, import/export tools, other client utilities, server software, default configuration, and init.d scripts.

(如果沒有提示相關匹配的資訊,) 說明你的centos系統中的yum源不包含MongoDB的相關資源,

2、增加源
vim /etc/yum.repos.d/mongodb-3.4.repo

輸入下面的語句:

[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、安裝
yum install -y mongodb-org
4、啟動Mongodb
service mongod start

以後有更新了執行yum update  mongodb-org 即可。

5、伺服器配置
# 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#啟用定期記錄CPU利用率和 I/O 等待   # Enables periodic logging of CPU utilization and I/O wait#cpu=true# 是否以安全認證方式運行,預設是不認證的非安全方式   # Turn on/off security.  Off is currently the default#noauth=trueauth=true# Verbose logging output.#verbose=true# Inspect all client data for validity on receipt (useful for# developing drivers)#objcheck=true# Enable db quota management 啟用資料庫配額管理,預設每個db可以有8個檔案,可以用quotaFiles參數設定   #quota=true# Set oplogging level where n is#   0=off (default)#   1=W#   2=R#   3=both#   7=W+some reads#diaglog=0# Ignore query hints#nohints=true# Enable the HTTP interface (Defaults to port 28017).#httpinterface=true# Turns off server-side scripting.  This will result in greatly limited# functionality#noscripting=true# Turns off table scans.  Any query that would do a table scan fails.#notablescan=true# Disable data file preallocation.#noprealloc=true# Specify .ns file size for new databases.# nssize=<size># Replication Options# in replicated mongo databases, specify the replica set name here#replSet=setname# maximum size in megabytes for replication operation log#oplogSize=1024# path to a key file storing authentication info for connections# between replica set members#keyFile=/path/to/keyfile
配置授權登入
> use admin> db.createUser({user:"root",pwd:"123456",roles:[{role:"root",db:"admin"}]})
登入資料庫
mongo 127.0.0.1:27017/admin -u root -p
查詢
> db.comlogs.find().count()326466
PHP測試代碼
<?php$mongo = new Mongo("mongodb://root:[email protected]:27017/admin");   //認證使用者,這裡的資料庫,只啟認證作用  $db = $mongo->selectDB(‘admin‘);  //選取資料庫  $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" => 100,    "url" => "http://www.cnblogs.com/chenpingzhao");$users->insert($document);
6、mongodb角色

內建角色

  • 資料庫使用者角色:read、readWrite;

  • 資料庫管理角色:dbAdmin、dbOwner、userAdmin;

  • 叢集管理角色:clusterAdmin、clusterManager、clusterMonitor、hostManager;

  • 備份恢複角色:backup、restore;

  • 所有資料庫角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、dbAdminAnyDatabase

  • 超級使用者角色:root, 這裡還有幾個角色間接或直接提供了系統超級使用者的訪問(dbOwner 、userAdmin、userAdminAnyDatabase)

  • 內部角色:__system

具體角色

  • read:允許使用者讀取指定資料庫

  • readWrite:允許使用者讀寫指定資料庫

  • dbAdmin:允許使用者在指定資料庫中執行管理函數,如索引建立、刪除,查看統計或訪問system.profile

  • userAdmin:允許使用者向system.users集合寫入,可以找指定資料庫裡建立、刪除和系統管理使用者

  • clusterAdmin:只在admin資料庫中可用,賦予使用者所有分區和複製集相關函數的系統管理權限。

  • readAnyDatabase:只在admin資料庫中可用,賦予使用者所有資料庫的讀許可權

  • readWriteAnyDatabase:只在admin資料庫中可用,賦予使用者所有資料庫的讀寫權限

  • userAdminAnyDatabase:只在admin資料庫中可用,賦予使用者所有資料庫的userAdmin許可權

  • dbAdminAnyDatabase:只在admin資料庫中可用,賦予使用者所有資料庫的dbAdmin許可權。

  • root:只在admin資料庫中可用。超級帳號,超級許可權

Centos下mongodb的安裝與配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.