安装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.asc

3、安装

yum install -y mongodb-org

4、启动Mongodb

service mongod start

以后有更新了执行yum update  mongodb-org 即可。

5、服务器配置

# mongod.conf

#where to log
logpath=/data/logs/mongodb/mongod.log logappend=true #以追加方式写入日志 # fork and run in background
fork=true #port=27017 dbpath=/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()
326466

PHP测试代码

<?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数据库中可用。超级账号,超级权限

Centos下mongodb的安装与配置的更多相关文章

  1. mac与centos下redis的安装与配置

    前言 最近在用redis,下面简单写一下mac和centos下redis的安装与配置方法. 安装 mac下面 安装命令:brew intall redis 运行命令:brew services sta ...

  2. Centos下telnet的安装和配置

    Centos下telnet的安装和配置 首先为Centos配置地址(192.168.0.1/24) 一.查看本机是否有安装telnetrpm -qa | grep telnetrpm -q telne ...

  3. Windows环境下MongoDB的安装与配置

    MongoDB是一种高性能的文档型数据库,现介绍一下在Windows环境下MongDB的安装与配置 获取MongoDB 打开官方网站 www.mongodb.org,找到页面右上解的DownLoad链 ...

  4. Centos下Nagios的安装与配置

    一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报 ...

  5. CentOS下PostgreSQL的安装与配置

    一.CentOS下PostgreSQL的yum安装: #安装yum源,默认源存在对版本的支持不好,下载不到等等问题. yum install http://yum.postgresql.org/9.5 ...

  6. windows下MongoDB的安装,配置与开机自启动

    关于简介不多说百度去吧少年.. MongoDB详细安装: 1.进入官网,点击DOWNLOAD MONGODB,下载所需要的版本.. 我这里把下载的文件放在d\MongoDB文件夹下,点击下载的官方镜像 ...

  7. Centos下的MySQL安装及配置

    里使用的是VMware虚拟机和Centos7系统 虚拟机安装这里不多讲,网上教程很多了,这里就介绍下虚拟机的网络配置. 虚拟机网络配置 Centos网络连接模式这里设置为桥接模式,不用勾选复制物理网络 ...

  8. centos下postgresql的安装与配置[转]

    本文摘自:http://blog.chinaunix.net/uid-24846094-id-78490.html 一.安装(以root身份进行) 1.检出最新的postgresql的yum配置从ht ...

  9. Linux下MongoDB的安装、配置、启动

    下载 MongoDB下载地址为 https://www.mongodb.org/downloads 安装 将文件放到/usr/local/目录下并解压 tar -zxvf mongodb-linux- ...

随机推荐

  1. (@WhiteTaken)设计模式学习——享元模式

    继续学习享元模式... 乍一看到享元的名字,一头雾水,学习了以后才觉得,这个名字确实比较适合这个模式. 享元,即共享对象的意思. 举个例子,如果制作一个五子棋的游戏,如果每次落子都实例化一个对象的话, ...

  2. win10 UWP 九幽数据分析

    九幽数据统计是统计和分析数据来源,用户使用,先申请账号 http://www.windows.sc 创建应用 图片要72*72 记密钥 在项目Nuget 在App.xaml.cs public App ...

  3. Xamarin Forms 进度条控件

    本文翻译:http://xamlnative.com/2016/04/14/xamarin-forms-a-simple-circular-progress-control/ 里面都是胡说的,如果看不 ...

  4. 小星星的php

    大家好,我是小星星,最近新学的php,我迫不及待要跟大家分享了!!come on!一起来看小星星的世界 先为大家介绍php基础 首先我们来看看什么叫php: PHP(外文名:PHP: Hypertex ...

  5. 前端(各种demo):右侧导航栏的折叠和打开(不使用js)基础版和升级版

    1.给div设置定位. 复习一下—— css中position有五种属性: static:默认值,没有定位 absolute:绝对定位,相对于父级元素进行定位 relative:相对定位 fixed: ...

  6. Linux入门(11)——Ubuntu16.04安装texlive2016并配置texmaker和sublime text3

    安装过程中需要调用 Perl 的模块 Digest::MD5 来检测 ISO 文件的完整性:升级过程中界面需要调用 Perl 的模块 Tk: sudo apt-get install libdiges ...

  7. APP在模拟器崩溃,提示__gcd_queue_item_enqueue_hook_block_invoke

    libBacktraceRecording.dylib`__gcd_queue_item_enqueue_hook_block_invoke: libBacktraceRecording.dylib` ...

  8. JAVA判断文件的内容类型

    Java 7 新的特性,判断文件的内容类型. Program to demonstrate Java 7 new feature : Determining the file content type ...

  9. WebService调用(基于KSOAP2)

    public static boolean getData(String param) { //WebService服务器地址 String SERVICE_URL = "http://22 ...

  10. Spring MVC前后端的数据传输

    本篇文章主要介绍了Spring MVC中如何在前后端传输数据. 后端 ➡ 前端 在Spring MVC中这主要通过Model将数据从后端传送到前端,一般的写法为: @RequestMapping(va ...