初始化

总结下我所碰到的情况

  1. 开启用户认证,初始化时报错
  2. 期间使用root用户启动,导致文件权限不一致

搭建mongo副本集时,安装好mongo 修改配置文件 启动初始化

mongodb 配置

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
46
47
48
# 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: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.


#security:
#security:
# authorization: enabled

#operationProfiling:

replication:
replSetName: contest #配置副本主要依靠此项配置 replSetName 后的名称必须一样


#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

初始化

1
2
3
config = {"_id":"contest","members":[{"_id":0,"host":"192.168.227.142:27017"},{"_id":1,"host":"192.168.227.142:27018"},{"_id":2,"host":"192.168.227.142:27019",arbiterOnly:true}]}

rs.initiate(config)

查看状态

1
rs.status();

当需要用户管理时,可通过副本集的主节点进行账号创建,同步后 修改配置文件 重启即可

1
2
3
4
增加如下配置即可

security:
authorization: enabled

用户管理提供另一篇文章进行参考 xshrim