搭建蚂蚁笔记

Author Avatar
doubledna 2017 年 04 月 06 日

<h2 id="2">Leanote</h2>
下面介绍一下本文的猪脚 :Leanote (蚂蚁笔记)

官网 : https://leanote.com

开源 https://github.com/leanote

Leanote 也提供了云笔记服务,有免费 也有付费的。

就免费而言没有有道云笔记实在点儿(个人观点)!

当然本文主要不是介绍 Leanote 提供的服务,而是开源项目。

 
<h2 id="3"> 开源项目 </h2>
Leanote, 不只是笔记!

特性

  • 高效笔记:Leanote 有易操作的界面, 包含一款富文本编辑器和 Markdown 编辑器,让您的笔记记录更轻松和高效。对高阶用户,我们还提供VimEmacs 编辑模式,助推你的写作速度更上层楼。
  • 知识管理: Leanote 灵活而强大的“笔记本 - 笔记 - 标签”系统,让它成为你个人知识管理的利器。
  • 分享: 你可以通过 Leanote 同好友分享知识、想法和经历, 邀请好友加入你的笔记簿,通过云端交流信息。
  • 协作: Leanote 协助你与同事之间相互协作,激荡新思路,随时随地头脑风暴。
  • 博客: Leanote 也可以作为你的个人博客, 把你的知识传播的更远!

其它特性

  • 支持 Markdown 编辑
  • 写作模式
  • VimEmacs 编辑模式
  • 支持 PDF 导出
  • 支持批量操作
  • 博客自定义主题, 实现高度定制化

 
<div class="alert alert-success">Leanote 云笔记产品包括: Leanote Web & Server(即本仓库), 桌面客户端, IOS, android. 4 端全部开源!</div>
 

 
<h2 id="4"> 部署指南 </h2>
Leanote 提供非常详细的 安装说明介绍。

更多内容: https://github.com/leanote/leanote/wiki

 

这里说一下 二进制安装。(推荐此方法)

安装步骤:

  1. 下载 leanote 二进制版。
  2. 安装 mongodb
  3. 导入初始数据。
  4. 配置 leanote
  5. 运行 leanote

 

1. 下载 leanote 二进制版

由此处下载 leanote 最新二进制版

假设将文件下载到 /home/user1 目录下, 解压文件从而在 /home/user1 目录下生成 leanote目录:
<div id="crayon-58e648f5cff15883516768" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff15883516768-1">1</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff15883516768-2">2</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff15883516768-1" class="crayon-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">cd</span> <span class="crayon-o">/</span><span class="crayon-v">home</span><span class="crayon-o">/</span><span class="crayon-i">user1</span></div> <div id="crayon-58e648f5cff15883516768-2" class="crayon-line crayon-striped-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">tar</span> <span class="crayon-o">-</span><span class="crayon-e">xzvf </span><span class="crayon-v">leanote</span><span class="crayon-o">-</span><span class="crayon-v">darwin</span><span class="crayon-o">-</span><span class="crayon-v">amd64</span><span class="crayon-sy">.</span><span class="crayon-v">v2</span><span class="crayon-sy">.</span><span class="crayon-cn">0.bin.tar.gz</span></div> </div>

</div>
</div>
2. 安装 mongodb

mongodb 官网 下载相应系统的最新版安装包,或者从以下链接下载旧版本:

下载到 /home/user1下, 直接解压即可:
<div id="crayon-58e648f5cff24027880629" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff24027880629-1">1</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff24027880629-2">2</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff24027880629-1" class="crayon-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">cd</span> <span class="crayon-o">/</span><span class="crayon-v">home</span><span class="crayon-o">/</span><span class="crayon-i">user1</span></div> <div id="crayon-58e648f5cff24027880629-2" class="crayon-line crayon-striped-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">tar</span> <span class="crayon-o">-</span><span class="crayon-e">xzvf </span><span class="crayon-v">mongodb</span><span class="crayon-o">-</span><span class="crayon-v">linux</span><span class="crayon-o">-</span><span class="crayon-v">x86_64</span><span class="crayon-o">-</span><span class="crayon-cn">3.0.1.tgz</span><span class="crayon-o">/</span></div> </div>

