司马海 發表於 2019-11-16 00:55:00

linux安装mongodb

<p><strong>这里是在虚拟机环境下操作</strong></p>
<p><strong>1、<strong>MongoDB官网下载地址&nbsp;&nbsp;&nbsp;&nbsp;https://www.mongodb.com/download-center?jmp=nav#community</strong></strong></p>
<p><strong><strong>2、<strong>下载MongoDB安装包</strong></strong></strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 1、cd /usr/local/</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 2、mkdir mongodb</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 3、cd mongodb/</strong></p>
<p><strong><strong>&nbsp; &nbsp; &nbsp; 4、wget&nbsp;&nbsp;</strong>https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.7.tgz&nbsp; &nbsp; 也可以直接下载源码压缩包</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 5、tar -zxvf&nbsp; mongodb-linux-x86_64-4.0.7.tgz&nbsp; 解压</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 6、cd mongodb-linux-x86_64-4.0.7/</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 7、创建两个目录 存放数据库和日记</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</strong>&nbsp; &nbsp;&nbsp;<strong>1、mkdir -p logs</strong></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<strong>2、mkdir -p datas</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 8、如果需要赋权限&nbsp;&nbsp;chmod&nbsp; 777&nbsp; 路径</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 9、<img src="https://img2018.cnblogs.com/blog/1643692/201903/1643692-20190327142256583-1635260585.png" alt=""></strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 10、创建一个mongodb.conf&nbsp; 直接 vim mongodb.conf</strong></p>
<p><span style="color: rgba(255, 0, 0, 1)"><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;1、dbpath = /usr/local//mongodb/mongodb-linux-x86_64-4.0.7/bin/datas&nbsp; 数据文件</strong></span></p>
<p><span style="color: rgba(255, 0, 0, 1)"><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2、logpath =/usr/local//mongodb/mongodb-linux-x86_64-4.0.7/bin/logs/mongodb.log&nbsp; 日记文件</strong></span></p>
<p><span style="color: rgba(255, 0, 0, 1)"><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3、port = 27017 端口号 默认</strong></span></p>
<p><span style="color: rgba(255, 0, 0, 1)"><strong>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 4、fork = true&nbsp; 后台启动</strong></span></p>
<p><span style="color: rgba(255, 0, 0, 1)"><strong>    5、<code class="language-jsx">bind_ip<span class="token operator">=<span class="token number">0.0<span class="token number">.0<span class="token number">.0&nbsp; #可外网访问</span></span></span></span></code></strong></span></p>
<p><strong>3、<strong>启动 Mongodb 服务器</strong></strong></p>
<p><strong>&nbsp; &nbsp; &nbsp;&nbsp;<img src="https://img2018.cnblogs.com/blog/1643692/201903/1643692-20190327142936198-456118674.png" alt=""></strong></p>
<p><strong><strong>&nbsp; &nbsp; &nbsp; cd bin/ 目录下&nbsp;&nbsp;</strong>&nbsp;1、</strong><strong>./mongod --config mongodb.conf</strong></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<strong>&nbsp;2、./mongod -f mongodb.conf</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp;&nbsp;<img src="https://img2018.cnblogs.com/blog/1643692/201903/1643692-20190327143257678-1796240149.png" alt="">&nbsp; 启动成功</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp;&nbsp;<img src="https://img2018.cnblogs.com/blog/1643692/201903/1643692-20190327143315623-845209160.png" alt="">&nbsp; 可以看到 mongodb的进程</strong></p>
<p><strong>4、关闭服务器</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp; 尽量不要&nbsp; kill -9 进程的 pid 58784&nbsp; &nbsp;数据库直接关闭,数据丢失,数据文件损失,修复数据库(成本高,有风险)</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp;&nbsp;<strong>kill -2 进程的 pid 58784 或者&nbsp;<strong>kill -4 进程的 pid 58784</strong></strong></strong></p>
<p><strong>5、<strong>启动 Mongodb的客户端</strong></strong></p>
<p><strong>&nbsp; &nbsp; &nbsp;<img src="https://img2018.cnblogs.com/blog/1643692/201903/1643692-20190327143549692-1347935564.png" alt=""></strong></p>
<p><strong>&nbsp; &nbsp; 会有一些提示信息&nbsp;&nbsp;echo never &gt;&gt; /sys/kernel/mm/transparent_hugepage/enabled<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo never &gt;&gt; /sys/kernel/mm/transparent_hugepage/defrag</strong></p>
<p><strong>6、测试</strong></p>
<p><strong>&nbsp; &nbsp; &nbsp;<img src="https://img2018.cnblogs.com/blog/1643692/201903/1643692-20190327144059020-1720759819.png" alt=""></strong></p>
<p><strong>&nbsp; &nbsp; 到此就安装完成了!</strong></p>
<p>&nbsp;</p>
<p><strong>转自:https://www.cnblogs.com/gaojingya/p/10607419.html</strong></p><br><br>
来源:https://www.cnblogs.com/tjp40922/p/11870321.html
頁: [1]
查看完整版本: linux安装mongodb