Centos下MongoDB的安装与配置
安裝MongoDB的方法有很多種,可以源代碼安裝,在Centos也可以用yum源安裝的方法。
1、準備工作
運行yum命令查看MongoDB的包信息(正常是沒有信息提示的,我這里已經按安裝好了)
[root@localhost~]# yum info mongodb-org Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Installed Packages Name : mongodb-org Arch : x86_64 Version : 3.4.10 Release : 1.el6 Size : 0.0 Repo : installed From repo : mongodb-org-3.4 Summary : MongoDB open source document-oriented database system (metapackage) URL : http://www.mongodb.org License : AGPL 3.0 Description : 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 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.2.asc3、安裝
yum install -y mongodb-org4、啟動Mongodb
service mongod start以后有更新了執行yum update??mongodb-org?即可。
5、服務器配置
# mongod.conf#where to log logpath=/data/logs/mongodb/mongod.loglogappend=true #以追加方式寫入日志# fork and run in background fork=true#port=27017dbpath=/data/mongo #數據庫文件保存位置# location of pidfile pidfilepath=/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=true auth=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() 326466PHP測試代碼
<?php $mongo = new Mongo("mongodb://root:123456@127.0.0.1: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數據庫中可用。超級賬號,超級權限
轉載于:https://www.cnblogs.com/chenpingzhao/p/7906360.html
總結
以上是生活随笔為你收集整理的Centos下MongoDB的安装与配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MySQL bin-log 日志清理方式
- 下一篇: 广发卡降额了咋办