使用官方文档安装

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

创建/var/run/mongodb/目录

mkdir -p /var/run/mongodb/

授权

# mongodb pid 文件目录
sudo chown -R mongodb: /var/run/mongodb/
# mongodb 数据存储目录
sudo chown -R mongodb:  /home/jmal/database/mongodb
sudo chown -R mongodb: /tmp/

配置文件

# mongod.conf

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

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

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

# network interfaces
net:
  port: 27017
  bindIp: 0.0.0.0


# how the process runs
processManagement:
  timeZoneInfo: /usr/share/zoneinfo
  fork: true
  pidFilePath: /var/run/mongodb/mongod.pid
#security:
#  authorization: enabled

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp: