mongodb Config Server的配置文件 (只需更改bindIP)
systemLog:
destination: file
path: "/opt/servers/mongodb_demo/standalone/logs/mongologs.log"
logAppend: true
storage:
dbPath: "/opt/servers/mongodb_demo/standalone/data/db/"
journal:
enabled: true
processManagement:
fork: true
#开启安全认证则去掉#
#security:
# keyFile: "/opt/servers/mongodb_demo/standalone/key/keyfile"
# authorization: enabled
net:
#服务实例绑定所有IP,有副作用,副本集初始化的时候,节点名字会自动设置为本地域名,而不是ip
#bindIpAll: true
#服务实例绑定的IP
bindIp: localhost,192.168.203.135
#bindIp
#绑定的端口
port: 27022
replication:
#副本集的名称
replSetName: itcast
sharding:
clusterRole: configsvr
shard 的配置文件(只需更改replSetName;port;bindIP)
systemLog:
destination: file
path: "/opt/servers/mongodb_demo/shard/logs/shard1.log"
logAppend: true
storage:
dbPath: "/opt/servers/mongodb_demo/shard/data/data1/"
journal:
enabled: true
processManagement:
fork: true
#开启安全认证则去掉#
#security:
# keyFile: "/opt/servers/mongodb_demo/shard/key/keyfile1"
# authorization: enabled
net:
#服务实例绑定所有IP,有副作用,副本集初始化的时候,节点名字会自动设置为本地域名,而不是ip
#bindIpAll: true
#服务实例绑定的IP
bindIp: localhost,192.168.203.135
#bindIp
#绑定的端口
port: 27018
replication:
#副本集的名称
replSetName: shart1
oplogSizeMB: 2048
sharding:
clusterRole: shardsvr
mongos(只需更改port;bindIP)
sharding:
configDB: itcast/192.168.203.135:27022,192.168.203.136:27022,192.168.203.137:27022
systemLog:
destination: file
path: "/opt/servers/mongodb_demo/mongos/logs/mongos.log"
logAppend: true
processManagement:
fork: true
#开启安全认证则去掉#
#security:
# keyFile: "/opt/servers/mongodb_demo/mongos/key/keyfile"
net:
#服务实例绑定所有IP,有副作用,副本集初始化的时候,节点名字会自动设置为本地域名,而不是ip
#bindIpAll: true
#服务实例绑定的IP
bindIp: localhost,192.168.203.135
port: 27021
最后关闭mongodb需要安装psmisc
yum install psmisc
安装完之后可以使用killall 命令 快速关闭多个进程
killall mongod
killall mongos
需注意:一定要关防火墙,出现错误查看路径,权限,最后找不出毛病可以查看日志文件
systemctl stop firewalld.service #暂时关闭防火墙
firewall-cmd --state #查看防火墙状态
启动一个服务:systemctl start firewalld.service
关闭一个服务:systemctl stop firewalld.service
在开机时启用一个服务:systemctl enable firewalld.servic
在开机时禁用一个服务:systemctl disable firewalld.servicefirewall-cmd --zone=public --add-port=28128/tcp --permanent #开放28128端口
firewall-cmd --reload #立即生效
user admin
db.system.users.find().pretty()#查看用户
nmtui #命令更改主机名和IP地址
#改变优先级:
conf_temp=rs.config()
conf_temp.members[0].priority=2
rs.reconfig(conf_temp)
mongo
mongod -f /opt/servers/mongodb_demo/mongodb/conf/mongod.conf
mongod -f /opt/servers/mongodb_demo/shard/conf/shard1.conf
mongos -f /opt/servers/mongodb_demo/mongos/conf/mongos.conf
mongo --host 192.168.203.135:27018
cd /opt/servers/mongodb_demo/mongodb/bin
source ~/.bash_profile
mongod -f /opt/servers/mongodb_demo/mongodb/conf/mongod.conf/