</div>
</div>
为了快速使用mongodb命令, 可以配置环境变量。编辑 ~/.profile/etc/profile 文件, 将mongodb/bin路径加入即可:
<div id="crayon-58e648f5cff2a090046269" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff2a090046269-1">1</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff2a090046269-1" class="crayon-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-e">sudo </span><span class="crayon-v">vim</span> <span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">profile</span></div> </div>

</div>
</div>
此处实例使用了vim文本编辑器,你可以使用自己熟悉的编辑器。

/etc/profile中添加以下行,注意把用户名(user1)和相应的文件目录名(mongodb-linux-x86_64-3.0.1)替换成自己系统中的名称:
<div id="crayon-58e648f5cff2f977140922" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff2f977140922-1">1</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff2f977140922-1" class="crayon-line"><span class="crayon-e">export </span><span class="crayon-v">PATH</span><span class="crayon-o">=</span><span class="crayon-sy">$</span><span class="crayon-v">PATH</span><span class="crayon-o">:</span><span class="crayon-o">/</span><span class="crayon-v">home</span><span class="crayon-o">/</span><span class="crayon-v">user1</span><span class="crayon-o">/</span><span class="crayon-v">mongodb</span><span class="crayon-o">-</span><span class="crayon-v">linux</span><span class="crayon-o">-</span><span class="crayon-v">x86_64</span><span class="crayon-o">-</span><span class="crayon-cn">3.0.1</span><span class="crayon-o">/</span><span class="crayon-v">bin</span></div> </div>

</div>
</div>
保存修改后,在终端运行以下命令使环境变量生效:
<div id="crayon-58e648f5cff34952893059" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff34952893059-1">1</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff34952893059-1" class="crayon-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">source</span> <span class="crayon-o">/</span><span class="crayon-v">etc</span><span class="crayon-o">/</span><span class="crayon-v">profile</span></div> </div>

</div>
</div>
3. 测试mongodb安装

先在/home/user1下新建一个目录data存放mongodb数据:
<div id="crayon-58e648f5cff39516078690" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff39516078690-1">1</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff39516078690-1" class="crayon-line"><span class="crayon-v">mkdir</span> <span class="crayon-o">/</span><span class="crayon-v">home</span><span class="crayon-o">/</span><span class="crayon-v">user1</span><span class="crayon-o">/</span><span class="crayon-v">data</span></div> </div>

</div>
</div>
用以下命令启动mongod:
<div id="crayon-58e648f5cff3e530767439" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff3e530767439-1">1</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff3e530767439-1" class="crayon-line"><span class="crayon-v">mongod</span> <span class="crayon-o">--</span><span class="crayon-v">dbpath</span> <span class="crayon-o">/</span><span class="crayon-v">home</span><span class="crayon-o">/</span><span class="crayon-v">user1</span><span class="crayon-o">/</span><span class="crayon-v">data</span></div> </div>

</div>
</div>
这时mongod已经启动,重新打开一个终端, 键入mongo进入交互程序:
<div id="crayon-58e648f5cff43594068670" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff43594068670-1">1</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff43594068670-2">2</div> <div class="crayon-num" data-line="crayon-58e648f5cff43594068670-3">3</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff43594068670-1" class="crayon-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">mongo</span></div> <div id="crayon-58e648f5cff43594068670-2" class="crayon-line crayon-striped-line"><span class="crayon-o">></span> <span class="crayon-e">show </span><span class="crayon-i">dbs</span></div> <div id="crayon-58e648f5cff43594068670-3" class="crayon-line"><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span> 数据库列表 </div> </div>

</div>
</div>
mongodb安装到此为止, 下面为mongodb导入leanote初始数据。


