One routing node
IP Address: 192.168.80.110
Port: 11111
Three sets of replica sets (each replica set in a shard node must have an arbiter node)
IP Address: 192.168.80.55, Port: 15555/15556/15557
IP Address: 192.168.80.56, Port: 15555/15556/15557
IP Address: 192.168.80.57, Port: 15555/15556/15557
All clusters are built on one machine. Different ports are used to distinguish them
A set of configuration cluster
IP address: 192.168.80.128, Port: 15555/15556/15557 (All clusters are built on one machine. Different ports are used to distinguish them)
Name and address mongodb-linux-x86_64-4.1.3.tgz Download link, Extraction code: 5555
IP addresses are as follows:
192.168.80.110 as the routing node, 192.168.80.128 as the configuration node (building a three-node replica set cluster, one primary and two secondaries), 192.168.80.55 as the sharding node (building a three-node replica set cluster, one primary and two secondaries), 192.168.80.56 as the sharding node (building a three-node replica set cluster, one primary and two secondaries), 192.168.80.57 as the sharding node (building a three-node replica set cluster, one primary and two secondaries)
Note: All clusters are built on one machine. Different ports are used to distinguish them
online casino helpJoin us
Node name configuration file Node 1: 192.168.80.128:155555 Configuration file: config-15555.conf Node 2: 192.168.80.128:155556 Configuration file: config-15556.conf Node 3: 192.168.80.128:155557 Configuration file: config-15557.conf
1. Copy the installation file and decompress it:
2. Rename the MongoDB directory and create a configuration directory under the root directory:
entry method lottery entry method and The latest entrance
3. Create configuration file: config-15555.conf
4. Create log directory and database file storage directory in the configuration file directory config:
5. Start the first MongoDB in the configuration set:
6. Perform the same operation to set up the other two machines in the configuration node cluster: copy the configuration filesports betting method and Just click to enter
Modify port:
Create directory for storing database files:
7. Perform the same operation to start the other two machines in the configuration node cluster
Note: use admin
Check cluster status: Node 15555 becomes primary, the other two nodes become secondary
Building shard1 cluster
Node name configuration file Node 1: 192.168.80.55:155555 Configuration file: config-15555.conf Node 2: 192.168.80.55:155556 Configuration file: config-15556.conf Node 3: 192.168.80.55:155557 Configuration file: config-15557.conf
Building shard2 cluster
Node name configuration file node 1: 192.168.80.56:155555 configuration file: config-15555.conf node 2: 192.168.80.56:155556 configuration file: config-15556.conf node 3: 192.168.80.56:155557 configuration file: config-15557.conf
shard3 cluster construction
Node name configuration file node 1: 192.168.80.57:155555 configuration file: config-15555.conf node 2: 192.168.80.57:155556 configuration file: config-15556.conf node 3: 192.168.80.57:155557 configuration file: config-15557.conf
Install and configure mongodb on server 192.168.80.55
Detailed configuration of each machine:
Start each mongod
Enter one of the mongodb to configure the cluster
Check the cluster status:
The configuration method is consistent with the shard1 cluster configuration
shard2 cluster construction from 15555 to 15557
shard2 cluster operation 1: Create the configuration file and start mongodb
shard2 cluster operation 2: Enter one of the mongodb to configure the cluster
shard3 cluster construction from 15555 to 15557
shard3 cluster operation 1: Create the configuration file and start mongodb
shard3 cluster operation 2: Enter one of the mongodb to configure the cluster
route routing node
Node name configuration file node 1: 192.168.80.110:155555 configuration file: config-15555.conf
Log in to the routing node, unzip mongodb, and rename
Edit the routing node configuration file: route-15555.conf
port=15555
bind_ip=0.0.0.0
fork=true
logpath=route/logs/route.log
configdb=configsvr/192.168.80.128:15555,192.168.80.128:15556,192.168.80.128:15557
Start the routing node using mongos (note that it is not mongod)
https://blog.csdn.net/chuanchengdabing/article/details/bin/mongos -f route/route-15555.conf
Enter mongo routing
https://blog.csdn.net/chuanchengdabing/article/details/bin/mongo –port 15555
Check mongo routing status
Add shard1 shard node
Add shard2 and shard3 shard nodes
Check status
Continue to use mongos to complete sharding enablement and sharding size setting
Enable sharding function for database: sh.enableSharding(“dabing_employee”)
Enable sharding function for specified collection: sh.shardCollection(“dabing_employee.dabing_employee_datas”,{“片键字段名如 name”: index description})
Check whether each shard has synchronized the collection:
Add data to the collection through routing in a loop for 500 times:
Enter the databases of shard1 and shard2 separately for verification: the names will be hashed and distributed to different nodes according to the hash method
Create an administrator:
Create a normal user:
Note:
Note:
Create a directory data/mongodb to store the generated keys:
Generate keys (for interaction between configuration nodes and shard node clusters) (copy testKeyFile.file to configuration nodes and shard nodes)
Both the node and the shard node need to be added to the configuration: a total of 12 configuration files
Configure node cluster
Shard node shard1 cluster
Shard node shard2 cluster
Shard node shard3 cluster
Note:
Solution: The 12 nodes need to be set, note: The permission here needs to be set to 600, too large will also cause the above problem
keyFile=data/mongodb/testKeyFile.file
Using an administrator account: admin/admin
Using a normal user: hanmeimei/123456
Directly query the sharding cluster, but cannot find the data because the data is not visible at this time. User permissions need to be created for each shard node
1. Maven dependency pom.xml
2. Configuration file application.properties
3. Entity class Employee
4. Persistence layer interface EmployeeRespository
5. Test class MongoDBRespositoryMain
6. Program execution result
Console execution log:
7. Data validation of mongo sharding cluster
Cloud disk address: springboot access mongodb test case, password: z5ow