linux安装mongodb

1.下载地址
https://fastdl.MongoDB.org/Linux/mongodb-linux-x86_64-3.4.7.tgz

2.创建目录,并在目录下解压

mkdir /mongodb

/mongodb/mongodb-linux-x86_64-3.4.7

3.配置 etc/profile文件

在最底部加入

export PATH=$PATH:/mongodb/mongodb-linux-x86_64-3.4.7/bin

保存退出,执行

source /etc/profile

4.启动

在/mongodb/mongodb-linux-x86_64-3.4.7下

mkdir data

mkdir log

mkdir conf

在log目录下创建

vim mongod.log

加上启动信息

dbpath = /mongodb/mongodb-linux-x86_64-3.4.7/data

logpath = /mongodb/mongodb-linux-x86_64-3.4.7/log/mongod.log

fork = true

保存退出

5.启动

(1)前台启动

cd /mongodb/mongodb-linux-x86_64-3.4.7/bin

mongod --dbpath ../data

(2)后台启动

mongod -f /mongodb/mongodb-linux-x86_64-3.4.7/conf/mongod.conf

6.设置开机自启

首先开启root登陆用户

1. vim /etc/gdm/custom.conf

查看[daemon]下有没有以下两行。没有自己加上

AutomaticLoginEnable=True

AutomaticLogin=root

2.然后向etc/rc.local最后一行添加以下命令

echo "/mongodb/mongodb-linux-x86_64-3.4.7/bin/mongod -f mongodb/mongodb-linux-x86_64-3.4.7/conf/mongod.conf">>/etc/rc.local

3.增加权限

chmod +x /etc/rc.d/rc.local

4.关闭mongodb不要使用kill -9

可以用:killall mongod

或者

kill -15 进程号

posted @ 2017-08-23 17:20  二班长  阅读(174)  评论(0编辑  收藏  举报