Centos 6.9 部署MongoDB

539 阅读2分钟

下载

直接官网下载相关的安装包,官网: www.mongodb.com/download-ce…

mongodb-server:
  mongodb服务安装包,这个是必须的。
mongodb-shell:
  mongodb命令行工具,想在命令行中登录mongo的话这个也要装。
mongodb-tools:
  这个是数据导出等工具包,方便管理也可装一下。
mongodb-mongos:
  做分片集群会用到的包。

上传

将下载好的rpm文件上传到服务器,这里我下载的是4.2.6版本。

rz

目录规划

日志文件目录

/data/logs/mongodb/mongod.log

数据目录

/data/mongodb/

这个两个目录和文件提前新建好并给好权限,这里我直接给了777

chmod 777 /data/mongodb/
chmod 777 /data/logs/mongodb/

安装

rpm -ivh mongodb-org-server-4.2.6-1.el6.x86_64.rpm
rpm -ivh mongodb-org-shell-4.2.6-1.el6.x86_64.rpm
rpm -ivh mongodb-org-tools-4.2.6-1.el6.x86_64.rpm

这里我把 server、shell、tools三部分一起安装了。

修改配置文件

安装好 server 后会自动生成一个默认的配置文件 /etc/mongod.conf。

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /var/lib/mongo
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /var/run/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

我们按目录规划来改一下配置文件。

vi /etc/mongod.conf
# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /data/logs/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /data/mongodb
  journal:
    enabled: true
#  engine:
#  wiredTiger:

# how the process runs
processManagement:
  fork: true  # fork and run in background
  pidFilePath: /data/mongodb/mongod.pid  # location of pidfile
  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1  # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.


#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options

#auditLog:

主要修改了 path、dbPath、pidFilePath 这三个路径。

启动mongo

service mongod start

启动后我们可以查看进程是否存在。

ps aux | grep mongo
mongod    2124  3.0  0.2 1611016 92284 ?       Sl   08:01   0:02 /usr/bin/mongod -f /etc/mongod.conf
root      2163  0.0  0.0 103312   884 pts/0    S+   08:02   0:00 grep mongo

到这mongodb基本已经完成了,至于密码设置以及配置优化是后话了。
tips

关闭命令
service mongod stop