一、mongodb下载

官方下载地址:https://www.mongodb.com/download-center#community

mongodb 3.4单实例安装与备

没有yueyu的用户可能下载比较缓慢,请自行解决

二、环境配置

测试系统centos6.8 ip地址:192.168.1.197

1、关闭SELinux

  vim /etc/selinux/config 

   SELINUX=disabled 


setenforce 0  

2.关闭防火墙

  service iptables stop

3、增加用户和组

groupadd mongodb  &&  useradd -g mongodb mongodb

4、上传二进制包到/opt下解压并授权

  cd /opt && tar -xf mongodb-linux-x86_64-rhel62-3.4.5.tgz

5、创建软连接

  ln -s /opt/mongodb-linux-x86_64-rhel62-3.4.5  /usr/local/mongodb

6、更改属性

 chown -R mongodb:mongodb /opt/mongodb-linux-x86_64-rhel62-3.4.5

 chown -R mongodb:mongodb  /usr/local/mongodb

7、配置环境变量


   echo 'PATH=/usr/local/mongodb/bin:$PATH' >>/etc/profile

   source /etc/profile

8、创建相关目录

mkdir -p /data/mongo/{db,log,tmp}

mkdir -p /etc/mongodb

9、创建mongodb配置文件

vim /etc/mongodb/mongo.conf


storage:

  dbPath: /data/mongo/db

  journal:

    enabled: true

  engine: wiredTiger

systemLog:

  destination: file

  logAppend: true

  path: /data/mongo/log/mongod.log

processManagement:

  fork: true  # fork and run in background

  pidFilePath: /data/mongo/tmp/mongod.pid

net:

  port: 27017

  bindIp: 192.168.1.197,127.0.0.1

security:

  authorization: enabled

10、授权

chown -R mongodb:mongodb /data/mongo

chown -R mongodb:mongodb /etc/mongodb

11、启动mongodb

su - mongodb 

mongod --config /etc/mongodb/mongo.conf

#ps aux |grep mongo

mongodb      1649  0.6  1.1 1015552 46780 ?       SLl  08:45   0:55 /usr/local/mongodb/bin/mongod --config /etc/mongodb/mongo.conf

mongodb    30100  0.0  0.0 103256   848 pts/0    S+   11:08   0:00 grep mongo