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.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的安装与配置的更多相关文章
- mac与centos下redis的安装与配置
前言 最近在用redis,下面简单写一下mac和centos下redis的安装与配置方法. 安装 mac下面 安装命令:brew intall redis 运行命令:brew services sta ...
- Centos下telnet的安装和配置
Centos下telnet的安装和配置 首先为Centos配置地址(192.168.0.1/24) 一.查看本机是否有安装telnetrpm -qa | grep telnetrpm -q telne ...
- Windows环境下MongoDB的安装与配置
MongoDB是一种高性能的文档型数据库,现介绍一下在Windows环境下MongDB的安装与配置 获取MongoDB 打开官方网站 www.mongodb.org,找到页面右上解的DownLoad链 ...
- Centos下Nagios的安装与配置
一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报 ...
- CentOS下PostgreSQL的安装与配置
一.CentOS下PostgreSQL的yum安装: #安装yum源,默认源存在对版本的支持不好,下载不到等等问题. yum install http://yum.postgresql.org/9.5 ...
- windows下MongoDB的安装,配置与开机自启动
关于简介不多说百度去吧少年.. MongoDB详细安装: 1.进入官网,点击DOWNLOAD MONGODB,下载所需要的版本.. 我这里把下载的文件放在d\MongoDB文件夹下,点击下载的官方镜像 ...
- Centos下的MySQL安装及配置
里使用的是VMware虚拟机和Centos7系统 虚拟机安装这里不多讲,网上教程很多了,这里就介绍下虚拟机的网络配置. 虚拟机网络配置 Centos网络连接模式这里设置为桥接模式,不用勾选复制物理网络 ...
- centos下postgresql的安装与配置[转]
本文摘自:http://blog.chinaunix.net/uid-24846094-id-78490.html 一.安装(以root身份进行) 1.检出最新的postgresql的yum配置从ht ...
- Linux下MongoDB的安装、配置、启动
下载 MongoDB下载地址为 https://www.mongodb.org/downloads 安装 将文件放到/usr/local/目录下并解压 tar -zxvf mongodb-linux- ...
随机推荐
- Codeforces A. Trip For Meal
A. Trip For Meal time limit per test 1 second memory limit per test 512 megabytes input standard inp ...
- 文本处理工具(grep)
文本处理工具: Linux上文本处理三剑客: 文本过滤工具(模式:pattern)工具: 1.grep:支持基本正则表达式; 2.egrep: ...
- 读Zepto源码之Data模块
Zepto 的 Data 模块用来获取 DOM 节点中的 data-* 属性的数据,和储存跟 DOM 相关的数据. 读 Zepto 源码系列文章已经放到了github上,欢迎star: reading ...
- 在CUDA8.0下编译安装OpenCV3.1.0来实现GPU加速(Compiling OpenCV3.1.0 with CUDA8.0 support)
在CUDA8.0下编译安装OpenCV3.1.0 一.本人电脑配置:ubuntu 14.04, NVIDIA GTX1060. 二.编译OpenCV3.1.0前,读者需要成功安装CUDA8.0(网上有 ...
- springCloud四:熔断器ribbon--Hystrix
注:前文概念部分摘抄自博客园 纯洁的微笑 熔断器 雪崩效应 在微服务架构中通常会有多个服务层调用,基础服务的故障可能会导致级联故障,进而造成整个系统不可用的情况,这种现象被称为服务雪崩效应.服务雪崩 ...
- java笔记04: String的理解与运用
一,“==”与equals() 运行以下代码,如何解释其输出结果? public class StringPool { public static void main(String args[]) { ...
- 『实践』Yalmip建模+Cplex类求解
Yalmip建模+Cplex类求解 一.缘由 Yalmip只能设置部分Cplex的参数,所以需要调用Cplex类.而且optimize是Yalmip提供的常用函数,但此函数的返回结果参数有限. 图1 ...
- FastDFS 集群 安装 配置
这篇文章介绍如何搭建FastDFS 集群 FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储.文件同步.文件访问(文件上传.文件下载)等,解决了大容量存储和负载均衡的 ...
- 套接字(linux相关)
前言:略 一.前因 一切从tcp.udp开始. 众所周知,网络模型一般有两种模型,一种为OSI概念模型(七层),另一种为tcp/ip网络模型(四层). tcp/ip应用层对应OSI的应用层.显示层.会 ...
- 在找一份相对完整的Webpack项目配置指南么?这里有
Webpack已经出来很久了,相关的文章也有很多,然而比较完整的例子却不是很多,让很多新手不知如何下脚,下脚了又遍地坑 说实话,官方文档是蛮乱的,而且有些还是错的错的..很多配置问题只有爬过坑才知道 ...