centos下安装mongodb

centos下安装mongodb

1.进入linux 服务器

2.进入/usr/local/下创建mongodb 文件

centos下安装mongodb

3.centos7下载mongodb文件

 wget  https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.9.tgz

centos下安装mongodb

4.解压文件

  tar -zxvf mongodb-linux-x86_64-rhel70-4.0.9.tgz

5.将文件拷贝到指定目录

 mv mongodb-linux-x86_64-rhel70-4.0.9/*  /usr/local/mongodb

6.在mongodb 下创建logs,data,conf 文件夹

centos下安装mongodb

7.在logs下创建mongodb.log

touch mongodb.conf

8.在conf下创建mongodb.conf,配置文档目录

centos下安装mongodb

9.添加环境变量

进入bin/etc/中 添加环境变量(如果编辑profile是吧,可以打开 ls -a 查看隐藏文件,删除.profile.swp这样的文件)

centos下安装mongodb

centos下安装mongodb

centos下安装mongodb

10.需要设置生效

centos下安装mongodb

11.启动mongodb服务

centos下安装mongodb

12.链接mongodb数据库

centos下安装mongodb

13.关闭 db.shutdownServer(),或者killall mongod

14.mongodb 

cd  /etc/init.d

MongoDB设置为系统服务并且设置开机启动

centos下安装mongodb

#!/bin/sh
#
#chkconfig: 2345 80 90
#description: mongodb

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi

start() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf
}

stop() {
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/bin/mongodb.conf --shutdown
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac

将代码放入mongod中

chmod –R a+x mongod 设置执行权限

chkconfig --add mongod #加入系统服务

chkconfig mongodb on #开机启动

centos下安装mongodb

shutdown -r重启服务器

启动mongodb service mongod start

service mongod stop 关闭

验证是否启动 lsof -i :28001

报错:

centos下安装mongodb

    停止mongodb 运行重新运行

centos下安装mongodb

     systemctl daemon-reload