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.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() 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数据库中可用。超级账号,超级权限
转载于:https://www.cnblogs.com/chenpingzhao/p/7906360.html
Centos下MongoDB的安装与配置相关推荐
- centOS下mongodb的安装
###############centOS下mongodb的安装######### mongodb作为非关系型数据库NoSQL数据库的一种,并且是属于免安装类型. mongodb安装说明:32的安装d ...
- Ubuntu下mongodb的安装与配置
MongoDB 是一个跨平台的,面向文档的数据库,提供高性能,高可用性和可扩展性方便.这里介绍在Ubuntu下mongodb的安装与配置. 1.下载 mongodb可以在官网上下载,地址,选择Ubun ...
- windows下mongodb的安装与配置
下载安装 官网下载mongoDB:http://www.mongodb.org/downloads windows7 64位安装3.6版本会发生安装到一半后,就一直无法安装下去的问题(可能是因为安装时 ...
- Centos下telnet的安装和配置
网上摘录的留着自己有用! 摘自:http://blog.sina.com.cn/s/blog_53ec9d910101pmi0.html#post vista或windows 7的系统默认安装是没有安 ...
- mongo连接命令 windows_windows下mongodb的安装与配置(全)
mongodb由于学Python存数据,需要用到mongodb数据库,自己在网上搜了很多教程,也踩了许多坑,特记录下来,希望能够对一些朋友有用,也记录下自己学的东西. 下载与安装下载符合你系统的版本, ...
- CentOS下Tomcat的安装及配置教程
下载Tomcat,官网地址:https://tomcat.apache.org/download-80.cgi. 在 /usr/local 目录下新建 tomcat 文件夹,并进入. cd /usr/ ...
- MongoDB的安装与配置(简单版本、Win7)
大家好,我是邵奈一,一个不务正业的程序猿.正儿八经的斜杠青年. 1.世人称我为:被代码耽误的诗人.没天赋的书法家.五音不全的歌手.专业跑龙套演员.不合格的运动员- 2.这几年,我整理了很多IT技术相关 ...
- windows10系统下MongoDB的安装及环境配置
windows10系统下MongoDB的安装及环境配置: MongoDB的安装 下载地址: https://www.mongodb.com/download-center (这是windows10环境 ...
- Centos 7下Nagios的安装及配置(完整版)
Centos 7下Nagios的安装及配置(完整版) 简介 Nagios 是一款自动化运维工具,可以协助运维人员监控服务器的运行状况,并且拥有报警功能.本文章将介绍其安装方法和详细的配置方法. nag ...
最新文章
- PHP----------php封装的一些简单实用的方法汇总
- 给RadioButtonList这些加JS事件
- Specified key was too long; max key length is 1000 bytes问题解决
- JNI学习积累之一 ---- 常用函数大全
- 程序员编程必备名言佳句,提升装逼指数~
- 对于Office Live平台的思考
- raspberry pi_前5名:替代密码,Raspberry Pi进入太空等等
- Linux CentOS 7.2 安装 Tomcat 8 服务器
- Atitit.增强系统稳定性----虚拟内存的设置
- 算法探究:线性时间选择问题
- android 城市列表分组,Android实现简单的城市列表功能
- Hdu-5053 the Sum of Cube(水题)
- splunk 日志分析软件 简介
- 车牌识别算法介绍与实践
- 回首13我们奋斗在14的路上
- 信息学奥赛一本通:1156:求π的值
- 批处理命令之Start的详细用法\批处理打开IE窗口最大化
- python的转义字符,以及字符串输出转义字符
- Lucene实现自定义中文同义词分词器
- 弹性地基梁板法计算原理_平面弹性地基梁法,详细讲解!