4. 导入初始数据

leanote初始数据存放在 /home/user1/leanote/mongodb_backup/leanote_install_data中。

打开终端, 输入以下命令导入数据。
<div id="crayon-58e648f5cff48631773873" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff48631773873-1">1</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff48631773873-1" class="crayon-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">mongorestore</span> <span class="crayon-o">-</span><span class="crayon-i">h</span> <span class="crayon-v">localhost</span> <span class="crayon-o">-</span><span class="crayon-i">d</span> <span class="crayon-v">leanote</span> <span class="crayon-o">--</span><span class="crayon-v">dir</span> <span class="crayon-o">/</span><span class="crayon-v">home</span><span class="crayon-o">/</span><span class="crayon-v">user1</span><span class="crayon-o">/</span><span class="crayon-v">leanote</span><span class="crayon-o">/</span><span class="crayon-v">mongodb_backup</span><span class="crayon-o">/</span><span class="crayon-v">leanote_install_data</span><span class="crayon-o">/</span></div> </div>

</div>
</div>
现在在mongodb中已经新建了leanote数据库, 可用命令查看下leanote有多少张”表”:
<div id="crayon-58e648f5cff60868055485" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff60868055485-1">1</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff60868055485-2">2</div> <div class="crayon-num" data-line="crayon-58e648f5cff60868055485-3">3</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff60868055485-4">4</div> <div class="crayon-num" data-line="crayon-58e648f5cff60868055485-5">5</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff60868055485-6">6</div> <div class="crayon-num" data-line="crayon-58e648f5cff60868055485-7">7</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff60868055485-8">8</div> <div class="crayon-num" data-line="crayon-58e648f5cff60868055485-9">9</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff60868055485-10">10</div> <div class="crayon-num" data-line="crayon-58e648f5cff60868055485-11">11</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff60868055485-12">12</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff60868055485-1" class="crayon-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">mongo</span></div> <div id="crayon-58e648f5cff60868055485-2" class="crayon-line crayon-striped-line"><span class="crayon-o">></span> <span class="crayon-e">show </span><span class="crayon-v">dbs</span> <span class="crayon-p"># 查看数据库 </span></div> <div id="crayon-58e648f5cff60868055485-3" class="crayon-line"><span class="crayon-i">leanote</span> <span class="crayon-cn">0.203125GB</span></div> <div id="crayon-58e648f5cff60868055485-4" class="crayon-line crayon-striped-line"><span class="crayon-i">local</span><span class="crayon-h">   </span><span class="crayon-cn">0.078125GB</span></div> <div id="crayon-58e648f5cff60868055485-5" class="crayon-line"><span class="crayon-o">></span> <span class="crayon-st">use</span> <span class="crayon-v">leanote</span> <span class="crayon-p"># 切换到 leanote</span></div> <div id="crayon-58e648f5cff60868055485-6" class="crayon-line crayon-striped-line"><span class="crayon-e">switched </span><span class="crayon-st">to</span> <span class="crayon-e">db </span><span class="crayon-v">leanote</span></div> <div id="crayon-58e648f5cff60868055485-7" class="crayon-line"><span class="crayon-o">></span> <span class="crayon-e">show </span><span class="crayon-v">collections</span> <span class="crayon-p"># 查看表 </span></div> <div id="crayon-58e648f5cff60868055485-8" class="crayon-line crayon-striped-line"><span class="crayon-e">files</span></div> <div id="crayon-58e648f5cff60868055485-9" class="crayon-line"><span class="crayon-e">has_share_notes</span></div> <div id="crayon-58e648f5cff60868055485-10" class="crayon-line crayon-striped-line"><span class="crayon-e">note_content_histories</span></div> <div id="crayon-58e648f5cff60868055485-11" class="crayon-line"><span class="crayon-v">note</span><span class="crayon-sy">_</span>contents</div> <div id="crayon-58e648f5cff60868055485-12" class="crayon-line crayon-striped-line"><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span></div> </div>

