Centos 安装mongodb
简介:yum 源安装MongoDB
MongoDB v2.6.0版的软件仓库一共有五个包:
1)mongodb-org
此包是元数据包,它可以实现自动安装下面的4个组件包。
2)mongodb-org-server
此包里面有mongod守护程序,以及相关的配置和初始化脚本。
3)mongodb-org-mongos
此包里面有mongos守护程序。
4)mongodb-org-shell
此包里面有mongo shell环境。
5)mongodb-org-tools
此包里面有以下的MongoDB工具:mongoimport、bsondump、mongodump、mongoexport、mongofiles、mongoimport、mongooplog、mongoperf、mongorestore、mongostat以及mongotop。
一、添加yum源文件:
根据官网步骤(Install on Red Hat),创建mongodb-org-3.2.repo文件。添加官方提供的yum源,因为网络原因,修改yum源为aliyun的yum源。
[mongodb-org-3.2]name=MongoDBRepository#baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/6/mongodb-org/3.2/x86_64/#gpgcheck=1gpgcheck=0enabled=1#gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc
二、执行安装命令:
[root@localhost yum.repos.d]# lsCentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo mongodb-org-3.2.repoCentOS-Base.repo.backup CentOS-fasttrack.repo CentOS-Vault.repo[root@localhost yum.repos.d]# yum info mongodb-org-3.2 #这个操作没懂是为啥?已加载插件:fastestmirror, securityLoading mirror speeds from cached hostfile*base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com错误:没有匹配的软件包可以列出[root@localhost yum.repos.d]# yum install -y mongodb-org已加载插件:fastestmirror, security设置安装进程Loading mirror speeds from cached hostfile*base: mirrors.aliyun.com* extras: mirrors.aliyun.com* updates: mirrors.aliyun.com解决依赖关系-->执行事务检查--->Package mongodb-org.x86_64 0:3.2.10-1.el6 will be 安装-->处理依赖关系 mongodb-org-tools =3.2.10,它被软件包 mongodb-org-3.2.10-1.el6.x86_64 需要-->处理依赖关系 mongodb-org-shell =3.2.10,它被软件包 mongodb-org-3.2.10-1.el6.x86_64 需要-->处理依赖关系 mongodb-org-server =3.2.10,它被软件包 mongodb-org-3.2.10-1.el6.x86_64 需要-->处理依赖关系 mongodb-org-mongos =3.2.10,它被软件包 mongodb-org-3.2.10-1.el6.x86_64 需要-->执行事务检查--->Package mongodb-org-mongos.x86_64 0:3.2.10-1.el6 will be 安装--->Package mongodb-org-server.x86_64 0:3.2.10-1.el6 will be 安装--->Package mongodb-org-shell.x86_64 0:3.2.10-1.el6 will be 安装--->Package mongodb-org-tools.x86_64 0:3.2.10-1.el6 will be 安装-->完成依赖关系计算依赖关系解决==================================================================================================================================软件包架构版本仓库大小==================================================================================================================================正在安装:mongodb-org x86_64 3.2.10-1.el6 mongodb-org-3.25.8 k为依赖而安装:mongodb-org-mongos x86_64 3.2.10-1.el6 mongodb-org-3.26.0 Mmongodb-org-server x86_64 3.2.10-1.el6 mongodb-org-3.213 Mmongodb-org-shell x86_64 3.2.10-1.el6 mongodb-org-3.27.3 Mmongodb-org-tools x86_64 3.2.10-1.el6 mongodb-org-3.242 M事务概要==================================================================================================================================Install5Package(s)总文件大小:68 M总下载量:6.0 MInstalled size:199 M下载软件包:(1/2): mongodb-org-3.2.10-1.el6.x86_64.rpm |5.8 kB 00:00(2/2): mongodb-org-mongos-3.2.10-1.el6.x86_64.rpm |6.0 MB 00:27----------------------------------------------------------------------------------------------------------------------------------总计219 kB/s |6.0 MB 00:28运行 rpm_check_debug执行事务测试事务测试成功执行事务正在安装: mongodb-org-mongos-3.2.10-1.el6.x86_64 1/5正在安装: mongodb-org-tools-3.2.10-1.el6.x86_64 2/5正在安装: mongodb-org-shell-3.2.10-1.el6.x86_64 3/5正在安装: mongodb-org-server-3.2.10-1.el6.x86_64 4/5正在安装: mongodb-org-3.2.10-1.el6.x86_64 5/5Verifying: mongodb-org-server-3.2.10-1.el6.x86_64 1/5Verifying: mongodb-org-3.2.10-1.el6.x86_64 2/5Verifying: mongodb-org-shell-3.2.10-1.el6.x86_64 3/5Verifying: mongodb-org-tools-3.2.10-1.el6.x86_64 4/5Verifying: mongodb-org-mongos-3.2.10-1.el6.x86_64 5/5已安装:mongodb-org.x86_64 0:3.2.10-1.el6作为依赖被安装:mongodb-org-mongos.x86_64 0:3.2.10-1.el6 mongodb-org-server.x86_64 0:3.2.10-1.el6 mongodb-org-shell.x86_64 0:3.2.10-1.el6mongodb-org-tools.x86_64 0:3.2.10-1.el6完毕![root@localhost yum.repos.d]# rpm -qa | grep mongodbmongodb-org-3.2.10-1.el6.x86_64mongodb-org-tools-3.2.10-1.el6.x86_64mongodb-org-shell-3.2.10-1.el6.x86_64mongodb-org-server-3.2.10-1.el6.x86_64mongodb-org-mongos-3.2.10-1.el6.x86_64[root@localhost yum.repos.d]#[root@localhost yum.repos.d]# ls /usr/bin/mongo(tab键) mongo mongodump mongofiles mongooplog mongorestore mongostat mongod mongoexport mongoimport mongoperf mongos mongotop
三、如果熟悉的话,可以修改配置文件,不熟悉保持默认即可。配置log位置和指定数据库路径位置:
# mongod.conf# for documentation of all options, see:# http://docs.mongodb.org/manual/reference/configuration-options/# where to write logging data.systemLog:destination: filelogAppend:truepath:/var/log/mongodb/mongod.log# Where and how to store data.storage:dbPath:/var/lib/mongojournal:enabled:true# engine:# mmapv1:# wiredTiger:# how the process runsprocessManagement:fork:true# fork and run in backgroundpidFilePath:/var/run/mongodb/mongod.pid # location of pidfile# network interfacesnet:port:27017bindIp:127.0.0.1# Listen to local interface only, comment to listen on all interfaces.#security:#operationProfiling:#replication:#sharding:## Enterprise-Only Options#auditLog:#snmp:
4、启动MongoDB
sudo service mongod start
5、使MongoDB开机自动启动
sudo chkconfig mongod on
6、停止MongoDB
sudo service mongod stop
7、重启MongoDB
sudo service mongod restart
8、进入Mongo命令行
[root@localhost yum.repos.d]# mongoMongoDB shell version:3.2.10connecting to: testWelcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, seehttp://docs.mongodb.org/Questions?Try the support grouphttp://groups.google.com/group/mongodb-userServer has startup warnings:2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]** WARNING:/sys/kernel/mm/transparent_hugepage/enabled is'always'.2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]**We suggest setting it to 'never'2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]** WARNING:/sys/kernel/mm/transparent_hugepage/defrag is'always'.2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]**We suggest setting it to 'never'2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]** WARNING: soft rlimits too low. rlimits set to 1024 processes,64000 files.Number of processes should be at least 32000:0.5 times number of files.2016-11-07T12:08:44.814+0800 I CONTROL [initandlisten]>2+24
参考链接:
yum 源安装MongoDB
MongoDB v2.6.0版的软件仓库一共有五个包:
1)mongodb-org
此包是元数据包,它可以实现自动安装下面的4个组件包。
2)mongodb-org-server
此包里面有mongod守护程序,以及相关的配置和初始化脚本。
3)mongodb-org-mongos
此包里面有mongos守护程序。
4)mongodb-org-shell
此包里面有mongo shell环境。
5)mongodb-org-tools
此包里面有以下的MongoDB工具:mongoimport、bsondump、mongodump、mongoexport、mongofiles、mongoimport、mongooplog、mongoperf、mongorestore、mongostat以及mongotop。
1,创建mongodb.repo文件
在/etc/yum.repos.d/目录下创建文件mongodb.repo,它包含MongoDB仓库的配置信息,内容如下:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
2,执行安装命令
# yum -y install mongodb-org
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: mirrors.yun-idc.com
* epel: mirrors.yun-idc.com
* extras: mirrors.yun-idc.com
* updates: mirrors.yun-idc.com
Setting up Install Process
Package mongodb-org-2.6.3-1.x86_64 already installed and latest version
Nothing to do
# rpm -qa |grep mongodb
mongodb-org-2.6.3-1.x86_64
mongodb-org-mongos-2.6.3-1.x86_64
mongodb-org-shell-2.6.3-1.x86_64
mongodb-org-server-2.6.3-1.x86_64
mongodb-org-tools-2.6.3-1.x86_64
3,自定义db和log存放路径
新建存放DB目录
#mkdir -p /data/mongodb/log
设置属主和属组,安装mongodb后会新建一个账号mongodb
#chown -R mongod:mongod /data/mongodb
#egrep 'dbpath|logpath' /etc/mongod.conf
logpath=/data/mongodb/log/mongod.log
dbpath=/data/mongodb
4,设置日志大小,并发连接数
oplogSize=4096
maxConns=3280
总配置文件如下:
# grep -Ev '^#|^$' /etc/mongod.conf
logpath=/data/mongodb/log/mongod.log
logappend=true
fork=true
port=27017
dbpath=/data/mongodb
pidfilepath=/var/run/mongodb/mongod.pid
oplogSize=4096
maxConns=3280
directoryperdb=true
nojournal=true
replSet=rpls
启动mongod
# service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [ OK ]
查看文件
# ls /data/mongodb/
journal local.0 local.ns mongod.lock _tmp
查看端口是否开启
# ss -anp |grep mongod
LISTEN 0 128 127.0.0.1:27017 *:* users:(("mongod",9295,9))
5,设置开机自动启动mongodb
#chkconfig mongod on
6,Mongodb启动命令mongod参数说明
mongod的主要参数有:
基本配置
--------------------------------------------------------------------------------
--quiet # 安静输出
--port arg # 指定服务端口号,默认端口27017
--bind_ip arg # 绑定服务IP,若绑定127.0.0.1,则只能本机访问,不指定默认本地所有IP
--logpath arg # 指定MongoDB日志文件,注意是指定文件不是目录
--logappend # 使用追加的方式写日志
--pidfilepath arg # PID File 的完整路径,如果没有设置,则没有PID文件
--keyFile arg # 集群的私钥的完整路径,只对于Replica Set 架构有效
--unixSocketPrefix arg # UNIX域套接字替代目录,(默认为 /tmp)
--fork # 以守护进程的方式运行MongoDB,创建服务器进程
--auth # 启用验证
--cpu # 定期显示CPU的CPU利用率和iowait
--dbpath arg # 指定数据库路径
--diaglog arg # diaglog选项 0=off 1=W 2=R 3=both 7=W+some reads
--directoryperdb # 设置每个数据库将被保存在一个单独的目录
--journal # 启用日志选项,MongoDB的数据操作将会写入到journal文件夹的文件里
--journalOptions arg # 启用日志诊断选项
--ipv6 # 启用IPv6选项
--jsonp # 允许JSONP形式通过HTTP访问(有安全影响)
--maxConns arg # 最大同时连接数 默认2000
--noauth # 不启用验证
--nohttpinterface # 关闭http接口,默认关闭27018端口访问
--noprealloc # 禁用数据文件预分配(往往影响性能)
--noscripting # 禁用脚本引擎
--notablescan # 不允许表扫描
--nounixsocket # 禁用Unix套接字监听
--nssize arg (=16) # 设置信数据库.ns文件大小(MB)
--objcheck # 在收到客户数据,检查的有效性,
--profile arg # 档案参数 0=off 1=slow, 2=all
--quota # 限制每个数据库的文件数,设置默认为8
--quotaFiles arg # number of files allower per db, requires --quota
--rest # 开启简单的rest API
--repair # 修复所有数据库run repair on all dbs
--repairpath arg # 修复库生成的文件的目录,默认为目录名称dbpath
--slowms arg (=100) # value of slow for profile and console log
--smallfiles # 使用较小的默认文件
--syncdelay arg (=60) # 数据写入磁盘的时间秒数(0=never,不推荐)
--sysinfo # 打印一些诊断系统信息
--upgrade # 如果需要升级数据库
* Replicaton 参数
--------------------------------------------------------------------------------
--fastsync # 从一个dbpath里启用从库复制服务,该dbpath的数据库是主库的快照,可用于快速启用同步
--autoresync # 如果从库与主库同步数据差得多,自动重新同步,
--oplogSize arg # 设置oplog的大小(MB)
* 主/从参数
--------------------------------------------------------------------------------
--master # 主库模式
--slave # 从库模式
--source arg # 从库 端口号
--only arg # 指定单一的数据库复制
--slavedelay arg # 设置从库同步主库的延迟时间
* Replica set(副本集)选项:
--------------------------------------------------------------------------------
--replSet arg # 设置副本集名称
* Sharding(分片)选项
--------------------------------------------------------------------------------
--configsvr # 声明这是一个集群的config服务,默认端口27019,默认目录/data/configdb
--shardsvr # 声明这是一个集群的分片,默认端口27018
--noMoveParanoia # 关闭偏执为moveChunk数据保存
服务器配置:/etc/mongod.conf
# mongo.conf#where to loglogpath=/var/log/mongo/mongod.loglogappend=true#以追加方式写入日志# fork and run in backgroundfork =true#port = 27017 #端口dbpath=/var/lib/mongo #数据库文件保存位置directoryperdb=true# Enables periodic logging of CPU utilization and I/O wait#启用定期记录CPU利用率和 I/O 等待#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# 设置oplog记录等级# Set oplogging level where n is# 0=off (default)# 1=W# 2=R# 3=both# 7=W+some reads#oplog = 0# Diagnostic/debugging option 动态调试项#nocursors = true# Ignore query hints 忽略查询提示#nohints = true# 禁用http界面,默认为localhost:28017# Disable the HTTP interface (Defaults to localhost:27018).这个端口号写的是错的#nohttpinterface = 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# 为新数据库指定.ns文件的大小,单位:MB# Specify .ns file size for new databases.# nssize = <size># Accout token for Mongo monitoring server.#mms-token = <token># mongo监控服务器的名称# Server name for Mongo monitoring server.#mms-name = <server-name># mongo监控服务器的ping 间隔# Ping interval for Mongo monitoring server.#mms-interval = <seconds># Replication Options 复制选项# in replicated mongo databases, specify here whether this is a slave or master 在复制中,指定当前是从属关系#slave = true#source = master.example.com# Slave only: specify a single database to replicate#only = master.example.com# or#master = true#source = slave.example.com
php是世界上最好的编程语言,没有之一


浙公网安备 33010602011771号