mongodb的安装

日常笔记

</div><!--end: blogTitle 博客的标题和副标题 -->
<div id="navigator">
	<div class="blogStats">
		
		<div id="blog_stats">

随笔- 14 
文章- 1 
评论- 0 

	</div><!--end: blogStats -->
</div><!--end: navigator 博客导航栏 -->
    <div id="post_detail">

Linux下Mongodb安装和启动配置

 

1.下载安装包

wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.2.tgz

下载完成后解压缩压缩包

tar zxf mongodb-linux-i686-1.8.2.tgz
2. 安装准备
将mongodb移动到/usr/local/server/mongdb文件夹
mv mongodb-linux-i686-1.8.2 /usr/local/mongodb

创建数据库文件夹与日志文件

mkdir /usr/local/mongodb/data
touch /usr/local/mongodb/logs
3. 设置开机自启动
将mongodb启动项目追加入rc.local保证mongodb在服务器开机时启动
echo "/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data –logpath=/usr/local/mongodb/logs –logappend  --auth -–port=27017" >> /etc/rc.local
4. 启动mongodb
cd到mongodb目录下的bin文件夹启动mongodb
//下面这个是需要权限的登录方式, 用户连接需要用户名和密码
/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend  --auth  --port=27017 --fork

//这个是不需要密码的

/usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs --logappend  --port=27017 --fork
5. 参数解释: --dbpath 数据库路径(数据文件)
 
--logpath 日志文件路径
--master 指定为主机器
--slave 指定为从机器
--source 指定主机器的IP地址
--pologSize 指定日志文件大小不超过64M.因为resync是非常操作量大且耗时,最好通过设置一个足够大的oplogSize来避免resync(默认的 oplog大小是空闲磁盘大小的5%)。
--logappend 日志文件末尾添加
--port 启用端口号
--fork 在后台运行
--only 指定只复制哪一个数据库
--slavedelay 指从复制检测的时间间隔
--auth 是否需要验证权限登录(用户名和密码)

-h [ --help ] show this usage information
–version show version information
-f [ --config ] arg configuration file specifying additional options
–port arg specify port number
–bind_ip arg local ip address to bind listener - all local ips
bound by default
-v [ --verbose ] be more verbose (include multiple times for more
verbosity e.g. -vvvvv)
–dbpath arg (=/data/db/) directory for datafiles 指定数据存放目录
–quiet quieter output 静默模式
–logpath arg file to send all output to instead of stdout 指定日志存放目录
–logappend appnd to logpath instead of over-writing 指定日志是以追加还是以覆盖的方式写入日志文件
–fork fork server process 以创建子进程的方式运行
–cpu periodically show cpu and iowait utilization 周期性的显示cpu和io的使用情况
–noauth run without security 无认证模式运行
–auth run with security 认证模式运行
–objcheck inspect client data for validity on receipt 检查客户端输入数据的有效性检查
–quota enable db quota management 开始数据库配额的管理
–quotaFiles arg number of files allower per db, requires --quota 规定每个数据库允许的文件数
–appsrvpath arg root directory for the babble app server
–nocursors diagnostic/debugging option 调试诊断选项
–nohints ignore query hints 忽略查询命中率
–nohttpinterface disable http interface 关闭http接口,默认是28017
–noscripting disable scripting engine 关闭脚本引擎
–noprealloc disable data file preallocation 关闭数据库文件大小预分配
–smallfiles use a smaller default file size 使用较小的默认文件大小
–nssize arg (=16) .ns file size (in MB) for new databases 新数据库ns文件的默认大小
–diaglog arg 0=off 1=W 2=R 3=both 7=W+some reads 提供的方式,是只读,只写,还是读写都行,还是主要写+部分的读模式
–sysinfo print some diagnostic system information 打印系统诊断信息
–upgrade upgrade db if needed 如果需要就更新数据库
–repair run repair on all dbs 修复所有的数据库
–notablescan do not allow table scans 不运行表扫描
–syncdelay arg (=60) seconds between disk syncs (0 for never) 系统同步刷新磁盘的时间,默认是60s

Replication options:
–master master mode 主复制模式
–slave slave mode 从复制模式
–source arg when slave: specify master as <server:port> 当为从时,指定主的地址和端口
–only arg when slave: specify a single database to replicate 当为从时,指定需要从主复制的单一库
–pairwith arg address of server to pair with
–arbiter arg address of arbiter server 仲裁服务器,在主主中和pair中用到
–autoresync automatically resync if slave data is stale 自动同步从的数据
–oplogSize arg size limit (in MB) for op log 指定操作日志的大小
–opIdMem arg size limit (in bytes) for in memory storage of op ids指定存储操作日志的内存大小

Sharding options:
–configsvr declare this is a config db of a cluster 指定shard中的配置服务器
–shardsvr declare this is a shard db of a cluster 指定shard服务器

 
6. 进入数据库的CLI管理界面
cd到mongodb目录下的bin文件夹,执行命令./mongo
运行如下:
[root@namenode mongodb]# ./bin/mongo
MongoDB shell version: 1.8.2
connecting to: test
> use test;
switched to db test
 