</div>
</div>
初始数据的users表中已有 2 个用户:
<div id="crayon-58e648f5cff68983117168" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff68983117168-1">1</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff68983117168-2">2</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff68983117168-1" class="crayon-line"><span class="crayon-e">user1 </span><span class="crayon-v">username</span><span class="crayon-o">:</span> <span class="crayon-v">admin</span><span class="crayon-sy">,</span> <span class="crayon-v">password</span><span class="crayon-o">:</span> <span class="crayon-e">abc123</span> <span class="crayon-sy">(</span> 管理员 <span class="crayon-sy">,</span> 只有该用户才有权管理后台 <span class="crayon-sy">,</span> 请及时修改密码 <span class="crayon-sy">)</span></div> <div id="crayon-58e648f5cff68983117168-2" class="crayon-line crayon-striped-line"><span class="crayon-e">user2 </span><span class="crayon-v">username</span><span class="crayon-o">:</span> <span class="crayon-v">demo</span><span class="crayon-sy">@</span><span class="crayon-v">leanote</span><span class="crayon-sy">.</span><span class="crayon-v">com</span><span class="crayon-sy">,</span> <span class="crayon-v">password</span><span class="crayon-o">:</span> <span class="crayon-v">demo</span><span class="crayon-sy">@</span><span class="crayon-v">leanote</span><span class="crayon-sy">.</span><span class="crayon-e">com</span> <span class="crayon-sy">(</span> 仅供体验使用 <span class="crayon-sy">)</span></div> </div>

</div>
</div>


5. 配置leanote

leanote的配置存储在文件 conf/app.conf 中。

请务必修改app.secret一项, 在若干个随机位置处,将字符修改成一个其他的值, 否则会有安全隐患!

其它的配置可暂时保持不变, 若需要配置数据库信息, 请参照 leanote 问题汇总


6. 运行leanote

注意: 在此之前请确保mongodb已在运行!

