In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The company's practical Replica Sets+Sharding solution adopts configuration file 2
The actual practice of the company's mongo cluster fragmentation
Three servers
Host 1 (172.16.0.115) Host 2 (172.16.0.114) Host 3 (172.16.0.103)
The first film (11731) master copy arbitration
The second film (11732) arbitration master copy
The third film (11733) copy of the arbitrator
30000 config Server config Server config Server
60000 Route Process Route Process Route Process
Create a database directory
Host 1 (172.16.0.115) profile
[root@mongodb115] # mkdir-p / home/data/shard1_1
[root@mongodb115] # mkdir-p / home/data/shard2_1
[root@mongodb115] # mkdir-p / home/data/shard3_1
[root@mongodb115 ~] # mkdir-p / home/data/config # config server directory
[root@mongodb115] # mkdir-p / home/config # playback configuration file
[root@mongodb115] # mkdir-p / home/data/logs
Shard 1
[root@mongodb115 config] # cat shard1_1.conf
Port=11731
Dbpath=/home/data/shard1_1
Logpath=/home/data/logs/shard1_1.log
Directoryperdb=true
Logappend=true
ReplSet=shard1
# bind_ip=172.16.0.115
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard1_1.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Shard 2
[root@mongodb115 config] # cat shard2_1.conf
Port=11732
Dbpath=/home/data/shard2_1
Logpath=/home/data/logs/shard2_1.log
Directoryperdb=true
Logappend=true
ReplSet=shard2
# bind_ip=172.16.0.115
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard2_1.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Shard 3
[root@mongodb115 config] # cat shard3_1.conf
Port=11733
Dbpath=/home/data/shard3_1
Logpath=/home/data/logs/shard3_1.log
Directoryperdb=true
Logappend=true
ReplSet=shard3
# bind_ip=172.16.0.115
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard3_1.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Config server profile
[root@mongodb115 config] # cat config.conf
Port=30000
Dbpath=/home/data/config
Logpath=/home/data/logs/config.log
Directoryperdb=true
Configsvr=true
Logappend=true
# bind_ip=172.16.0.115
Fork=true
Pidfilepath=/home/data/config.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Route Proces profile
[root@mongodb115 config] # cat mongos.conf
Port=60000
Logpath=/home/data/logs/mongos.log
Logappend=true
Configdb=172.16.0.115:30000172.16.0.114:30000172.16.0.103:30000
# bind_ip=172.16.0.115
Fork=true
Pidfilepath=/home/data/mongos.pid
ChunkSize=5
MaxConns=20000
Nohttpinterface=true
Host 2 (172.16.0.114) profile
[root@mongodb114] # mkdir-p / home/data/shard1_2
[root@mongodb114] # mkdir-p / home/data/shard2_2
[root@mongodb114] # mkdir-p / home/data/shard3_2
[root@mongodb114 ~] # mkdir-p / home/data/config # config server directory
[root@mongodb114] # mkdir-p / home/config # playback configuration file
[root@mongodb114] # mkdir-p / home/data/logs
Shard 1
[root@mongodb114 config] # cat shard1_2.conf
Port=11731
Dbpath=/home/data/shard1_2
Logpath=/home/data/logs/shard1_2.log
Directoryperdb=true
Logappend=true
ReplSet=shard1
# bind_ip=172.16.0.114
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard1_2.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Shard 2
[root@mongodb114config] # cat shard2_2.conf
Port=11732
Dbpath=/home/data/shard2_2
Logpath=/home/data/logs/shard2_2.log
Directoryperdb=true
Logappend=true
ReplSet=shard2
# bind_ip=172.16.0.114
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard2_2.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Shard 3
[root@mongodb114 config] # cat shard3_2.conf
Port=11733
Dbpath=/home/data/shard3_2
Logpath=/home/data/logs/shard3_2.log
Directoryperdb=true
Logappend=true
ReplSet=shard3
# bind_ip=172.16.0.114
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard3_2.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Config server profile
[root@mongodb114 config] # cat config.conf
Port=30000
Dbpath=/home/data/config
Logpath=/home/data/logs/config.log
Directoryperdb=true
Configsvr=true
Logappend=true
# bind_ip=172.16.0.114
Fork=true
Pidfilepath=/home/data/config.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Route Proces profile
[root@mongodb114 config] # cat mongos.conf
Port=60000
Logpath=/home/data/logs/mongos.log
Logappend=true
Configdb=172.16.0.115:30000172.16.0.114:30000172.16.0.103:30000
# bind_ip=172.16.0.114
Fork=true
Pidfilepath=/home/data/mongos.pid
ChunkSize=5
MaxConns=20000
Nohttpinterface=true
Host 3 (172.16.0.103) profile
[root@mongodb103] # mkdir-p / home/data/shard1_3
[root@mongodb103] # mkdir-p / home/data/shard2_3
[root@mongodb103] # mkdir-p / home/data/shard3_3
[root@mongodb103 ~] # mkdir-p / home/data/config # config server directory
[root@mongodb103] # mkdir-p / home/config # playback configuration file
[root@mongodb103] # mkdir-p / home/data/logs
Shard 1
[root@mongodb103 config] # cat shard1_3.conf
Port=11731
Dbpath=/home/data/shard1_3
Logpath=/home/data/logs/shard1_3.log
Directoryperdb=true
Logappend=true
ReplSet=shard1
# bind_ip=172.16.0.103
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard1_3.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Shard 2
[root@mongodb103 config] # cat shard2_3.conf
Port=11732
Dbpath=/home/data/shard2_3
Logpath=/home/data/logs/shard2_3.log
Directoryperdb=true
Logappend=true
ReplSet=shard2
# bind_ip=172.16.0.103
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard2_3.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Shard 3
[root@mongodb103 config] # cat shard3_3.conf
Port=11733
Dbpath=/home/data/shard3_3
Logpath=/home/data/logs/shard3_3.log
Directoryperdb=true
Logappend=true
ReplSet=shard3
# bind_ip=172.16.0.103
Shardsvr=true
Fork=true
Pidfilepath=/home/data/shard3_3.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Config server profile
[root@mongodb103 config] # cat config.conf
Port=30000
Dbpath=/home/data/config
Logpath=/home/data/logs/config.log
Directoryperdb=true
Configsvr=true
Logappend=true
# bind_ip=172.16.0.103
Fork=true
Pidfilepath=/home/data/config.pid
MaxConns=20000
OplogSize=5000
Noprealloc=true
Nohttpinterface=true
Route Proces profile
[root@mongodb103 config] # cat mongos.conf
Port=60000
Logpath=/home/data/logs/mongos.log
Logappend=true
Configdb=172.16.0.115:30000172.16.0.114:30000172.16.0.103:30000
# bind_ip=172.16.0.103
Fork=true
Pidfilepath=/home/data/mongos.pid
ChunkSize=5
MaxConns=20000
Nohttpinterface=true
Extract the mongodb file
Host 1
[root@mongodb115 ~] # tar zxvf mongodb-linux-x86_64-2.4.7.tgz
[root@mongodb115] # mv mongodb-linux-x86_64-2.4.7 / home/mongodb
Host 2
[root@mongodb114 ~] # tar zxvf mongodb-linux-x86_64-2.4.7.tgz
[root@mongodb114] # mv mongodb-linux-x86_64-2.4.7 / home/mongodb
Host 3
[root@mongodb103 ~] # tar zxvf mongodb-linux-x86_64-2.4.7.tgz
[root@mongodb103] # mv mongodb-linux-x86_64-2.4.7 / home/mongodb
Start shard1,shard2,shard3
Host 1
[root@mongodb115] # / home/mongodb/bin/mongod-f / home/config/shard1_1.conf
[root@mongodb115] # / home/mongodb/bin/mongod-f / home/config/shard2_1.conf
[root@mongodb115] # / home/mongodb/bin/mongod-f / home/config/shard3_1.conf
Host 2
[root@mongodb114] # / home/mongodb/bin/mongod-f / home/config/shard1_2.conf
[root@mongodb114] # / home/mongodb/bin/mongod-f / home/config/shard2_2.conf
[root@mongodb114] # / home/mongodb/bin/mongod-f / home/config/shard3_2.conf
Host 3
[root@mongodb103] # / home/mongodb/bin/mongod-f / home/config/shard1_3.conf
[root@mongodb103] # / home/mongodb/bin/mongod-f / home/config/shard2_3.conf
[root@mongodb103] # / home/mongodb/bin/mongod-f / home/config/shard3_3.conf
Configure Replica Sets
Configuration Shard 1 is configured on 172.16.0.115
[root@mongodb115] # / home/mongodb/bin/mongo-- port 11731
MongoDB shell version: 2.4.7
Connecting to: 127.0.0.1:11731/test
> config= {_ id:'shard1',members: [{_ id:0,host:'172.16.0.115:11731', priority:2}, {_ id:1,host:'172.16.0.114:11731'}, {_ id:2,host:'172.16.0.103:11731',arbiterOnly:true}]}
Rs.initiate (config)
Configure Shard 2 on 172.16.0.114
[root@mongodb114] # / home/mongodb/bin/mongo-- port 11732
MongoDB shell version: 2.4.7
Connecting to: 127.0.0.1:11732/test
> config= {_ id:'shard2',members: [{_ id:0,host:'172.16.0.115:11732',arbiterOnly:true}, {_ id:1,host:'172.16.0.114:11732',priority:2}, {_ id:2,host:'172.16.0.103:11732'}]}
Rs.initiate (config)
Configure shard 3 configure the primary node with high priority value in members on 172.16.0.103, and be sure to add arbiterOnly:true to the arbitration point.
[root@mongodb103] # / home/mongodb/bin/mongo-- port 11733
MongoDB shell version: 2.4.7
Connecting to: 127.0.0.1:11733/test
> config= {_ id:'shard3',members: [{_ id:0,host:'172.16.0.115:11733'}, {_ id:1,host:'172.16.0.114:11733',arbiterOnly:true}, {_ id:2,host:'172.16.0.103:11733',priority:2}]}
Rs.initiate (config)
Start 3 config server
Host 1
[root@mongodb115] # / home/mongodb/bin/mongod-f / home/config/config.conf
Host 2
[root@mongodb114] # / home/mongodb/bin/mongod-f / home/config/config.conf
Host 3
[root@mongodb103] # / home/mongodb/bin/mongod-f / home/config/config.conf
Start 3 Route Process
Host 1
[root@mongodb115] # / home/mongodb/bin/mongos-f / home/config/mongos.conf
Host 2
[root@mongodb114] # / home/mongodb/bin/mongos-f / home/config/mongos.conf
Host 3
[root@mongodb103] # / home/mongodb/bin/mongos-f / home/config/mongos.conf
Configure shard Cluser
[root@mongodb115] # / home/mongodb/bin/mongo-- port 60000
MongoDB shell version: 2.4.7
Connecting to: 127.0.0.1:60000/test
Mongos > use admin
Switched to db admin
Mongos > db.runCommand ({addshard: "shard1/172.16.0.115:11731, 172.16.0.114purl 11731, 172.16.0.103 addshard 11731"})
Mongos > db.runCommand ({addshard: "shard2/172.16.0.115:11732, 172.16.0.114virtual 11732, 172.16.0.103virtual 11732"})
Mongos > db.runCommand ({addshard: "shard3/172.16.0.115:11733, 172.16.0.114virtual 11733, 172.16.0.103virtual 11733"})
Next, activate sharding, as shown in the following code: using hash shredding
Db.runCommand ({enablesharding: "test"})
Db.runCommand ({shardcollection: "test.users", key: {id: "hashed"}})
Emphasize that the service time must be synchronized, otherwise there will be problems.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.