MongoDBV3.0.7版本(shard+replica)集群的搭建及验证(2)

opt]# tar zxvf mongodb-linux-x86_64-rhel55-3.0.7.gz opt]# mv mongodb-linux-x86_64-rhel55-3.0.7 /usr/local/mongodb opt]# useradd mongo opt]# passwd mongo Changing password for user mongo. New UNIX password: BAD PASSWORD: it is too simplistic/systematic Retype new UNIX password: passwd: all authentication tokens updated successfully. opt]# chown -R mongo:mongo /usr/local/mongodb/ opt]# chown -R mongo:mongo /db

创建相关模块存放路径:

创建configeServer目录(172.16.16.120/121/122):

#mkdir -p /db/configS/data & mkdir -p /db/configS/log (存放ConfigServer的数据、日志)

创建shard1目录(172.16.16.124/125/126):

#mkdir -p /db/shard1/data & mkdir -p /db/shard1/log (存放shard1的数据、日志)

创建shard2目录(172.16.16.125/126/131 ):

#mkdir -p /db/shard2/data & mkdir -p /db/shard2/log (存放shard2的数据、日志)

创建shard3目录(172.16.16.126/131/124 ):

#mkdir -p /db/shard3/data & mkdir -p /db/shard3/log (存放shard3的数据、日志)

创建shard4目录(172.16.16.131/124/125 ):

#mkdir -p /db/shard4/data & mkdir -p /db/shard4/log (存放shard4的数据、日志)

创建mongos目录(172.16.16.124/125/126/131)

#mkdir -p /db/mongos/log (由于mongos只做路由使用,不存数据,所以只需要建立log目录)

 模块配置及启动:

configServer(172.16.16.120/121/122)配置及服务启动:

编写 /usr/local/mongodb/conf/configServer.conf,将参数都放在该文件中:

 

#vim /usr/local/mongodb/conf/configServer.conf #!/bin/bash systemLog: destination: file path: "/db/configS/log/configServer.log" #日志存储位置 logAppend: true storage: journal: #journal配置 enabled: true dbPath: "/db/configS/data" #数据文件存储位置 directoryPerDB: true #是否一个库一个文件夹 engine: wiredTiger #数据引擎 wiredTiger: #WT引擎配置 engineConfig: cacheSizeGB: 6 #设置为6G,默认为物理内存的一半 directoryForIndexes: true #是否将索引也按数据库名单独存储 journalCompressor: zlib collectionConfig: #表压缩配置 blockCompressor: zlib indexConfig: #索引配置 prefixCompression: true net: #端口配置 port: 30001 #另外两台需要分别修改为30002、30003 processManagement: #配置启动管理方式 fork: true sharding: #分片配置 clusterRole: configsvr #分片角色

启动configServer:

conf]$ /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/conf/configServer.conf

mongos(172.16.16.124/125/126/131)配置及服务启动:

编写mongos.conf,将参数都放在该文件中(4台配置文件都一样):

#vim /usr/local/mongodb/conf/mongos.conf #!/bin/bash systemLog: destination: file path: "/db/mongos/log/mongos.log" logAppend: true net: port: 50001 sharding: configDB: 172.16.16.120:30001,172.16.16.121:30001,172.16.16.122:30001 processManagement: fork: true

启动mongos:应保证集群中设备的时间都是一样的,否则启动mongos会报错,若不相同,可先搭建一套NTP服务器

conf]$ /usr/local/mongodb/bin/mongos -f /usr/local/mongodb/conf/mongos.conf

shard1分片+副本集配置及服务启动(172.16.16.124/125/126 ):

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/fe9141f5ffdfe13e416927805afc8b76.html