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- ...
随机推荐
- Git相关操作三
1.显示当前分支: git branch 输入上述命令可以显示出分支,*所在的分支为当前分支. 2.新建分支: git branch new_branch new_branch为新建分支的名称,注意该 ...
- Pdf文件处理组件对比(Aspose.Pdf,Spire.Pdf,iText7)
目的 因为公司是做医疗相关软件的,所以经常和文档打交道,其中就包含了Pdf.医院的Pdf(通常是他们的报告)都千奇百怪,而我们一直以来都是在用一些免费且可能已经没人维护了的组件来处理Pdf,所以就经常 ...
- LeetCode 533. Lonely Pixel II (孤独的像素之二) $
Given a picture consisting of black and white pixels, and a positive integer N, find the number of b ...
- 解决执行sql脚本报错:没有足够的内存继续执行程序。
出现执行sql脚本报错:没有足够的内存继续执行程序.是因为sql脚本过大,大家可能分为多个文件多次执行,这种笨方法可行,不过比较麻烦,大家可以用下面的方式,利用sqlcmd一次就行了: 执行cmd ...
- eclipse查看类源码出现failed to create the part's controls的解决方法
刚装好eclipse和Tomcat ,在看准备使用的一个开源框架jeesite,可是在查看源代码的时候出现这个问题
- idea配置jetty服务器,通过mvn实现
今天想试试除了tomcat之外的另一个服务器jetty的使用: 关于项目在tomcat中的启动大概有多种,尤其是在本地环境下,ide关于tomcat的优化做的很好,但是在idea上面部署tomcat总 ...
- Ionic3 遇到的一些错误-submodule update -q --init --recursive
解决方法: ionic start myTabs tabs --skip-deps cd .\myTabs cnpm install --save-dev ionic serve > npm i ...
- Linux学习(十四)磁盘格式化、磁盘挂载、手动增加swap空间
一.磁盘格式化 分好去的磁盘需要格式化之后才可以使用.磁盘分区一般用mke2fs命令或者mkfs.filesystemtype.这个filesystemtype分为ext4,ext3,xfs等等.xf ...
- linux学习(七)环境变量、cp、mv、cat,less,more,head,tail
一.环境变量 环境变量其实就是$PATH: [root@iZ25lzba47vZ ~]# echo $PATH /usr/local/nginx/sbin:/usr/local/php/bin:/us ...
- js获取浏览器版本
获取火狐,谷歌,ie,常见浏览器的方法 function myBrowser(){ var userAgent = navigator.userAgent, rMsie = /(msie\s|trid ...