目录

MongoDB的安装

# 环境

linux centos 7.x

# 步骤

# repo

注意 截止到2023-11-21阿里云上yum最新的只有6.0版本,后期如果有新版自行替换

vim /etc/yum.repos.d/mongodb-org.repo
1

输入内容

[mongo-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/6.0/x86_64/
gpgcheck=0
enabled=1
1
2
3
4
5

# yum建立缓存

yum clean all
yum makecache
1
2

# 安装

yum install -y mongodb-org
1

# 查看安装路径

whereis mongod
1

返回的结果是:

mongod: /usr/bin/mongod /etc/mongod.conf /usr/share/man/man1/mongod.1.gz
1

注意第二个.conf文件。这个文件是我们需要的

# 修改配置

vim /etc/mongod.conf
1

默认的配置文件为:

# 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:

#snmp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

我们需要注意的是里面的bindIp,如果有开发需求,最好改成0.0.0.0。如果是生产环境则严格按照生产要求来设置。

# 启动、停止、开机自启

systemctl start mongod.service
systemctl stop mongod.service
systemctl enable mongod.service
1
2
3
上次更新: 2024-11-06, 19:27:10
最近更新
01
java playwright爬虫
11-06
02
连接chrome调试
07-23
03
连接chrome调试
07-23
更多文章>