mongodb一主一从一Arbiter复制集部署
警告
本文最后更新于 2020-05-31 16:50,文中内容可能已过时。
安装mongodb
可参考:https://soulchild.cn/1279.html
环境:
10.0.0.40 mongodb-01
10.0.0.41 mongodb-02
10.0.0.42 mongodb-arb
修改配置文件:
# 系统日志相关
systemLog:
destination: file
logAppend: true
path: /application/mongodb/log/mongod.log
# 数据存储相关
storage:
dbPath: /application/mongodb/data
journal:
enabled: true
# 网络相关
net:
port: 27017
bindIp: 0.0.0.0
# 进程控制相关
processManagement:
fork: true
# pidFilePath: /var/run/mongod.pid
# 安全配置
#security:
# authorization: enable
# keyFile: /application/mongodb/data/keyfile
#复制集配置
replication:
oplogSizeMB: 2048
replSetName: app_1
配置复制集
#登陆主mongo
mongo
conf = {
_id: 'app_1',
members: [
{_id: 0, host: '10.0.0.40:27017',priority:10},
{_id: 1, host: '10.0.0.41:27017',priority:9},
{_id: 2, host: '10.0.0.42:27017',"arbiterOnly": true}
]
}
#初始化pepei配置
rs.initiate(conf)
# 查看状态
rs.status()
添加超级管理员
# 连接数据库
mongo
# 切换到admin库
use admin
# 创建用户
db.createUser(
{
user: "root",
pwd: "123",
roles: [{ role:"root",db:"admin"}]
}
)
生成认证keyfile
openssl rand -base64 512 > /application/mongodb/data/keyfile
配置文件添加安全配置
security:
authorization: enable
keyFile: /application/mongodb/data/keyfile
重启所有节点
请我喝杯水
微信号
微信打赏