文章目录
一、集群规划
1.1 集群安装规划

1.2 端口规划
mongos:20000
config:21000
shard1:27001
shard2:27002
shard3:27003
1.3 目录创建
数据目录:
/mongodb/data/config
/mongodb/data/shard1
/mongodb/data/shard2
/mongodb/data/shard3
日志目录:
/mongodb/logs/mongos
/mongodb/logs/config
/mongodb/logs/shard1
/mongodb/logs/shard2
/mongodb/logs/shard3
配置目录:
/usr/local/mongodb/conf
/usr/local/mongodb/server
二、mongodb安装(三台均需要操作)
2.1 下载、解压
https://www.mongodb.com/try/download/community-edition/releases/archive
cd /usr/local/
tar -zxvf mongodb-linux-x86_64-rhel70-4.0.26.tgz
2.2 配置环境变量
vim /etc/profile
#mongodb path
export MONGODB_HOME=/usr/local/mongodb
export PATH=$MONGODB_HOME/bin:$PATH
source /etc/profile
三、mongodb组件配置
3.1 配置config server的副本集
3.1.1 config配置文件
vim /usr/local/mongodb/conf/config.conf
## content
systemLog:
destination: file
logAppend: true
path: /mongodb/logs/config.log
# Where and how to store data.
storage:
dbPath: /mongodb/data/config
journal:
enabled: true
# how the process runs
processManagement:
fork: true
pidFilePath: /mongodb/logs/config/configsrv.pid
# network interfaces
net:
port: 21000
bindIp: 0.0.0.0
#operationProfiling:
replication:
replSetName: config
sharding:
clusterRole: configsvr
3.1.2 config server启动
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/config.conf &
3.1.3 初始化config
只需要在一台主机上执行
mongo 10.10.3.134:21000
config = {
_id : "config",members : [{
_id : 0, host : "10.10.3.134:21000" },{
_id : 1, host : "10.10.3.135:21000" },{
_id : 2, host : "10.10.3.136:21000" }]}
rs.initiate(config)

需要关闭防火墙,selinux
3.2 配置shard1 server的副本集
3.2.1 shard1配置文件
vim /usr/local/mongodb/conf/shard1.conf
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /mongodb/logs/shard1/shard1.log
# Where and how to store data.
storage:
dbPath: /mongodb/data/shard1
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
# how the process runs
processManagement:
fork: true
pidFilePath: /mongodb/logs/shard1/shard1.pid
# network interfaces
net:
port: 27001
bindIp: 0.0.0.0
#operationProfiling:
replication:
replSetName: shard1
sharding:
clusterRole: shardsvr
同步配置文件
scp /usr/local/m

最低0.47元/天 解锁文章
438

被折叠的 条评论
为什么被折叠?