7.  MongoDB配置
  a 通过上面的MongoDB安装,我们已经将其安装成功并且启动,但是发现启动太过于麻烦,所以需要我们自己给MongoDB配置配置文件,因MongoDB开发者没有配置样例,所以需要我们自己去创建并且写入内容
  b 在和bin目录同级的目录下面建一个mongo.conf文件(编码格式为utf8无bom格式,否则会报错),作为mongodb的配置文件。[ps:在启动的时候会用到]
    ---mongo.conf文件内容如下:
     vim mongo.conf
  c 打开编辑器之后将如下图所示的内容写入到编辑器中,保证是正确的,如果你的安装地址和我的不一致,则需要自己修改

#数据库数据存放目录
dbpath=/usr/local/mongodb/data
#数据库日志存放目录
logpath=/usr/local/mongodb/logs/mongodb.log
#以追加的方式记录日志
logappend = true
#端口号 默认为27017
port=27017
#以后台方式运行进程
fork=true
#开启用户认证
auth=true
#关闭http接口,默认关闭http端口访问
#nohttpinterface=true
#mongodb所绑定的ip地址
#bind_ip = 127.0.0.1
#启用日志文件,默认启用
journal=true
#这个选项可以过滤掉一些无用的日志信息,若需要调试使用请设置为false
quiet=true

 
 

其他配置参数含义

 

--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数据保存
 

启动mongod
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongo.conf
报错:
about to fork child process, waiting until server is ready for connections.
forked process: 2340
ERROR: child process failed, exited with error number 1


cd data
删除mongo.lock文件
rm mongod.lock
mongod --repair --dbpath=/usr/local/mongodb/data
完成修复后就可以启动mongodb的客户端了!

启动客户端:
/usr/local/mongodb/bin/mongo



分类: linux
标签: linux mongodb
0
0
« 上一篇: CentOS之7与6的区别
» 下一篇: mysql 执行show databases没有mysql库
	</div>
	<div class="postDesc">posted @ <span id="post-date">2018-05-02 11:11</span> <a href="https://www.cnblogs.com/mnote/">ML。</a> 阅读(<span id="post_view_count">3427</span>) 评论(<span id="post_comment_count">0</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=8979299" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(8979299);return false;">收藏</a></div>
</div>
<script type="text/javascript">var allowComments=true,cb_blogId=356001,cb_entryId=8979299,cb_blogApp=currentBlogApp,cb_blogUserGuid='d8d32db0-91eb-473c-e01c-08d49c350eca',cb_entryCreatedDate='2018/5/2 11:11:00';loadViewCount(cb_entryId);var cb_postType=1;var isMarkdown=false;</script>
</div><!--end: forFlow -->
</div><!--end: mainContent 主体内容容器-->

<div id="sideBar">
	<div id="sideBarMain">

公告

昵称: ML。
园龄: 2年1个月
粉丝: 0
关注: 0
+加关注
		<div id="calendar"><div id="blog-calendar" style=""><table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="Calendar">
<tbody><tr><td colspan="7"><table class="CalTitle" cellspacing="0">
	<tbody><tr><td class="CalNextPrev"><a href="javascript:void(0);" onclick="loadBlogCalendar('2019/06/01');return false;">&lt;</a></td><td align="center">2019年7月</td><td class="CalNextPrev" align="right"><a href="javascript:void(0);" onclick="loadBlogCalendar('2019/08/01');return false;">&gt;</a></td></tr>
</tbody></table></td></tr><tr><th class="CalDayHeader" align="center" abbr="日" scope="col">日</th><th class="CalDayHeader" align="center" abbr="一" scope="col">一</th><th class="CalDayHeader" align="center" abbr="二" scope="col">二</th><th class="CalDayHeader" align="center" abbr="三" scope="col">三</th><th class="CalDayHeader" align="center" abbr="四" scope="col">四</th><th class="CalDayHeader" align="center" abbr="五" scope="col">五</th><th class="CalDayHeader" align="center" abbr="六" scope="col">六</th></tr><tr><td class="CalOtherMonthDay" align="center">30</td><td align="center">1</td><td align="center">2</td><td class="CalTodayDay" align="center">3</td><td align="center">4</td><td align="center">5</td><td class="CalWeekendDay" align="center">6</td></tr><tr><td class="CalWeekendDay" align="center">7</td><td align="center">8</td><td align="center">9</td><td align="center">10</td><td align="center">11</td><td align="center">12</td><td class="CalWeekendDay" align="center">13</td></tr><tr><td class="CalWeekendDay" align="center">14</td><td align="center">15</td><td align="center">16</td><td align="center">17</td><td align="center">18</td><td align="center">19</td><td class="CalWeekendDay" align="center">20</td></tr><tr><td class="CalWeekendDay" align="center">21</td><td align="center">22</td><td align="center">23</td><td align="center">24</td><td align="center">25</td><td align="center">26</td><td class="CalWeekendDay" align="center">27</td></tr><tr><td class="CalWeekendDay" align="center">28</td><td align="center">29</td><td align="center">30</td><td align="center">31</td><td class="CalOtherMonthDay" align="center">1</td><td class="CalOtherMonthDay" align="center">2</td><td class="CalOtherMonthDay" align="center">3</td></tr><tr><td class="CalOtherMonthDay" align="center">4</td><td class="CalOtherMonthDay" align="center">5</td><td class="CalOtherMonthDay" align="center">6</td><td class="CalOtherMonthDay" align="center">7</td><td class="CalOtherMonthDay" align="center">8</td><td class="CalOtherMonthDay" align="center">9</td><td class="CalOtherMonthDay" align="center">10</td></tr>
		<div id="leftcontentcontainer">
			<div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block">
    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值