0 6 min 1 week

  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)

  Insert image description here

  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
  Insert image description here

  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:

  Insert image description here

  2. Rename the MongoDB directory and create a configuration directory under the root directory:
entry method lottery entry method and The latest entrance
  Insert image description here

  3. Create configuration file: config-15555.conf

  Insert image description here

  Insert image description here

  4. Create log directory and database file storage directory in the configuration file directory config:

  Insert image description here

  5. Start the first MongoDB in the configuration set:

  Insert image description here

  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

  Insert image description here

  Modify port:

  Insert image description here

  Insert image description here

  Create directory for storing database files:

  Insert image description here

  7. Perform the same operation to start the other two machines in the configuration node cluster

  Insert image description here

  Insert image description here

  Note: use admin

  Insert image description here

  Insert image description here

  Check cluster status: Node 15555 becomes primary, the other two nodes become secondary

  Insert image description here

  Insert image description here

  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

  Insert image description hereInsert image description here

  Detailed configuration of each machine:

  Start each mongod

  Insert image description here

  Enter one of the mongodb to configure the cluster

  Insert image description here

  Check the cluster status:

  Insert image description here

  Insert image description here

  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

  Insert image description here

  shard2 cluster operation 2: Enter one of the mongodb to configure the cluster

  Insert image description here

  shard3 cluster construction from 15555 to 15557

  shard3 cluster operation 1: Create the configuration file and start mongodb

  Insert image description here

  shard3 cluster operation 2: Enter one of the mongodb to configure the cluster

  Insert image description here

  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

  Insert image description here

  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

  Insert image description here

  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

  Insert image description here

  Enter mongo routing

  https://blog.csdn.net/chuanchengdabing/article/details/bin/mongo –port 15555

  Insert image description here

  Check mongo routing status

  Insert image description here

  Add shard1 shard node

  Insert image description hereAdd shard2 and shard3 shard nodes

  Insert image description here

  Check status

  Insert image description here

  Continue to use mongos to complete sharding enablement and sharding size setting

  Enable sharding function for database: sh.enableSharding(“dabing_employee”)

  Insert image description here

  Enable sharding function for specified collection: sh.shardCollection(“dabing_employee.dabing_employee_datas”,{“片键字段名如 name”: index description})

  Insert image description here

  Check whether each shard has synchronized the collection:

  Insert image description here

  Add data to the collection through routing in a loop for 500 times:

  Insert image description here

  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

  Insert image description here

  Create an administrator:

  Insert image description here

  Create a normal user:

  Insert image description here

  Note:

  Insert image description here

  Insert image description here

  Insert image description here

  Insert image description here

  Insert image description here

  Note:

  Create a directory data/mongodb to store the generated keys:

  Insert image description here

  Generate keys (for interaction between configuration nodes and shard node clusters) (copy testKeyFile.file to configuration nodes and shard nodes)

  Insert image description here

  Both the node and the shard node need to be added to the configuration: a total of 12 configuration files

  Configure node cluster

  Insert image description here

  Insert image description here

  Insert image description here

  Shard node shard1 cluster

  Insert image description here

  Insert image description here

  Insert image description here

  Shard node shard2 cluster

  Insert image description here

  Insert image description here

  Insert image description here

  Shard node shard3 cluster

  Insert image description here

  Insert image description here

  Insert image description here

  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

  Insert image description here

  Insert image description here

  Insert image description here

  Insert image description here

  Insert image description here

  Insert image description here

  Insert image description here

  Using an administrator account: admin/admin

  Insert image description here

  Using a normal user: hanmeimei/123456

  Insert image description here

  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

  Insert image description here

  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:

  Insert image description here

  7. Data validation of mongo sharding cluster

  Insert image description here

  Cloud disk address: springboot access mongodb test case, password: z5ow