由于 Ubuntu 中安装 Mongodb 时,默认是保存在系统盘的,而固态硬盘的容量不够,因此,修改 Mongodb 数据仓库的存储路径.

Mongodb 的配置文件:/etc/mongod.conf

# mongod.conf

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

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb  # 默认的数据保存路径
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log  # 默认的日志保存路径

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo

#security:

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

有两种修改方式:

[1] - 方式一:修改 /etc/mongod.conf 文件中的 storage - dbPath 路径位置,如:

storage:
  dbPath: /data/mongodb/dbs  # 默认的数据保存路径
  journal:
    enabled: true
    
systemLog:
  destination: file
  logAppend: true
  path: /data/mongodb/logs/mongod.log  # 默认的日志保存路径

重启 mongodb 服务.

sudo service mongod start

[2] - 方式二:建立软链接的方式

# 停止 mongod
sudo service mongod stop

# 修改数据存储路径
sudo mv /var/lib/mongodb/* /data/mongodb/dbs/
sudo ln -s /data/mongodb/dbs /var/lib/mongodb

# 修改日志存储路径
sudo mv /var/log/mongodb/* /data/mongodb/logs/
sudo ln -s /data/mongodb/logs /var/log/mongodb

# 重启 mongod
sudo service mongod start
# 查看 mongod 状态
sudo service mongod status

如果出现问题可能是文件路径的权限问题,如,修改权限:

sudo chmod -R 777 /data/mongodb/
Last modification:March 9th, 2019 at 04:41 pm