新开一个窗口, 运行:( 这里可以将 run.sh 设置成后台程序,设置方法:1. chmod +x run.sh,    2. nohup ./run.sh &
<div id="crayon-58e648f5cff6e065499270" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff6e065499270-1">1</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff6e065499270-2">2</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff6e065499270-1" class="crayon-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-v">cd</span> <span class="crayon-o">/</span><span class="crayon-v">home</span><span class="crayon-o">/</span><span class="crayon-v">user1</span><span class="crayon-o">/</span><span class="crayon-v">leanote</span><span class="crayon-o">/</span><span class="crayon-i">bin</span></div> <div id="crayon-58e648f5cff6e065499270-2" class="crayon-line crayon-striped-line"><span class="crayon-sy">$</span><span class="crayon-o">></span> <span class="crayon-e">bash </span><span class="crayon-v">run</span><span class="crayon-sy">.</span><span class="crayon-v">sh</span></div> </div>

</div>
</div>
最后出现以下信息证明运行成功:
<div id="crayon-58e648f5cff73672490855" class="crayon-syntax crayon-theme-github crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover disable-anim">
<div class="crayon-plain-wrap"></div>
<div class="crayon-main">

<div class="crayon-nums-content"> <div class="crayon-num" data-line="crayon-58e648f5cff73672490855-1">1</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff73672490855-2">2</div> <div class="crayon-num" data-line="crayon-58e648f5cff73672490855-3">3</div> <div class="crayon-num crayon-striped-num" data-line="crayon-58e648f5cff73672490855-4">4</div> </div> <div class="crayon-pre"> <div id="crayon-58e648f5cff73672490855-1" class="crayon-line"><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span></div> <div id="crayon-58e648f5cff73672490855-2" class="crayon-line crayon-striped-line"><span class="crayon-i">TRACE</span> <span class="crayon-cn">2013</span><span class="crayon-o">/</span><span class="crayon-cn">06</span><span class="crayon-o">/</span><span class="crayon-cn">06</span> <span class="crayon-cn">15</span><span class="crayon-o">:</span><span class="crayon-cn">01</span><span class="crayon-o">:</span><span class="crayon-cn">27</span> <span class="crayon-v">watcher</span><span class="crayon-sy">.</span><span class="crayon-v">go</span><span class="crayon-o">:</span><span class="crayon-cn">72</span><span class="crayon-o">:</span> <span class="crayon-v">Watching</span><span class="crayon-o">:</span> <span class="crayon-o">/</span><span class="crayon-v">home</span><span class="crayon-o">/</span><span class="crayon-v">life</span><span class="crayon-o">/</span><span class="crayon-v">leanote</span><span class="crayon-o">/</span><span class="crayon-v">bin</span><span class="crayon-o">/</span><span class="crayon-v">src</span><span class="crayon-o">/</span><span class="crayon-v">github</span><span class="crayon-sy">.</span><span class="crayon-v">com</span><span class="crayon-o">/</span><span class="crayon-v">leanote</span><span class="crayon-o">/</span><span class="crayon-v">leanote</span><span class="crayon-o">/</span><span class="crayon-v">conf</span><span class="crayon-o">/</span><span class="crayon-e">routes</span></div> <div id="crayon-58e648f5cff73672490855-3" class="crayon-line"><span class="crayon-e">Go </span><span class="crayon-st">to</span> <span class="crayon-o">/</span><span class="crayon-sy">@</span><span class="crayon-e">tests </span><span class="crayon-st">to</span> <span class="crayon-e">run </span><span class="crayon-e">the </span><span class="crayon-v">tests</span><span class="crayon-sy">.</span></div> <div id="crayon-58e648f5cff73672490855-4" class="crayon-line crayon-striped-line"><span class="crayon-e">Listening </span><span class="crayon-v">on</span> <span class="crayon-o">:</span><span class="crayon-cn">9000...</span></div> </div>

</div>
</div>
恭喜你, 打开浏览器输入: http://ip:9000 体验leanote吧!

!!!重点:如何让 mongo 后台运行

mongodb设置后台运行
我们要在mongodb下面创建data目录和logs目录,用于存放data和logs。
设置好了之后,我们通常通过
mongod --dbpath /usr/local/mongo/data

让mongodb启动。
但是我们关闭shell,mongodb就停止运行了。如果想在后台运行,启动时只需添加 --fork函数即可。可以在日志路径后面添加--logappend,防止日志被删除。
代码如下:
mongod --fork --dbpath=/usr/local/mongodb/data --logpath=/usr/local/mongodb/logs/mongodb2.log --logappend
这样,你关闭shell,在打开shell,照常可以允许mongo了!
mongodb设置开机启动。
当我们把服务器关闭,重启之后,发现mongodb又停止了,有没有开机就启动的方法呢?我们把上面代码放到/etc/rc.local,中,就可以了。
具体操作步骤:
vim  /etc/rc.local

添加上面启动代码:
/usr/local/mongodb/bin/mongod  --fork --dbpath=/usr/local/mongodb/data  --logpath=/usr/local/mongodb/logs/mongodb2.log  --logappend

下次重启就可以直接运行mongodb了!
关于linux的rc.local也是一个重点,我下节课给大家讲讲!具体可以看http://www.haorooms.com/post/linux_path_commond
关闭mongodb
有开启就有关闭,上面方法会永久开启mongodb,那么如何关闭其运行呢?
1、普通命令
$ ./mongod
> use admin
> db.shutdownServer()

2、如果没有up-to-date 从Mongodb且你想强制关闭服务,可以通过添加force:true;命令如下
> db.adminCommand({shutdown : 1, force : true})
> //or
> db.shutdownServer({force : true})

3、指定特定超时时间的关闭服务器,命令同上,另外加上一个timeoutsec:参数
> db.adminCommand(shutdown : 1, force : true, timeoutsec : 5)
> //or
> db.shutdownServer({force : true, timeoutsec : 5})