{"id":13475,"date":"2019-11-08T12:25:18","date_gmt":"2019-11-08T12:25:18","guid":{"rendered":"https:\/\/dbtut.com\/?p=13475"},"modified":"2020-01-14T06:56:49","modified_gmt":"2020-01-14T06:56:49","slug":"deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux","status":"publish","type":"post","link":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/","title":{"rendered":"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS"},"content":{"rendered":"<p>As you know security is one of the key points during database administration. In MongoDB sharded clusters security between components of the cluster is provided by Internal authentication. In this tutorial I will deploy a sharded cluster and enable internal authentication by using a keyfile.<\/p>\n<p>Enforcing internal authentication also enforces user access control. To connect to the replica set, clients like the mongo shell need to use a user account.<\/p>\n<h2>Step 1: Create a User For Administration<\/h2>\n<pre class=\"lang:default decode:true\">[root@mongodbserv ~]# adduser mongodb\n[root@mongodbserv ~]# passwd mongodb<\/pre>\n<p><strong>Important Note:<\/strong> Create mongodb user in all servers and perform all operations with this user.<\/p>\n<h2>Step 2: Install MongoDB Community Edition<\/h2>\n<h3>Using .rpm Packages (Recommended)<\/h3>\n<p>Configure the package management system (yum).<\/p>\n<p>Create a \/etc\/yum.repos.d\/mongodb-org-4.0.repo file so that you can install MongoDB directly using yum:<\/p>\n<pre class=\"lang:default decode:true\">vi \/etc\/yum.repos.d\/mongodb-org-4.0.repo<\/pre>\n<pre class=\"lang:default decode:true\">[mongodb-org-4.0]\nname=MongoDB Repository\nbaseurl=https:\/\/repo.mongodb.org\/yum\/redhat\/$releasever\/mongodb-org\/4.0\/x86_64\/\ngpgcheck=1\nenabled=1\ngpgkey=https:\/\/www.mongodb.org\/static\/pgp\/server-4.0.asc<\/pre>\n<p><strong>Note:<\/strong> If you want to install difference version you must change 4.0 in the above content.<\/p>\n<h3>Install MongoDB packages<\/h3>\n<p>To install the latest stable version of MongoDB, issue the following command:<\/p>\n<pre class=\"lang:default decode:true \">sudo yum install -y mongodb-org<\/pre>\n<h2>Step 3: Disable SELINUX<\/h2>\n<p>If you are using SELinux, you must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red Hat Enterprise Linux or CentOS Linux).<\/p>\n<p>Disable SELinux by setting the SELINUX setting to disabled in \/etc\/selinux\/config.<\/p>\n<pre class=\"lang:default decode:true\">SELINUX=disabled<\/pre>\n<h2>Step 4: Stop Firewalld and Disable iptables<\/h2>\n<h3>Disable and Stop Firewalld<\/h3>\n<p>Stop the firewall so the servers can communicate with each other.<\/p>\n<pre class=\"lang:default decode:true \">systemctl disable firewalld\nsystemctl mask --now firewalld<\/pre>\n<h3>Disable iptables<\/h3>\n<pre class=\"lang:default decode:true \">sudo \/sbin\/iptables -F &amp;&amp; \/sbin\/iptables-save<\/pre>\n<h2>Step 5:\u00a0 Recommended ulimit Settings<\/h2>\n<p>Configure some ulimit parameters as below for mongodb.<\/p>\n<p><strong>Edit limits.conf:<\/strong><\/p>\n<pre class=\"lang:default decode:true  \">vi \/etc\/security\/limits.conf<\/pre>\n<pre class=\"lang:default decode:true   \">*               soft    nproc           64000\n*               hard    nproc           64000\n*               soft    nofile          64000\n*               hard    nofile          64000\n<\/pre>\n<p><strong>Edit 20-nproc.conf:<\/strong><\/p>\n<p>Edit 20-nproc.conf and update the value as below.\u00a0<\/p>\n<pre class=\"lang:default decode:true  \">vi \/etc\/security\/limits.d\/20-nproc.conf<\/pre>\n<pre class=\"lang:default decode:true   \">*               soft    nproc           64000\n<\/pre>\n<ul>\n<li>-f (file size): unlimited<\/li>\n<li>-t (cpu time): unlimited<\/li>\n<li>-v (virtual memory): unlimited<\/li>\n<li>-l (locked-in-memory size): unlimited<\/li>\n<li>-n (open files): 64000<\/li>\n<li>-m (memory size): unlimited<\/li>\n<li>-u (processes\/threads): 64000<\/li>\n<\/ul>\n<p><strong>Note:<\/strong> You must logout and login or restart the server to activate changes.<\/p>\n<p>Make sure that your ulimit settings are configured correctly. You can check current ulimit settings with the command below:<\/p>\n<pre class=\"lang:default decode:true\">ulimit -a<\/pre>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-13821 aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-44.png\" alt=\"\" width=\"401\" height=\"246\" \/><\/h2>\n<h2>Step 6: Disable Transparent Huge Pages<\/h2>\n<p>Before starting mongod processes, it is recommended to disable Transparent Huge Pages. Mongodb often perform poorly with THP enabled. You can use the following document:<\/p>\n<p><a href=\"https:\/\/docs.mongodb.com\/manual\/tutorial\/transparent-huge-pages\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/docs.mongodb.com\/manual\/tutorial\/transparent-huge-pages\/<\/a><\/p>\n<h2>Step 7: Create Directories<\/h2>\n<p>Create a folder structure to store database files. The path structure will be as follows. You may want to change this path structure. Its your choice.\u00a0<\/p>\n<p><strong>Note:<\/strong> Create directories with mongodb user.<\/p>\n<p><strong>hostname1<\/strong><\/p>\n<pre class=\"lang:default decode:true  \">\/mongodb\n         \/shA\n              \/data\n              \/configfile\n         \/shB\n              \/data\n              \/configfile\n         \/shC\n              \/data\n              \/configfile\n         \/cfg\n              \/data\n              \/configfile\n         \/logs\n         \/mongos\n              \/configfile<\/pre>\n<p><strong>hostname2<\/strong><\/p>\n<pre class=\"lang:default decode:true  \">\/mongodb\n         \/shA\n              \/data\n              \/configfile\n         \/shB\n              \/data\n              \/configfile\n         \/shC\n              \/data\n              \/configfile\n         \/cfg\n              \/data\n              \/configfile\n         \/logs\n         \/mongos\n              \/configfile<\/pre>\n<p><strong>hostname3<\/strong><\/p>\n<pre class=\"lang:default decode:true  \">\/mongodb\n         \/shA\n              \/data\n              \/configfile\n         \/shB\n              \/data\n              \/configfile\n         \/shC\n              \/data\n              \/configfile\n         \/cfg\n              \/data\n              \/configfile\n         \/logs\n         \/mongos\n              \/configfile<\/pre>\n<h2>Step 8: Add IP Addresses and Hostnames to \/etc\/hosts<\/h2>\n<p>We need to add hostname informations to \/etc\/hosts in all nodes to access between servers by the hostnames.<\/p>\n<pre class=\"lang:default decode:true \">vi \/etc\/hosts<\/pre>\n<pre class=\"lang:default decode:true\">10.0.0.14     hostname1.domain           hostname1\n10.0.0.15     hostname2.domain           hostname2\n10.0.0.16     hostname3.domian           hostname3\n<\/pre>\n<h2>Step 9: Create a Keyfile<\/h2>\n<p>You can generate a keyfile using any method you choose. For example, the following operation uses openssl to generate a complex pseudo-random 1024 character string to use for a keyfile.<br \/>It then uses chmod to change file permissions to provide read permissions for the file owner only:<\/p>\n<pre class=\"lang:default decode:true\">openssl rand -base64 756 &gt; \/mongodb\/keyfile\nchmod 400 \/mongodb\/keyfile<\/pre>\n<p>Copy the keyfile to each server hosting the sharded cluster members. Ensure that the user running the mongod or mongos instances is the owner of the file and can access the keyfile.<\/p>\n<p><strong>Copy the file to other nodes:<\/strong><\/p>\n<pre class=\"lang:default decode:true  \">scp \/mongodb\/keyfile hostname2:\/mongodb\/keyfile\nscp \/mongodb\/keyfile hostname3:\/mongodb\/keyfile\n<\/pre>\n<h2>Step 10: Configure Config Servers<\/h2>\n<p>We will use a configuration file in this deployment so we will set :<\/p>\n<p><strong>security.keyFile<\/strong> to the keyfile\u2019s path,<br \/><strong>sharding.clusterRole<\/strong> to configsvr<\/p>\n<h3>Sample configuration file for config server:<\/h3>\n<p>There is a sample configuration file \/etc\/mongod.conf or you can use the below one according to our path structure.\u00a0<\/p>\n<h3>Create config-cfg.conf file on each config server<\/h3>\n<pre class=\"lang:default decode:true  \">vi \/mongodb\/cfg\/configfile\/config-cfg.conf<\/pre>\n<p><strong>Content of the files:<\/strong><\/p>\n<p>hostname1:<\/p>\n<pre class=\"lang:default decode:true \"># where to write logging data.\nsystemLog:\n  destination: file\n  logAppend: true\n  path: \"\/mongodb\/logs\/cfg.log\"\n# Where and how to store data.\nstorage:\n  dbPath: \"\/mongodb\/cfg\/data\"\n  directoryPerDB: true\n  journal:\n    enabled: true\n# how the process runs\nprocessManagement:\n  fork: true  # fork and run in background\n# network interfaces\nnet:\n  port: 27000\n  bindIp: hostname1,127.0.0.1\nsecurity:\n  keyFile: \/mongodb\/keyfile\n  authorization: enabled\n#replication:\n#  replSetName: myconfigreplicasetname\nsharding:\n  clusterRole: configsvr\n<\/pre>\n<p>hostname2:<\/p>\n<pre class=\"lang:default decode:true \"># where to write logging data.\nsystemLog:\n  destination: file\n  logAppend: true\n  path: \"\/mongodb\/logs\/cfg.log\"\n# Where and how to store data.\nstorage:\n  dbPath: \"\/mongodb\/cfg\/data\"\n  directoryPerDB: true\n  journal:\n    enabled: true\n# how the process runs\nprocessManagement:\n  fork: true  # fork and run in background\n# network interfaces\nnet:\n  port: 27000\n  bindIp: hostname2,127.0.0.1\nsecurity:\n  keyFile: \/mongodb\/keyfile\n  authorization: enabled\n#replication:\n#  replSetName: myconfigreplicasetname\nsharding:\n  clusterRole: configsvr\n<\/pre>\n<p>hostname3:<\/p>\n<pre class=\"lang:default decode:true\">\/mongodb\/cfg\/configfile\/config-cfg.conf\n# where to write logging data.\nsystemLog:\n  destination: file\n  logAppend: true\n  path: \"\/mongodb\/logs\/cfg.log\"\n# Where and how to store data.\nstorage:\n  dbPath: \"\/mongodb\/cfg\/data\"\n  directoryPerDB: true\n  journal:\n    enabled: true\n# how the process runs\nprocessManagement:\n  fork: true  # fork and run in background\n# network interfaces\nnet:\n  port: 27000\n  bindIp: hostname3,127.0.0.1\nsecurity:\n  keyFile: \/mongodb\/keyfile\n  authorization: enabled\n#replication:\n#  replSetName: myconfigreplicasetname\nsharding:\n  clusterRole: configsvr\n<\/pre>\n<p>You can include additional options as required for your configuration.<\/p>\n<p>For instance, our deployment members are run on different hosts so we specify the net.bindIp setting here.<\/p>\n<h3>Start mongod<\/h3>\n<p>Start the mongod on each config server.<\/p>\n<pre class=\"lang:default decode:true\">mongod --config \/mongodb\/cfg\/configfile\/config-cfg.conf --auth<\/pre>\n<p>Now we have started the mongodb instance but we don&#8217;t have any authenticated users so we can do nothing!!<\/p>\n<p>In this state MongoDB has an exception called &#8220;localhost exception&#8221;. By this we can create only one user and this user can be created only connecting from the localhost.<\/p>\n<pre class=\"lang:default decode:true \">mongo --port 27000\n\nImplicit session: session { \"id\" : UUID(\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\") }\nMongoDB server version: 4.0.4\n&gt; use admin\nswitched to db admin\n&gt; db.createUser({user:'user1', pwd:'passwd', roles:[{role:'userAdminAnyDatabase', db:'admin'}]})\nSuccessfully added user: {\n\"user\" : \"user1\",\n\"roles\" : [\n{\n\"role\" : \"userAdminAnyDatabase\",\n\"db\" : \"admin\"\n}\n]\n}<\/pre>\n<p>When all the replica members start running, it is time to initiate replica sets.<\/p>\n<p><strong>Grant Roles:<\/strong><\/p>\n<p><strong>user1<\/strong> is your username.<\/p>\n<pre class=\"lang:default decode:true \">use admin\ndb.grantRolesToUser( \"user1\", [ \"clusterManager\" ] )\ndb.grantRolesToUser( \"user1\", [ \"dbOwner\" ] )\n<\/pre>\n<p><b>If you want to grant root privilege execute the below command to be able to perform all operations:<\/b><\/p>\n<pre class=\"lang:default decode:true\">use admin\ndb.grantRolesToUser( \"user1\", [ \"root\" ] )\n<\/pre>\n<p><strong>Note:<\/strong> If you want to use db.updateUser command, ensure all roles is available in the command. Because when you execute db.updateUser, it replaces old permissions. Thats why I use db.grantRolesToUser().<\/p>\n<h3>Connect to the one of the members of the config server :<\/h3>\n<pre class=\"lang:default decode:true \">mongo --port 27000 -u user1 -p --authenticationDatabase admin<\/pre>\n<p><strong>Shutdown all the config replica set members:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">use admin\ndb.shutdownServer();<\/pre>\n<p><strong>Add below lines to each config replica set member&#8217;s configuration file:<\/strong><\/p>\n<p>Write myconfigreplicasetname instead of yourreplicasetname in our example. Because we specify our replica set name as &#8220;<strong>myconfigreplicasetname<\/strong>&#8221; in our config file.<\/p>\n<pre class=\"lang:default decode:true\">replication: replSetName: &lt;yourreplicasetname&gt;<\/pre>\n<p><strong>Start mongod instance again:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">mongod --config \/mongodb\/cfg\/configfile\/config-cfg.conf --auth<\/pre>\n<p><strong>Initiate config server&#8217;s replica sets:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">rs.initiate( \n{ \n_id: \"myconfigreplicasetname\", \nconfigsvr: true, members: [ \n{ _id : 0, host : \"hostname1.domain:27000\" }, \n{ _id : 1, host : \"hostname2.domain:27000\" }, \n{ _id : 2, host : \"hostname3.domain:27000\" } \n] \n} \n)<\/pre>\n<h2>Step 11: Configure Shards<\/h2>\n<p>I will create 3 shard shA, shB and shC in my example. There will be 2 copy of each shard. Therefore, we need 9 conf file.<\/p>\n<p>I will create shard shA on hostname1 and shB on hostname2 and shC on hostname3, but this does not mean shA only resides on hostname1. This means that hostname1 will be the primary node of shA and hostname2 will be the primary node of shB and hostname3 will be the primary node of shC. Other nodes of each shard will be secondary nodes.<\/p>\n<p>If you want, you can create all the shards on hostname1. If you perform all operations from hostname1, primary of all shards will be hostname1.<\/p>\n<h3>Shard Distribution in our Example<\/h3>\n<table style=\"height: 100%; width: 100%; border-collapse: collapse;\" border=\"1\">\n<tbody>\n<tr style=\"height: 23px;\">\n<td style=\"width: 33%; height: 52px;\"><strong>hostname1<\/strong><\/td>\n<td style=\"width: 33%; height: 52px;\"><strong>hostname2<\/strong><\/td>\n<td style=\"width: 33%; height: 52px;\"><strong>hostname3<\/strong><\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 31.1194%; height: 60px;\">shA_Primary<\/td>\n<td style=\"width: 32.9351%; height: 60px;\">shA_Secondary<\/td>\n<td style=\"width: 89.6866%; height: 60px;\">shA_Secondary<\/td>\n<\/tr>\n<tr style=\"height: 23px;\">\n<td style=\"width: 31.1194%; height: 71px;\">shB_Secondary<\/td>\n<td style=\"width: 32.9351%; height: 71px;\">shB_Primary<\/td>\n<td style=\"width: 89.6866%; height: 71px;\">shB_Secondary<\/td>\n<\/tr>\n<tr style=\"height: 52px;\">\n<td style=\"width: 31.1194%; height: 52px;\">shC_Secondary<\/td>\n<td style=\"width: 32.9351%; height: 52px;\">shC_Secondary<\/td>\n<td style=\"width: 89.6866%; height: 52px;\">shC_Primary<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Create Shard shA on hostname1<\/h2>\n<p><strong>Create a config file for shard shA:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">vi \/mongodb\/shA\/configfile\/shard-cfg.conf<\/pre>\n<p><strong>Content of the file:<\/strong><\/p>\n<pre class=\"lang:default decode:true \"># where to write logging data.\nsystemLog:\n  destination: file\n  logAppend: true\n  path: \"\/mongodb\/logs\/shA.log\"\n# Where and how to store data.\nstorage:\n  dbPath: \"\/mongodb\/shA\/data\"\n  directoryPerDB: true\n  journal:\n    enabled: true\n# how the process runs\nprocessManagement:\n  fork: true  # fork and run in background\n# network interfaces\nnet:\n  port: 27001\n  bindIp: hostname1,127.0.0.1\nsecurity:\n  keyFile: \/mongodb\/keyfile\n  authorization: enabled\n#replication:\n#  replSetName: shA\nsharding:\n  clusterRole: shardsvr\n<\/pre>\n<p><strong>Note: <\/strong>Copy this file to hostname2 and hostname3 and change hostname.<\/p>\n<h3>Start mongod<\/h3>\n<p>Start the mongod on each shard server specifying the &#8211;config option and the path to the configuration file.<\/p>\n<pre class=\"lang:default decode:true\">mongod --config \/mongodb\/shA\/configfile\/shard-cfg.conf --auth<\/pre>\n<p>Now we have started the mongodb instance but we don&#8217;t have any authenticated users so we can do nothing!!<\/p>\n<p>In this state MongoDB has an exception called &#8220;localhost exception&#8221;. By this we can create only one user and this user can be created only connecting from the localhost.<\/p>\n<pre class=\"lang:default decode:true \">mongo --port 27001\n\nImplicit session: session { \"id\" : UUID(\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\") }\nMongoDB server version: 4.0.4\n&gt; use admin\nswitched to db admin\n&gt; db.createUser({user:'user1', pwd:'passwd', roles:[{role:'userAdminAnyDatabase', db:'admin'}]})\nSuccessfully added user: {\n\"user\" : \"user1\",\n\"roles\" : [\n{\n\"role\" : \"userAdminAnyDatabase\",\n\"db\" : \"admin\"\n}\n]\n}<\/pre>\n<p><strong>Grant Roles:<\/strong><\/p>\n<p><strong>user1<\/strong> is your username.<\/p>\n<pre class=\"lang:default decode:true \">use admin\ndb.grantRolesToUser( \"user1\", [ \"clusterManager\" ] )\ndb.grantRolesToUser( \"user1\", [ \"dbOwner\" ] )<\/pre>\n<p><b>If you want to grant root privilege execute the below command to be able to perform all operations:<\/b><\/p>\n<pre class=\"lang:default decode:true \">use admin\ndb.grantRolesToUser( \"user1\", [ \"root\" ] )\n<\/pre>\n<h3>Connect to the one of the members of the shard server :<\/h3>\n<pre class=\"lang:default decode:true \">mongo --port 27001 -u user1 -p --authenticationDatabase admin<\/pre>\n<p><strong>Shutdown all the shard replica set members:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">use admin\ndb.shutdownServer();<\/pre>\n<p><strong>Add below lines to each shard replica set member&#8217;s configuration file:<\/strong><\/p>\n<p>Write shA instead of &lt;yourreplicasetname&gt; in our example.<\/p>\n<pre class=\"lang:default decode:true\">replication: replSetName: &lt;yourreplicasetname&gt;<\/pre>\n<p><strong>Start mongod instance again:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">mongod --config \/mongodb\/shA\/configfile\/shard-cfg.conf --auth<\/pre>\n<p><strong>Initiate shA:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">rs.initiate(\n{\n_id : \"shA\",\nmembers: [\n{ _id : 0, host : \"hostname1.domain:27001\" },\n{ _id : 1, host : \"hostname2.domain:27001\" },\n{ _id : 2, host : \"hostname3.domain:27001\" }\n]\n}\n)<\/pre>\n<h2>Create Shard shB on hostname2<\/h2>\n<p><strong>Create a config file for shard shB:<\/strong><\/p>\n<pre class=\"lang:default decode:true  \">vi \/mongodb\/shB\/configfile\/shard-cfg.conf<\/pre>\n<p><strong>Content of the file:<\/strong><\/p>\n<pre class=\"lang:default decode:true\"># where to write logging data.\nsystemLog:\n  destination: file\n  logAppend: true\n  path: \"\/mongodb\/logs\/shB.log\"\n# Where and how to store data.\nstorage:\n  dbPath: \"\/mongodb\/shB\/data\"\n  directoryPerDB: true\n  journal:\n    enabled: true\n# how the process runs\nprocessManagement:\n  fork: true  # fork and run in background\n# network interfaces\nnet:\n  port: 27002\n  bindIp: hostname2,127.0.0.1\nsecurity:\n  keyFile: \/mongodb\/keyfile\n  authorization: enabled\n#replication:\n#  replSetName: shB\nsharding:\n  clusterRole: shardsvr\n<\/pre>\n<p><strong>Note:<\/strong> Copy this file to hostname1 and hostname3 and change hostname.<\/p>\n<h3>Start mongod<\/h3>\n<p>Start the mongod on each shard server specifying the &#8211;config option and the path to the configuration file.<\/p>\n<pre class=\"lang:default decode:true \">mongod --config \/mongodb\/shB\/configfile\/shard-cfg.conf --auth<\/pre>\n<p>Now we have started the mongodb instance but we don&#8217;t have any authenticated users so we can do nothing!!<\/p>\n<p>In this state MongoDB has an exception called &#8220;localhost exception&#8221;. By this we can create only one user and this user can be created only connecting from the localhost.<\/p>\n<pre class=\"lang:default decode:true\">mongo --port 27002\n\nImplicit session: session { \"id\" : UUID(\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\") }\nMongoDB server version: 4.0.4\n&gt; use admin\nswitched to db admin\n&gt; db.createUser({user:'user1', pwd:'passwd', roles:[{role:'userAdminAnyDatabase', db:'admin'}]})\nSuccessfully added user: {\n\"user\" : \"user1\",\n\"roles\" : [\n{\n\"role\" : \"userAdminAnyDatabase\",\n\"db\" : \"admin\"\n}\n]\n}<\/pre>\n<p><strong>Grant Roles:<\/strong><\/p>\n<p><strong>user1<\/strong> is your username.<\/p>\n<pre class=\"lang:default decode:true\">use admin\ndb.grantRolesToUser( \"user1\", [ \"clusterManager\" ] )\ndb.grantRolesToUser( \"user1\", [ \"dbOwner\" ] )<\/pre>\n<p><b>If you want to grant root privilege execute the below command to be able to perform all operations:<\/b><\/p>\n<pre class=\"lang:default decode:true \">use admin\ndb.grantRolesToUser( \"user1\", [ \"root\" ] )\n<\/pre>\n<h3>Connect to the one of the members of the shard server :<\/h3>\n<pre class=\"lang:default decode:true\">mongo --port 27002 -u user1 -p --authenticationDatabase admin<\/pre>\n<p><strong>Shutdown all the shard replica set members:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">use admin\ndb.shutdownServer();<\/pre>\n<p><strong>Add below lines to each shard replica set member&#8217;s configuration file:<\/strong><\/p>\n<p>Write shB instead of &lt;yourreplicasetname&gt; in our example.<\/p>\n<pre class=\"lang:default decode:true\">replication: replSetName: &lt;yourreplicasetname&gt;<\/pre>\n<p><strong>Start mongod instance again:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">mongod --config \/mongodb\/shB\/configfile\/shard-cfg.conf --auth<\/pre>\n<p><strong>Initiate shB:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">rs.initiate(\n{\n_id : \"shB\",\nmembers: [\n{ _id : 0, host : \"hostname1.domain:27002\" },\n{ _id : 1, host : \"hostname2.domain:27002\" },\n{ _id : 2, host : \"hostname3.domain:27002\" }\n]\n}\n)<\/pre>\n<h2>Create Shard shC on hostname3<\/h2>\n<p><strong>Create a config file for shard shC:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">vi \/mongodb\/shC\/configfile\/shard-cfg.conf<\/pre>\n<p><strong>Content of the file:<\/strong><\/p>\n<pre class=\"lang:default decode:true\"># where to write logging data.\nsystemLog:\n  destination: file\n  logAppend: true\n  path: \"\/mongodb\/logs\/shC.log\"\n# Where and how to store data.\nstorage:\n  dbPath: \"\/mongodb\/shC\/data\"\n  directoryPerDB: true\n  journal:\n    enabled: true\n# how the process runs\nprocessManagement:\n  fork: true  # fork and run in background\n# network interfaces\nnet:\n  port: 27003\n  bindIp: hostname3,127.0.0.1\nsecurity:\n  keyFile: \/mongodb\/keyfile\n  authorization: enabled\n#replication:\n#  replSetName: shC\nsharding:\n  clusterRole: shardsvr\n<\/pre>\n<p><strong>Note:<\/strong> Copy this file to hostname1 and hostname2 and change hostname.<\/p>\n<h3>Start mongod<\/h3>\n<p>Start the mongod on each shard server specifying the &#8211;config option and the path to the configuration file.<\/p>\n<pre class=\"lang:default decode:true \">mongod --config \/mongodb\/shC\/configfile\/shard-cfg.conf --auth<\/pre>\n<p>Now we have started the mongodb instance but we don&#8217;t have any authenticated users so we can do nothing!!<\/p>\n<p>In this state MongoDB has an exception called &#8220;localhost exception&#8221;. By this we can create only one user and this user can be created only connecting from the localhost.<\/p>\n<pre class=\"lang:default decode:true\">mongo --port 27003\n\nImplicit session: session { \"id\" : UUID(\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\") }\nMongoDB server version: 4.0.4\n&gt; use admin\nswitched to db admin\n&gt; db.createUser({user:'user1', pwd:'passwd', roles:[{role:'userAdminAnyDatabase', db:'admin'}]})\nSuccessfully added user: {\n\"user\" : \"user1\",\n\"roles\" : [\n{\n\"role\" : \"userAdminAnyDatabase\",\n\"db\" : \"admin\"\n}\n]\n}<\/pre>\n<p><strong>Grant Roles:<\/strong><\/p>\n<p><strong>user1<\/strong> is your username.<\/p>\n<pre class=\"lang:default decode:true \">use admin\ndb.grantRolesToUser( \"user1\", [ \"clusterManager\" ] )\ndb.grantRolesToUser( \"user1\", [ \"dbOwner\" ] )<\/pre>\n<p><b>If you want to grant root privilege execute the below command to be able to perform all operations:<\/b><\/p>\n<pre class=\"lang:default decode:true \">use admin\ndb.grantRolesToUser( \"user1\", [ \"root\" ] )\n<\/pre>\n<h3>Connect to the one of the members of the shard server :<\/h3>\n<pre class=\"lang:default decode:true \">mongo --port 27003 -u user1 -p --authenticationDatabase admin<\/pre>\n<p><strong>Shutdown all the shard replica set members:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">use admin\ndb.shutdownServer();<\/pre>\n<p><strong>Add below lines to each shard replica set member&#8217;s configuration file:<\/strong><\/p>\n<p>Write shC instead of &lt;yourreplicasetname&gt; in our example.<\/p>\n<pre class=\"lang:default decode:true\">replication: replSetName: &lt;yourreplicasetname&gt;<\/pre>\n<p><strong>Start mongod instance again:<\/strong><\/p>\n<pre class=\"lang:default decode:true \">mongod --config \/mongodb\/shC\/configfile\/shard-cfg.conf --auth<\/pre>\n<p><strong>Initiate shC:<\/strong><\/p>\n<pre class=\"lang:default decode:true\">rs.initiate(\n{\n_id : \"shC\",\nmembers: [\n{ _id : 0, host : \"hostname1.domain:27003\" },\n{ _id : 1, host : \"hostname2.domain:27003\" },\n{ _id : 2, host : \"hostname3.domain:27003\" }\n]\n}\n)<\/pre>\n<h2>Step 12: Start Mongoses<\/h2>\n<p>Now it&#8217;s time to run mongoses. There is no replica for mongoses. But you can multiplies mongoses. I will create 3 mongoses in our example.<\/p>\n<h3>Create a mongos file on all mongos servers:<\/h3>\n<pre class=\"lang:default decode:true \">vi \/mongodb\/mongos\/configfile\/mongos-cfg.conf<\/pre>\n<p><strong>mongos config file is like this:<\/strong><\/p>\n<pre class=\"lang:default decode:true \"># where to write logging data.\nsystemLog:\n destination: file\n logAppend: true\n path: \"\/mongodb\/logs\/mongos.log\"\n\n# how the process runs\nprocessManagement:\n fork: true # fork and run in background\n\n# network interfaces\nnet:\n port: 27017\n bindIp: hostname1,127.0.0.1\n maxIncomingConnections: 5000\n\nsecurity:\n keyFile: \/mongodb\/keyfile\n\nsharding:\n configDB: \"myconfigreplicasetname\/hostname1.domain:27000,hostname2.domain:27000,hostname3.domain:27000\"<\/pre>\n<p><strong>Note:<\/strong> Copy this file to other mongos servers and change hostnames.<\/p>\n<h3>To run the mongos process:<\/h3>\n<pre class=\"lang:default decode:true  \">mongos --config \/mongodb\/mongos\/configfile\/mongos-cfg.conf<\/pre>\n<h2><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-13690 aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-22.png\" alt=\"\" width=\"660\" height=\"88\" \/><\/h2>\n<h2>Step 13: Check All Mongos Components Started<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-13692 aligncenter\" src=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-23.png\" alt=\"\" width=\"1300\" height=\"192\" \/><\/p>\n<h2>Step 14: Connect to mongos and add shards<\/h2>\n<pre class=\"lang:default decode:true \">mongo --port 27017 -u user1 -p --authenticationDatabase admin<\/pre>\n<pre class=\"lang:default decode:true\">sh.addShard( \"shA\/hostname1.domain:27001,hostname2.domain:27001,hostname3.domain:27001\")\nsh.addShard( \"shB\/hostname1.domain:27002,hostname2.domain:27002,hostname3.domain:27002\")\nsh.addShard( \"shC\/hostname1.domain:27003,hostname2.domain:27003,hostname3.domain:27003\")<\/pre>\n<p><strong>Note:<\/strong> shA,shB and shC our replica set names. If your replica set names is different, change the script above according to your replica set names.<\/p>\n<p><strong>Check sharded cluster status:<\/strong><\/p>\n<p>Connect mongos and run below command.<\/p>\n<pre class=\"lang:default decode:true \">sh.status()<\/pre>\n<p>The sharded replica set configuration is done. Now you can restore a dump and start working on dbs \ud83d\ude42<\/p>\n<p>You may want to read below articles:<\/p>\n<p>&#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2018\/08\/09\/back-up-a-sharded-cluster-with-file-system-snapshots\/\" target=\"_blank\" rel=\"noopener noreferrer\">Back Up a Sharded Cluster with File System Snapshots<\/a>&#8220;,<\/p>\n<p>&#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2018\/08\/09\/automatizing-backup-process-on-sharded-clusters\/\" target=\"_blank\" rel=\"noopener noreferrer\">Automatizing backup process on sharded clusters<\/a>&#8220;,<\/p>\n<p>&#8220;<a href=\"https:\/\/dbtut.com\/index.php\/2018\/08\/09\/restore-a-sharded-cluster-with-database-dumps-in-mongodb\/\" target=\"_blank\" rel=\"noopener noreferrer\">Restore a Sharded Cluster with Database Dumps in MongoDB<\/a>&#8220;<\/p>\n\n<div class=\"pvc_clear\"><\/div><p id=\"pvc_stats_13475\" class=\"pvc_stats all  \" data-element-id=\"13475\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p><div class=\"pvc_clear\"><\/div>","protected":false},"excerpt":{"rendered":"<p>As you know security is one of the key points during database administration. In MongoDB sharded clusters security between components of the cluster is provided by Internal authentication. In this tutorial I will deploy a sharded cluster and enable internal authentication by using a keyfile. Enforcing internal authentication also enforces user access control. To connect &hellip;<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_13475\" class=\"pvc_stats all  \" data-element-id=\"13475\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/dbtut.com\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":13,"featured_media":13477,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[1306,1388],"tags":[5373,5370,5372,5378,5366,5354,5355,5353,5235,5384,5385,5361,5380,5383,5382,5349,7882,7892,5374,5381,5360,5358,5356,5391,5375,5357,5386,5387,5389,5390,7887,5352,7881,7888,7885,7890,7886,7883,7884,5369,5371,5388,5377,5376,5335,7891,7889,1374,2753,5337,5363,5365,5359,5328,5368,5362,5364,5379,5336,5347,5331,5334,5333,5332,5338],"class_list":["post-13475","post","type-post","status-publish","format-standard","has-post-thumbnail","","category-mongodb","category-nosql","tag-add-shards-to-sharded-cluster","tag-configuration-server-config-file-sample","tag-connect-to-mongos","tag-create-user-and-password-for-mongodb","tag-db-shutdownserver","tag-deploy-sharded-cluster","tag-deploy-sharded-cluster-in-mongodb","tag-deploy-sharded-cluster-with-keyfile-access-control","tag-disable-selinux","tag-enable-authentication-in-mongodb","tag-enable-mongodb-authentication","tag-grant-role-mongodb","tag-how-do-i-create-user-and-password-in-mongodb","tag-how-do-i-enable-authentication-in-mongodb","tag-how-do-i-give-a-user-permission-in-mongodb","tag-how-does-mongodb-sharding-work","tag-how-to-install-mongodb-sharded-cluster","tag-how-to-install-mongodb-sharded-cluster-with-keyfile-access-control","tag-how-to-install-sharded-cluster-in-mongodb","tag-how-to-secure-mongodb-with-username-and-password","tag-initiate-mongodb","tag-install-mongodb-community-edition","tag-install-mongodb-packages","tag-install-mongodb-sharded-cluster","tag-install-sharded-cluster","tag-install-the-mongodb-packages","tag-keyfile-access-control","tag-keyfile-access-control-in-mongodb","tag-keyfile-authentication","tag-keyfile-authentication-in-mongodb","tag-mongodb-setup-sharded-cluster","tag-mongodb-shard","tag-mongodb-sharded-cluster","tag-mongodb-sharded-cluster-installation","tag-mongodb-sharded-cluster-setup","tag-mongodb-sharded-cluster-vs-replica-set","tag-mongodb-sharding","tag-mongodb-sharding-configuration","tag-mongodb-sharding-installation","tag-mongos-config-file","tag-mongos-config-file-sample","tag-securing-mongodb","tag-security-in-mongodb","tag-setup-sharded-cluster","tag-sharded-cluster","tag-sharded-cluster-mongodb-tutorial","tag-sharded-cluster-vs-replica-set","tag-sharded-clusters","tag-sharding-in-mongodb","tag-shards-in-mongodb","tag-shutdown-mongodb","tag-shutdown-mongodb-shards","tag-start-mongod","tag-start-mongodb","tag-start-mongoses","tag-stop-mongodb","tag-stop-mongodb-replicas","tag-user-and-password-in-mongodb","tag-what-is-a-shard-in-mongodb","tag-what-is-shard-cluster","tag-what-is-shard-in-mongodb","tag-what-is-sharded-cluster-in-mongodb","tag-what-is-sharding-in-mongodb","tag-what-is-shards-in-mongodb","tag-whaty-is-a-shard"],"aioseo_notices":[],"a3_pvc":{"activated":true,"total_views":856,"today_views":2},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS - Database Tutorials<\/title>\n<meta name=\"description\" content=\"Deploy Sharded Cluster with Keyfile Access Control on Red Hat Enterprise Linux or CentOS Linux\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS - Database Tutorials\" \/>\n<meta property=\"og:description\" content=\"Deploy Sharded Cluster with Keyfile Access Control on Red Hat Enterprise Linux or CentOS Linux\" \/>\n<meta property=\"og:url\" content=\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/\" \/>\n<meta property=\"og:site_name\" content=\"Database Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-11-08T12:25:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-14T06:56:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png\" \/>\n\t<meta property=\"og:image:width\" content=\"803\" \/>\n\t<meta property=\"og:image:height\" content=\"514\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Selcen Sahin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Selcen Sahin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/\"},\"author\":{\"name\":\"Selcen Sahin\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/87438a648f4fcee5ebc050fa2d1b68ca\"},\"headline\":\"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS\",\"datePublished\":\"2019-11-08T12:25:18+00:00\",\"dateModified\":\"2020-01-14T06:56:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/\"},\"wordCount\":1582,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png\",\"keywords\":[\"add shards to sharded cluster\",\"configuration server config file sample\",\"Connect to mongos\",\"create user and password for mongodb\",\"db.shutdownServer()\",\"Deploy Sharded Cluster\",\"Deploy Sharded Cluster in MongoDB\",\"Deploy Sharded Cluster with Keyfile Access Control\",\"Disable selinux\",\"enable authentication in MongoDB\",\"Enable MongoDB Authentication\",\"grant role mongodb\",\"how do I create user and password in mongodb\",\"How do I enable authentication in MongoDB?\",\"How do I give a user permission in MongoDB?\",\"How does MongoDB Sharding work?\",\"how to install mongodb sharded cluster\",\"How To Install Mongodb Sharded Cluster with Keyfile Access Control\",\"How To Install Sharded Cluster in MongoDb\",\"How to secure MongoDB with username and password\",\"initiate mongodb\",\"Install MongoDB Community Edition\",\"Install MongoDB packages\",\"Install MongoDB Sharded Cluster\",\"Install Sharded Cluster\",\"Install the MongoDB packages\",\"Keyfile Access Control\",\"Keyfile Access Control in mongodb\",\"Keyfile Authentication\",\"Keyfile Authentication in MongoDB\",\"mongodb setup sharded cluster\",\"mongodb shard\",\"mongodb sharded cluster\",\"mongodb sharded cluster installation\",\"mongodb sharded cluster setup\",\"mongodb sharded cluster vs replica set\",\"mongodb sharding\",\"mongodb sharding configuration\",\"mongodb sharding installation\",\"mongos config file\",\"mongos config file sample\",\"Securing MongoDB\",\"security in mongodb\",\"Setup Sharded Cluster\",\"Sharded Cluster\",\"sharded cluster mongodb tutorial\",\"sharded cluster vs replica set\",\"sharded clusters\",\"Sharding in MongoDB\",\"Shards in mongodb\",\"shutdown mongodb\",\"shutdown mongodb shards\",\"Start mongod\",\"Start MongoDB\",\"Start Mongoses\",\"stop mongodb\",\"stop mongodb replicas\",\"user and password in mongodb\",\"What is a Shard in MongoDB\",\"What is shard cluster?\",\"What is Shard in MongoDB\",\"What is Sharded Cluster in MongoDB\",\"What is Sharding in MongoDB\",\"What is Shards in MongoDB\",\"Whaty is a shard\"],\"articleSection\":[\"MongoDB\",\"NoSQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/\",\"url\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/\",\"name\":\"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS - Database Tutorials\",\"isPartOf\":{\"@id\":\"https:\/\/dbtut.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png\",\"datePublished\":\"2019-11-08T12:25:18+00:00\",\"dateModified\":\"2020-01-14T06:56:49+00:00\",\"description\":\"Deploy Sharded Cluster with Keyfile Access Control on Red Hat Enterprise Linux or CentOS Linux\",\"breadcrumb\":{\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#primaryimage\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png\",\"width\":803,\"height\":514},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/dbtut.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/dbtut.com\/#website\",\"url\":\"https:\/\/dbtut.com\/\",\"name\":\"Database Tutorials\",\"description\":\"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux\",\"publisher\":{\"@id\":\"https:\/\/dbtut.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/dbtut.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/dbtut.com\/#organization\",\"name\":\"dbtut\",\"url\":\"https:\/\/dbtut.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"contentUrl\":\"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg\",\"width\":223,\"height\":36,\"caption\":\"dbtut\"},\"image\":{\"@id\":\"https:\/\/dbtut.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/87438a648f4fcee5ebc050fa2d1b68ca\",\"name\":\"Selcen Sahin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/dbtut.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/403f3e1ed22269aba4b27e275764c81032219d846808ea020c5512c9ffe300f6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/403f3e1ed22269aba4b27e275764c81032219d846808ea020c5512c9ffe300f6?s=96&d=mm&r=g\",\"caption\":\"Selcen Sahin\"},\"url\":\"https:\/\/dbtut.com\/index.php\/author\/selcensahin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS - Database Tutorials","description":"Deploy Sharded Cluster with Keyfile Access Control on Red Hat Enterprise Linux or CentOS Linux","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/","og_locale":"en_US","og_type":"article","og_title":"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS - Database Tutorials","og_description":"Deploy Sharded Cluster with Keyfile Access Control on Red Hat Enterprise Linux or CentOS Linux","og_url":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/","og_site_name":"Database Tutorials","article_published_time":"2019-11-08T12:25:18+00:00","article_modified_time":"2020-01-14T06:56:49+00:00","og_image":[{"width":803,"height":514,"url":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png","type":"image\/png"}],"author":"Selcen Sahin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Selcen Sahin","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#article","isPartOf":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/"},"author":{"name":"Selcen Sahin","@id":"https:\/\/dbtut.com\/#\/schema\/person\/87438a648f4fcee5ebc050fa2d1b68ca"},"headline":"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS","datePublished":"2019-11-08T12:25:18+00:00","dateModified":"2020-01-14T06:56:49+00:00","mainEntityOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/"},"wordCount":1582,"commentCount":0,"publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png","keywords":["add shards to sharded cluster","configuration server config file sample","Connect to mongos","create user and password for mongodb","db.shutdownServer()","Deploy Sharded Cluster","Deploy Sharded Cluster in MongoDB","Deploy Sharded Cluster with Keyfile Access Control","Disable selinux","enable authentication in MongoDB","Enable MongoDB Authentication","grant role mongodb","how do I create user and password in mongodb","How do I enable authentication in MongoDB?","How do I give a user permission in MongoDB?","How does MongoDB Sharding work?","how to install mongodb sharded cluster","How To Install Mongodb Sharded Cluster with Keyfile Access Control","How To Install Sharded Cluster in MongoDb","How to secure MongoDB with username and password","initiate mongodb","Install MongoDB Community Edition","Install MongoDB packages","Install MongoDB Sharded Cluster","Install Sharded Cluster","Install the MongoDB packages","Keyfile Access Control","Keyfile Access Control in mongodb","Keyfile Authentication","Keyfile Authentication in MongoDB","mongodb setup sharded cluster","mongodb shard","mongodb sharded cluster","mongodb sharded cluster installation","mongodb sharded cluster setup","mongodb sharded cluster vs replica set","mongodb sharding","mongodb sharding configuration","mongodb sharding installation","mongos config file","mongos config file sample","Securing MongoDB","security in mongodb","Setup Sharded Cluster","Sharded Cluster","sharded cluster mongodb tutorial","sharded cluster vs replica set","sharded clusters","Sharding in MongoDB","Shards in mongodb","shutdown mongodb","shutdown mongodb shards","Start mongod","Start MongoDB","Start Mongoses","stop mongodb","stop mongodb replicas","user and password in mongodb","What is a Shard in MongoDB","What is shard cluster?","What is Shard in MongoDB","What is Sharded Cluster in MongoDB","What is Sharding in MongoDB","What is Shards in MongoDB","Whaty is a shard"],"articleSection":["MongoDB","NoSQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/","url":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/","name":"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS - Database Tutorials","isPartOf":{"@id":"https:\/\/dbtut.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#primaryimage"},"image":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#primaryimage"},"thumbnailUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png","datePublished":"2019-11-08T12:25:18+00:00","dateModified":"2020-01-14T06:56:49+00:00","description":"Deploy Sharded Cluster with Keyfile Access Control on Red Hat Enterprise Linux or CentOS Linux","breadcrumb":{"@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#primaryimage","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2019\/11\/Ads\u0131z-10.png","width":803,"height":514},{"@type":"BreadcrumbList","@id":"https:\/\/dbtut.com\/index.php\/2019\/11\/08\/deploy-sharded-cluster-with-keyfile-access-control-on-red-hat-enterprise-linux-or-centos-linux\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/dbtut.com\/"},{"@type":"ListItem","position":2,"name":"How To Install Mongodb Sharded Cluster with Keyfile Access Control on Red Hat or CentOS"}]},{"@type":"WebSite","@id":"https:\/\/dbtut.com\/#website","url":"https:\/\/dbtut.com\/","name":"Database Tutorials","description":"MSSQL, Oracle, PostgreSQL, MySQL, MariaDB, DB2, Sybase, Teradata, Big Data, NOSQL, MongoDB, Couchbase, Cassandra, Windows, Linux","publisher":{"@id":"https:\/\/dbtut.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/dbtut.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/dbtut.com\/#organization","name":"dbtut","url":"https:\/\/dbtut.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/","url":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","contentUrl":"https:\/\/dbtut.com\/wp-content\/uploads\/2021\/02\/dbtutlogo.jpg","width":223,"height":36,"caption":"dbtut"},"image":{"@id":"https:\/\/dbtut.com\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/dbtut.com\/#\/schema\/person\/87438a648f4fcee5ebc050fa2d1b68ca","name":"Selcen Sahin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/dbtut.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/403f3e1ed22269aba4b27e275764c81032219d846808ea020c5512c9ffe300f6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/403f3e1ed22269aba4b27e275764c81032219d846808ea020c5512c9ffe300f6?s=96&d=mm&r=g","caption":"Selcen Sahin"},"url":"https:\/\/dbtut.com\/index.php\/author\/selcensahin\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/13475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/comments?post=13475"}],"version-history":[{"count":0,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/posts\/13475\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media\/13477"}],"wp:attachment":[{"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/media?parent=13475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/categories?post=13475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dbtut.com\/index.php\/wp-json\/wp\/v2\/tags?post=13475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}