{"componentChunkName":"component---src-templates-post-js","path":"/posts/mongodb-cluster-setup-centos-7-47hh/","result":{"data":{"sitePage":{"id":"SitePage /posts/mongodb-cluster-setup-centos-7-47hh/"}},"pageContext":{"url":"/posts/mongodb-cluster-setup-centos-7-47hh/","relativePath":"posts/mongodb-cluster-setup-centos-7-47hh.md","relativeDir":"posts","base":"mongodb-cluster-setup-centos-7-47hh.md","name":"mongodb-cluster-setup-centos-7-47hh","frontmatter":{"title":"MongoDB Cluster Setup Centos","date":"2020-08-10T14:19:12.601Z","excerpt":"We will be setting up Mongo DB for high availability using 3 virtual machines   1) Mongo Primary (t3a...","thumb_img_path":"https://res.cloudinary.com/practicaldev/image/fetch/s--ZcaStyBD--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/bqijylyalckck382nujy.png","comments_count":0,"positive_reactions_count":4,"tags":["mongodb","centos","opensource","linux"],"canonical_url":"https://dev.to/tomahawkpilot/mongodb-cluster-setup-centos-7-47hh","template":"post"},"html":"<p>We will be setting up Mongo DB for high availability using 3 virtual machines </p>\n<ol>\n<li>Mongo Primary (t3a.medium)</li>\n<li>Mongo Secondary (t3a.medium)</li>\n<li>Mongo Arbiter (t3a.small)</li>\n</ol>\n<h2>Let's begin the system preparations</h2>\n<h3>The following setup has to be done in all 3 machines</h3>\n<ul>\n<li>login as sudo in each machine</li>\n</ul>\n<pre><code>sudo --login \n</code></pre>\n<ul>\n<li>Update centos packages to the latest version\nCentos 7</li>\n</ul>\n<pre><code>yum update -y\n</code></pre>\n<p>Centos 8</p>\n<pre><code>dnf update -y\n</code></pre>\n<ul>\n<li>install Nano editor (I am a Nano fan)\nCentos 7</li>\n</ul>\n<pre><code>yum install nano -y\n</code></pre>\n<p>Centos 8</p>\n<pre><code>dnf install nano -y\n</code></pre>\n<ul>\n<li>add hosts values\nedit the\n<code>nano /etc/hosts</code>\nfile to add the following entries</li>\n</ul>\n<pre><code>172.31.28.16 mongo1\n172.31.31.194 mongo2\n172.31.25.65 mongo3\n</code></pre>\n<h2>important Step</h2>\n<p>Disable SELinux as it has breaking effects  on internode connection\nedit\n<code>/etc/selinux/config</code></p>\n<p>change </p>\n<pre><code>SELINUX=disabled\n</code></pre>\n<p>do the above step in all 3 machines and make sure to do a reboot by running </p>\n<pre><code>reboot\n</code></pre>\n<h2>Now Install Mongo</h2>\n<ul>\n<li>Configure the package management system</li>\n</ul>\n<p>Create a\n<code>nano /etc/yum.repos.d/mongodb-org-4.4.repo</code>\nfile so that you can install MongoDB directly using yum</p>\n<p>Add the following content to it.</p>\n<pre><code>[mongodb-org-4.4]\nname=MongoDB Repository\nbaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/\ngpgcheck=1\nenabled=1\ngpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc\n</code></pre>\n<ul>\n<li>Install Mongo DB latest Stable\nCentos 7</li>\n</ul>\n<pre><code>yum install -y mongodb-org\n</code></pre>\n<p>Centos 8</p>\n<pre><code>dnf install -y mongodb-org\n</code></pre>\n<p>Before we can begin cluster Setup lets prepare mongo</p>\n<h3>Enable Mongo Authentication</h3>\n<p>To add authentication to mongo add the following lines to </p>\n<p><code>nano /etc/mongod.conf</code></p>\n<pre><code>security:\n    authorization: enabled\n</code></pre>\n<p>Then do a restart </p>\n<pre><code>service mongod restart\n</code></pre>\n<ul>\n<li>let's create mongodb user\nOpen mongo shell</li>\n</ul>\n<p><code>mongo</code></p>\n<p>the following commands</p>\n<pre><code>use admin\n</code></pre>\n<pre><code>db.createUser({\n    user: \"tomahawk\",\n    pwd: \"tomahawkPilot\",\n    roles: [ \n        { \n            role: \"userAdminAnyDatabase\", \n            db: \"admin\" \n        },\n        {\n            role: \"clusterAdmin\",\n             db: \"admin\"\n        },\n        {\n            role: \"root,\n            db: \"admin\n        }\n    ]\n})\n</code></pre>\n<h2>Now let's Begin the Replication Configuration</h2>\n<ul>\n<li>Add replSet to mongod.conf in all 3 machines\nedit your\n<code>nano /etc/mongod.conf</code>\nfile </li>\n</ul>\n<pre><code>replication:\n  replSetName: rs0\n</code></pre>\n<h2>Keyfile Access Control on Replica Set</h2>\n<p>navigate to your mongo path</p>\n<pre><code>/var/lib/mongo in my case\n</code></pre>\n<p>Use the following command to generate a keyfile</p>\n<pre><code>openssl rand -base64 756 > keyfile\n</code></pre>\n<p>Copy the key file to all 3 machines\nadd Appropriate permissions</p>\n<pre><code>chmod 400 keyfile\nchown mongod:mongod keyfile\n</code></pre>\n<p>Now add the keyfile to your\n<code>nano /etc/mongod.conf</code>\nfile</p>\n<pre><code>security:\n    authorization: enabled\n    keyFile: /var/lib/mongo/keyfile\n</code></pre>\n<ul>\n<li>do a restart of all mongod services</li>\n</ul>\n<pre><code>systemctl restart mongod\n</code></pre>\n<p>for the changes in replication to take effect before initializing the replica</p>\n<ul>\n<li>On mongo1</li>\n</ul>\n<pre><code>use admin\ndb.auth(\"tomahawk\",\"tomahawkPilot\");\nrs.initiate(\n   {\n      _id: \"rs0\",\n      version: 1,\n      members: [\n         { _id: 0, host : \"mongo1:27017\" }\n      ]\n   }\n)\n</code></pre>\n<p>You can always run </p>\n<pre><code>mongo --port 27017 -u tomahawk --authenticationDatabase 'admin' -p tomahawkPilot\n</code></pre>\n<p>to directly login to the cluster</p>\n<p>Now let's create the replica set</p>\n<pre><code>rs.add(\"mongo2:27017\");\n</code></pre>\n<p>Check connection status by running</p>\n<pre><code>rs.status()\n</code></pre>\n<p>On Successful connection, you will get a response </p>\n<pre><code>rs.status()\n{\n        \"set\" : \"rs0\",\n        \"date\" : ISODate(\"2020-08-10T14:03:42.405Z\"),\n        \"myState\" : 1,\n        \"term\" : NumberLong(2),\n        \"syncSourceHost\" : \"\",\n        \"syncSourceId\" : -1,\n        \"heartbeatIntervalMillis\" : NumberLong(2000),\n        \"majorityVoteCount\" : 2,\n        \"writeMajorityCount\" : 2,\n        \"votingMembersCount\" : 2,\n        \"writableVotingMembersCount\" : 2,\n        \"optimes\" : {\n                \"lastCommittedOpTime\" : {\n                        \"ts\" : Timestamp(1597068221, 2),\n                        \"t\" : NumberLong(2)\n                },\n                \"lastCommittedWallTime\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"readConcernMajorityOpTime\" : {\n                        \"ts\" : Timestamp(1597068221, 2),\n                        \"t\" : NumberLong(2)\n                },\n                \"readConcernMajorityWallTime\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"appliedOpTime\" : {\n                        \"ts\" : Timestamp(1597068221, 2),\n                        \"t\" : NumberLong(2)\n                },\n                \"durableOpTime\" : {\n                        \"ts\" : Timestamp(1597068221, 2),\n                        \"t\" : NumberLong(2)\n                },\n                \"lastAppliedWallTime\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"lastDurableWallTime\" : ISODate(\"2020-08-10T14:03:41.727Z\")\n        },\n        \"lastStableRecoveryTimestamp\" : Timestamp(1597066170, 1),\n        \"electionCandidateMetrics\" : {\n                \"lastElectionReason\" : \"electionTimeout\",\n                \"lastElectionDate\" : ISODate(\"2020-08-10T14:03:41.721Z\"),\n                \"electionTerm\" : NumberLong(2),\n                \"lastCommittedOpTimeAtElection\" : {\n                        \"ts\" : Timestamp(0, 0),\n                        \"t\" : NumberLong(-1)\n                },\n                \"lastSeenOpTimeAtElection\" : {\n                        \"ts\" : Timestamp(1597066987, 1),\n                        \"t\" : NumberLong(1)\n                },\n                \"numVotesNeeded\" : 2,\n                \"priorityAtElection\" : 1,\n                \"electionTimeoutMillis\" : NumberLong(10000),\n                \"numCatchUpOps\" : NumberLong(0),\n                \"newTermStartDate\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"wMajorityWriteAvailabilityDate\" : ISODate(\"2020-08-10T14:03:41.898Z\")\n        },\n        \"members\" : [\n                {\n                        \"_id\" : 0,\n                        \"name\" : \"mongo1:27017\",\n                        \"health\" : 1,\n                        \"state\" : 1,\n                        \"stateStr\" : \"PRIMARY\",\n                        \"uptime\" : 454,\n                        \"optime\" : {\n                                \"ts\" : Timestamp(1597068221, 2),\n                                \"t\" : NumberLong(2)\n                        },\n                        \"optimeDate\" : ISODate(\"2020-08-10T14:03:41Z\"),\n                        \"syncSourceHost\" : \"\",\n                        \"syncSourceId\" : -1,\n                        \"infoMessage\" : \"\",\n                        \"electionTime\" : Timestamp(1597068221, 1),\n                        \"electionDate\" : ISODate(\"2020-08-10T14:03:41Z\"),\n                        \"configVersion\" : 2,\n                        \"configTerm\" : 2,\n                        \"self\" : true,\n                        \"lastHeartbeatMessage\" : \"\"\n                },\n                {\n                        \"_id\" : 1,\n                        \"name\" : \"mongo2:27017\",\n                        \"health\" : 1,\n                        \"state\" : 2,\n                        \"stateStr\" : \"SECONDARY\",\n                        \"uptime\" : 7,\n                        \"optime\" : {\n                                \"ts\" : Timestamp(1597066987, 1),\n                                \"t\" : NumberLong(1)\n                        },\n                        \"optimeDurable\" : {\n                                \"ts\" : Timestamp(1597066987, 1),\n                                \"t\" : NumberLong(1)\n                        },\n                        \"optimeDate\" : ISODate(\"2020-08-10T13:43:07Z\"),\n                        \"optimeDurableDate\" : ISODate(\"2020-08-10T13:43:07Z\"),\n                        \"lastHeartbeat\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                        \"lastHeartbeatRecv\" : ISODate(\"2020-08-10T14:03:42.261Z\"),\n                        \"pingMs\" : NumberLong(0),\n                        \"lastHeartbeatMessage\" : \"\",\n                        \"syncSourceHost\" : \"\",\n                        \"syncSourceId\" : -1,\n                        \"infoMessage\" : \"\",\n                        \"configVersion\" : 2,\n                        \"configTerm\" : 1\n                }\n        ],\n        \"ok\" : 1,\n        \"$clusterTime\" : {\n                \"clusterTime\" : Timestamp(1597068221, 2),\n                \"signature\" : {\n                        \"hash\" : BinData(0,\"17CdXYPWQ6I24TCLhxpQt8nGGPk=\"),\n                        \"keyId\" : NumberLong(\"6859346398467325956\")\n                }\n        },\n        \"operationTime\" : Timestamp(1597068221, 2)\n}\nrs0:PRIMARY> \n</code></pre>\n<h1>Setting up the Arbiter</h1>\n<pre><code>rs.addArb(\"mongo3:27017\");\n</code></pre>\n<pre><code>{\n        \"ok\" : 1,\n        \"$clusterTime\" : {\n                \"clusterTime\" : Timestamp(1597068567, 1),\n                \"signature\" : {\n                        \"hash\" : BinData(0,\"q5F6v883q8+1gBfmEJtwINbXAYY=\"),\n                        \"keyId\" : NumberLong(\"6859346398467325956\")\n                }\n        },\n        \"operationTime\" : Timestamp(1597068567, 1)\n}\n</code></pre>\n<p>Now check connection status by running</p>\n<pre><code>rs.status()\n</code></pre>\n<p>rs.status()</p>\n<pre><code>rs0:PRIMARY> rs.status()\n{\n        \"set\" : \"rs0\",\n        \"date\" : ISODate(\"2020-08-10T14:10:18.328Z\"),\n        \"myState\" : 1,\n        \"term\" : NumberLong(2),\n        \"syncSourceHost\" : \"\",\n        \"syncSourceId\" : -1,\n        \"heartbeatIntervalMillis\" : NumberLong(2000),\n        \"majorityVoteCount\" : 2,\n        \"writeMajorityCount\" : 2,\n        \"votingMembersCount\" : 3,\n        \"writableVotingMembersCount\" : 2,\n        \"optimes\" : {\n                \"lastCommittedOpTime\" : {\n                        \"ts\" : Timestamp(1597068611, 1),\n                        \"t\" : NumberLong(2)\n                },\n                \"lastCommittedWallTime\" : ISODate(\"2020-08-10T14:10:11.737Z\"),\n                \"readConcernMajorityOpTime\" : {\n                        \"ts\" : Timestamp(1597068611, 1),\n                        \"t\" : NumberLong(2)\n                },\n                \"readConcernMajorityWallTime\" : ISODate(\"2020-08-10T14:10:11.737Z\"),\n                \"appliedOpTime\" : {\n                        \"ts\" : Timestamp(1597068611, 1),\n                        \"t\" : NumberLong(2)\n                },\n                \"durableOpTime\" : {\n                        \"ts\" : Timestamp(1597068611, 1),\n                        \"t\" : NumberLong(2)\n                },\n                \"lastAppliedWallTime\" : ISODate(\"2020-08-10T14:10:11.737Z\"),\n                \"lastDurableWallTime\" : ISODate(\"2020-08-10T14:10:11.737Z\")\n        },\n        \"lastStableRecoveryTimestamp\" : Timestamp(1597068601, 1),\n        \"electionCandidateMetrics\" : {\n                \"lastElectionReason\" : \"electionTimeout\",\n                \"lastElectionDate\" : ISODate(\"2020-08-10T14:03:41.721Z\"),\n                \"electionTerm\" : NumberLong(2),\n                \"lastCommittedOpTimeAtElection\" : {\n                        \"ts\" : Timestamp(0, 0),\n                        \"t\" : NumberLong(-1)\n                },\n                \"lastSeenOpTimeAtElection\" : {\n                        \"ts\" : Timestamp(1597066987, 1),\n                        \"t\" : NumberLong(1)\n                },\n                \"numVotesNeeded\" : 2,\n                \"priorityAtElection\" : 1,\n                \"electionTimeoutMillis\" : NumberLong(10000),\n                \"numCatchUpOps\" : NumberLong(0),\n                \"newTermStartDate\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"wMajorityWriteAvailabilityDate\" : ISODate(\"2020-08-10T14:03:41.898Z\")\n        },\n        \"members\" : [\n                {\n                        \"_id\" : 0,\n                        \"name\" : \"mongo1:27017\",\n                        \"health\" : 1,\n                        \"state\" : 1,\n                        \"stateStr\" : \"PRIMARY\",\n                        \"uptime\" : 850,\n                        \"optime\" : {\n                                \"ts\" : Timestamp(1597068611, 1),\n                                \"t\" : NumberLong(2)\n                        },\n                        \"optimeDate\" : ISODate(\"2020-08-10T14:10:11Z\"),\n                        \"syncSourceHost\" : \"\",\n                        \"syncSourceId\" : -1,\n                        \"infoMessage\" : \"\",\n                        \"electionTime\" : Timestamp(1597068221, 1),\n                        \"electionDate\" : ISODate(\"2020-08-10T14:03:41Z\"),\n                        \"configVersion\" : 3,\n                        \"configTerm\" : 2,\n                        \"self\" : true,\n                        \"lastHeartbeatMessage\" : \"\"\n                },\n                {\n                        \"_id\" : 1,\n                        \"name\" : \"mongo2:27017\",\n                        \"health\" : 1,\n                        \"state\" : 2,\n                        \"stateStr\" : \"SECONDARY\",\n                        \"uptime\" : 403,\n                        \"optime\" : {\n                                \"ts\" : Timestamp(1597068611, 1),\n                                \"t\" : NumberLong(2)\n                        },\n                        \"optimeDurable\" : {\n                                \"ts\" : Timestamp(1597068611, 1),\n                                \"t\" : NumberLong(2)\n                        },\n                        \"optimeDate\" : ISODate(\"2020-08-10T14:10:11Z\"),\n                        \"optimeDurableDate\" : ISODate(\"2020-08-10T14:10:11Z\"),\n                        \"lastHeartbeat\" : ISODate(\"2020-08-10T14:10:17.346Z\"),\n                        \"lastHeartbeatRecv\" : ISODate(\"2020-08-10T14:10:17.389Z\"),\n                        \"pingMs\" : NumberLong(0),\n                        \"lastHeartbeatMessage\" : \"\",\n                        \"syncSourceHost\" : \"mongo1:27017\",\n                        \"syncSourceId\" : 0,\n                        \"infoMessage\" : \"\",\n                        \"configVersion\" : 3,\n                        \"configTerm\" : 2\n                },\n                {\n                        \"_id\" : 2,\n                        \"name\" : \"mongo3:27017\",\n                        \"health\" : 1,\n                        \"state\" : 7,\n                        \"stateStr\" : \"ARBITER\",\n                        \"uptime\" : 50,\n                        \"lastHeartbeat\" : ISODate(\"2020-08-10T14:10:17.351Z\"),\n                        \"lastHeartbeatRecv\" : ISODate(\"2020-08-10T14:10:17.471Z\"),\n                        \"pingMs\" : NumberLong(0),\n                        \"lastHeartbeatMessage\" : \"\",\n                        \"syncSourceHost\" : \"\",\n                        \"syncSourceId\" : -1,\n                        \"infoMessage\" : \"\",\n                        \"configVersion\" : 3,\n                        \"configTerm\" : 2\n                }\n        ],\n        \"ok\" : 1,\n        \"$clusterTime\" : {\n                \"clusterTime\" : Timestamp(1597068611, 1),\n                \"signature\" : {\n                        \"hash\" : BinData(0,\"Pir6qAUNxIu6/AbFv6fCxpVVwOs=\"),\n                        \"keyId\" : NumberLong(\"6859346398467325956\")\n                }\n        },\n        \"operationTime\" : Timestamp(1597068611, 1)\n}\n</code></pre>\n<p>now run </p>\n<pre><code>rs.conf()\n</code></pre>\n<p>to see your config</p>\n<pre><code>rs0:PRIMARY> rs.conf()\n{\n        \"_id\" : \"rs0\",\n        \"version\" : 3,\n        \"term\" : 2,\n        \"protocolVersion\" : NumberLong(1),\n        \"writeConcernMajorityJournalDefault\" : true,\n        \"members\" : [\n                {\n                        \"_id\" : 0,\n                        \"host\" : \"mongo1:27017\",\n                        \"arbiterOnly\" : false,\n                        \"buildIndexes\" : true,\n                        \"hidden\" : false,\n                        \"priority\" : 1,\n                        \"tags\" : {\n\n                        },\n                        \"slaveDelay\" : NumberLong(0),\n                        \"votes\" : 1\n                },\n                {\n                        \"_id\" : 1,\n                        \"host\" : \"mongo2:27017\",\n                        \"arbiterOnly\" : false,\n                        \"buildIndexes\" : true,\n                        \"hidden\" : false,\n                        \"priority\" : 1,\n                        \"tags\" : {\n\n                        },\n                        \"slaveDelay\" : NumberLong(0),\n                        \"votes\" : 1\n                },\n                {\n                        \"_id\" : 2,\n                        \"host\" : \"mongo3:27017\",\n                        \"arbiterOnly\" : true,\n                        \"buildIndexes\" : true,\n                        \"hidden\" : false,\n                        \"priority\" : 0,\n                        \"tags\" : {\n\n                        },\n                        \"slaveDelay\" : NumberLong(0),\n                        \"votes\" : 1\n                }\n        ],\n        \"settings\" : {\n                \"chainingAllowed\" : true,\n                \"heartbeatIntervalMillis\" : 2000,\n                \"heartbeatTimeoutSecs\" : 10,\n                \"electionTimeoutMillis\" : 10000,\n                \"catchUpTimeoutMillis\" : -1,\n                \"catchUpTakeoverDelayMillis\" : 30000,\n                \"getLastErrorModes\" : {\n\n                },\n                \"getLastErrorDefaults\" : {\n                        \"w\" : 1,\n                        \"wtimeout\" : 0\n                },\n                \"replicaSetId\" : ObjectId(\"5f314b35458f8460ab22cda1\")\n        }\n}\n</code></pre>\n<p>Have an awesome day ahead</p>\n<p><em><a href=\"https://dev.to/tomahawkpilot/mongodb-cluster-setup-centos-7-47hh\">This post is also available on DEV.</a></em></p>\n<script>\nconst parent = document.getElementsByTagName('head')[0];\nconst script = document.createElement('script');\nscript.type = 'text/javascript';\nscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.1.1/iframeResizer.min.js';\nscript.charset = 'utf-8';\nscript.onload = function() {\n    window.iFrameResize({}, '.liquidTag');\n};\nparent.appendChild(script);\n</script>    ","pages":[{"url":"/contact/","relativePath":"contact.md","relativeDir":"","base":"contact.md","name":"contact","frontmatter":{"title":"Get in Touch","img_path":"images/contact.jpg","form_id":"contactForm","form_fields":[{"input_type":"text","name":"name","label":"Name","default_value":"Your name","is_required":true},{"input_type":"email","name":"email","label":"Email","default_value":"Your email address","is_required":true},{"input_type":"select","name":"subject","label":"Subject","default_value":"Please select","options":["Error on the site","Sponsorship","Other"]},{"input_type":"textarea","name":"message","label":"Message","default_value":"Your message"},{"input_type":"checkbox","name":"consent","label":"I understand that this form is storing my submitted information so I can be contacted."}],"submit_label":"Send Message","template":"contact"},"html":"<p>To get in touch fill the form below.</p>"},{"url":"/posts/centos-7-to-8-upgrade-2bj8/","relativePath":"posts/centos-7-to-8-upgrade-2bj8.md","relativeDir":"posts","base":"centos-7-to-8-upgrade-2bj8.md","name":"centos-7-to-8-upgrade-2bj8","frontmatter":{"title":"Centos 7 to 8 Upgrade","date":"2020-07-29T07:09:41.306Z","excerpt":"Red Hat Enterprise Linux 8 was released on 2019-05-07, and everyone is waiting to find out when the...","thumb_img_path":"https://res.cloudinary.com/practicaldev/image/fetch/s--nfVyZDJy--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/khggm10hhsm52aitdr79.png","comments_count":0,"positive_reactions_count":7,"tags":["devops","linux","centos"],"canonical_url":"https://dev.to/tomahawkpilot/centos-7-to-8-upgrade-2bj8","template":"post"},"html":"<p><img src=\"https://dev-to-uploads.s3.amazonaws.com/i/d1mlbptmfps7r8450pzx.png\" alt=\"Alt Text\"></p>\n<p>Red Hat Enterprise Linux 8 was released on 2019-05-07, and everyone is waiting to find out when the CentOS rebuild will occur. This document is meant to cover general questions and a timeline for what is happening.</p>\n<p>A CentOS major release takes a lot of planning and changes in tooling as it is based on a much newer version of Fedora than previous versions. This means that everything from the installer, packages, packaging, and build systems need major overhauls to work with the newer OS. This means that there is always a ramp-up period depending on the changes needed to make a rebuild work. The differences between EL-8 and EL-7 are no exception as the kernel has changed drastically, the repository format has added 'modules' and RPMS has grown many features that EL7 and before do not have. About the only item which has not drastically changed between EL7 and EL8 is the init system which is still system.</p>\n<p>To upgrade centos 7 to centos 8 </p>\n<p>Login as sudo\n<code>sudo --login</code></p>\n<p>Steps :</p>\n<ul>\n<li>Install Epel release package</li>\n</ul>\n<pre><code>yum install epel-release -y\n</code></pre>\n<ul>\n<li>Install yum utils</li>\n</ul>\n<pre><code>yum install yum-utils -y\n</code></pre>\n<ul>\n<li>Resolve RPM packages by executing the command.</li>\n</ul>\n<pre><code>yum install rpmconf -y\nrpmconf -a\n</code></pre>\n<ul>\n<li>Perform a clean-up of all the packages you don’t require.</li>\n</ul>\n<pre><code> package-cleanup --leaves\n package-cleanup --orphans\n</code></pre>\n<ul>\n<li>Install DNF package manager since Centos 8 uses DNF instead of yum</li>\n</ul>\n<pre><code>yum install dnf -y \n</code></pre>\n<ul>\n<li>Remove yum package manager which was part of centos 7</li>\n</ul>\n<pre><code>dnf -y remove yum yum-metadata-parser \nrm -Rf /etc/yum\n</code></pre>\n<ul>\n<li>Run\n<code>dnf upgrade -y</code></li>\n<li>install CentOS 8 release package</li>\n</ul>\n<pre><code>dnf install http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-repos-8.2-2.2004.0.1.el8.x86_64.rpm http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-release-8.2-2.2004.0.1.el8.x86_64.rpm http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/centos-gpg-keys-8.2-2.2004.0.1.el8.noarch.rpm\n</code></pre>\n<ul>\n<li>upgrade the EPEL repository.</li>\n</ul>\n<pre><code>dnf -y upgrade https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm\n</code></pre>\n<ul>\n<li>remove all the temporary files.</li>\n</ul>\n<pre><code>dnf clean all \n</code></pre>\n<ul>\n<li>Remove the old kernel core for CentOS 7.</li>\n</ul>\n<pre><code> rpm -e `\nrpm -q kernel\n` \n</code></pre>\n<ul>\n<li>to remove conflicting packages.</li>\n</ul>\n<pre><code>rpm -e --nodeps sysvinit-tools \n</code></pre>\n<ul>\n<li>launch the CentOS 8 system upgrade</li>\n</ul>\n<pre><code> dnf -y --releasever=8 --allowerasing --setopt=deltarpm=false distro-sync \n</code></pre>\n<p>Troubleshooting for common errors during this step.</p>\n<ul>\n<li>Python 3 dependency error.\nfix by </li>\n</ul>\n<p><code>dnf remove python3</code></p>\n<ul>\n<li>Segmentation fault </li>\n</ul>\n<pre><code>rm -rf /var/lib/rpm/__db.*\nrpm --rebuilddb\ndnf clean all\ndnf makecache\n</code></pre>\n<ul>\n<li>install a new kernel for CentOS 8 </li>\n</ul>\n<pre><code>dnf -y install kernel-core\n</code></pre>\n<ul>\n<li>install CentOS 8 minimal package</li>\n</ul>\n<pre><code>dnf -y groupupdate \"Core\" \"Minimal Install\"\n</code></pre>\n<ul>\n<li>check the version of CentOS installed by running.</li>\n</ul>\n<pre><code>cat /etc/redhat-release\n</code></pre>\n<p>You have complete Centos Upgrade</p>\n<p><em><a href=\"https://dev.to/tomahawkpilot/centos-7-to-8-upgrade-2bj8\">This post is also available on DEV.</a></em></p>\n<script>\nconst parent = document.getElementsByTagName('head')[0];\nconst script = document.createElement('script');\nscript.type = 'text/javascript';\nscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.1.1/iframeResizer.min.js';\nscript.charset = 'utf-8';\nscript.onload = function() {\n    window.iFrameResize({}, '.liquidTag');\n};\nparent.appendChild(script);\n</script>    "},{"url":"/","relativePath":"index.md","relativeDir":"","base":"index.md","name":"index","frontmatter":{"title":"Home","template":"home"},"html":""},{"url":"/posts/setup-an-openldap-in-centos-5hge/","relativePath":"posts/setup-an-openldap-in-centos-5hge.md","relativeDir":"posts","base":"setup-an-openldap-in-centos-5hge.md","name":"setup-an-openldap-in-centos-5hge","frontmatter":{"title":"Setup an OpenLDAP Server in Centos","date":"2020-07-29T07:44:09.059Z","excerpt":"OpenLDAP is a free, open-source implementation of the Lightweight Directory Access Protocol develop...","thumb_img_path":"https://res.cloudinary.com/practicaldev/image/fetch/s--et-wc0UN--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/75lpp6kgf3j2usul4t71.png","comments_count":0,"positive_reactions_count":9,"tags":["centos","linux","openldap","opensource"],"canonical_url":"https://dev.to/tomahawkpilot/setup-an-openldap-in-centos-5hge","template":"post"},"html":"<p><img src=\"https://dev-to-uploads.s3.amazonaws.com/i/z0pioz7mztix47nwlc7t.png\" alt=\"Alt Text\"></p>\n<p>OpenLDAP is a free, open-source implementation of the Lightweight Directory Access Protocol developed by the OpenLDAP Project. It is released under its own BSD-style license called the OpenLDAP Public License. LDAP is a platform-independent protocol.</p>\n<p>Follow the following steps to setup an OpenLDAP server in centos </p>\n<ul>\n<li>login as Sudo.\n<code>sudo --login</code></li>\n<li>Run package updates<br>\n<code>yum update -y</code></li>\n<li>Install Epel Release\n<code>yum install -y epel-release</code></li>\n<li>Install nano editor\n<code>yum install -y nano</code></li>\n<li>Install OpenLDAP</li>\n</ul>\n<pre><code>yum -y install openldap compat-openldap openldap-clients openldap-servers openldap-servers-sql openldap-devel\n</code></pre>\n<ul>\n<li>start the LDAP daemon and enable it on boot</li>\n</ul>\n<pre><code>systemctl start slapd\nsystemctl enable slapd\nsystemctl status slapd \n</code></pre>\n<ul>\n<li>Now create an OpenLDAP administrative user and assign a password for that user</li>\n</ul>\n<p><code>slappasswd</code>\nwill generate a hashed value for a given password which we can use to configure admin auth</p>\n<ul>\n<li>create an LDIF file (ldaprootpasswd.ldif) which is used to add an entry to the LDAP directory.</li>\n</ul>\n<pre><code>nano ldaprootpasswd.ldif\n</code></pre>\n<p>Add the following contents in it:</p>\n<pre><code>dn: olcDatabase={0}config,cn=config\nchangetype: modify\nadd: olcRootPW\nolcRootPW: {SSHA}PASSWORD_CREATED\n</code></pre>\n<ul>\n<li>add the corresponding LDAP entry by specifying the URI referring to the LDAP server and the file above.</li>\n</ul>\n<pre><code>ldapadd -Y EXTERNAL -H ldapi:/// -f ldaprootpasswd.ldif\n</code></pre>\n<ul>\n<li>copy the sample database configuration file for slapd into the /var/lib/ldap directory, and set the correct permissions on the file.</li>\n</ul>\n<pre><code>cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG\nchown -R ldap:ldap /var/lib/ldap/DB_CONFIG\nsystemctl restart slapd\n</code></pre>\n<ul>\n<li>import some basic LDAP schemas from the /etc/openldap/schema directory </li>\n</ul>\n<pre><code>ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif \nldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif\nldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif\n</code></pre>\n<ul>\n<li>add your domain in the LDAP database and create a file called ldapdomain.ldif for your domain.</li>\n</ul>\n<pre><code>dn: olcDatabase={1}monitor,cn=config\nchangetype: modify\nreplace: olcAccess\nolcAccess: {0}to * by dn.base=\"gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\"\n  read by dn.base=\"cn=auth,dc=example,dc=com\" read by * none\n\ndn: olcDatabase={2}hdb,cn=config\nchangetype: modify\nreplace: olcSuffix\nolcSuffix: dc=example,dc=com\n\ndn: olcDatabase={2}hdb,cn=config\nchangetype: modify\nreplace: olcRootDN\nolcRootDN: cn=auth,dc=example,dc=com\n\ndn: olcDatabase={2}hdb,cn=config\nchangetype: modify\nadd: olcRootPW\nolcRootPW: {SSHA}PASSWORD_CREATED\n\ndn: olcDatabase={2}hdb,cn=config\nchangetype: modify\nadd: olcAccess\nolcAccess: {0}to attrs=userPassword,shadowLastChange by\n  dn=\"cn=auth,dc=example,dc=com\" write by anonymous auth by self write by * none\nolcAccess: {1}to dn.base=\"\" by * read\nolcAccess: {2}to * by dn=\"cn=auth,dc=example,dc=com\" write by * read\n</code></pre>\n<ul>\n<li>add the above configuration to the LDAP database</li>\n</ul>\n<pre><code>ldapmodify -Y EXTERNAL -H ldapi:/// -f ldapdomain.ldif\n</code></pre>\n<ul>\n<li>create baseldapdomain.ldif</li>\n</ul>\n<pre><code>dn: dc=example,dc=com\nobjectClass: top\nobjectClass: dcObject\nobjectclass: organization\no: example com\ndc: example\n\ndn: cn=auth,dc=example,dc=com\nobjectClass: organizationalRole\ncn: Manager\ndescription: Directory Manager\n\ndn: ou=People,dc=example,dc=com\nobjectClass: organizationalUnit\nou: People\n\ndn: ou=Group,dc=example,dc=com\nobjectClass: organizationalUnit\nou: Group \n</code></pre>\n<ul>\n<li>add the entries to the LDAP directory. </li>\n</ul>\n<pre><code>ldapadd -Y EXTERNAL -x -D cn=auth,dc=example,dc=com -W -f baseldapdomain.ldif\n</code></pre>\n<ul>\n<li>create an LDAP User</li>\n</ul>\n<pre><code>useradd tomahawk\npasswd tomahawk\n</code></pre>\n<ul>\n<li>create an LDAP group</li>\n</ul>\n<p><code>create a file called ldapgroup.ldif</code></p>\n<pre><code>dn: cn=auth,ou=Group,dc=example,dc=com\nobjectClass: top\nobjectClass: posixGroup\ngidNumber: 1005\n</code></pre>\n<p><strong>gidNumber is the GID in /etc/group for tomahawk and add it to the OpenLDAP directory.</strong></p>\n<ul>\n<li>Add to OpenLDAP directory.</li>\n</ul>\n<pre><code>ldapadd -Y EXTERNAL -x  -W -D \"cn=auth,dc=example,dc=com\" -f ldapgroup.ldif\n</code></pre>\n<ul>\n<li>Create an LDAP user </li>\n</ul>\n<p><code>create a file named tomahawk.ldif</code></p>\n<pre><code>dn: uid=tomahawk,ou=People,dc=example,dc=com\nobjectClass: top\nobjectClass: account\nobjectClass: posixAccount\nobjectClass: shadowAccount\ncn: tomahawk\nuid: tomahawk\nuidNumber: 1005\ngidNumber: 1005\nhomeDirectory: /home/tomahawk\nuserPassword: {SSHA}PASSWORD_HERE\nloginShell: /bin/bash\ngecos: tecmint\nshadowLastChange: 0\nshadowMax: 0\nshadowWarning: 0\n</code></pre>\n<p>** Run\n<code>slappasswd</code>\nto generate a hashed password **</p>\n<ul>\n<li>Add the above file to LDAP directory</li>\n</ul>\n<pre><code>ldapadd -Y EXTERNAL  -x -D cn=auth,dc=example,dc=com -W -f  tomahawk.ldif\n</code></pre>\n<p>You can also download Tools like\n<a href=\"https://directory.apache.org/studio/\">Apache Directory Studio</a> to manage LDAP after following the above steps to add more user and groups without creating config files. </p>\n<h3>Optional Steps</h3>\n<h4>LDAPS ( LDAP via SSL)</h4>\n<ul>\n<li>Now we will generate a certificate and a private key so we can communicate securely with the OpenLDAP server using OpenSSL</li>\n</ul>\n<pre><code>openssl req -new -x509 -nodes -out \\\n/etc/openldap/certs/auth.example.com.cert \\\n-keyout /etc/openldap/certs/auth.example.com.key \\\n-days 365\n</code></pre>\n<ul>\n<li>Change the owner and group permissions so OpenLDAP can read the files:</li>\n</ul>\n<pre><code>chown -R ldap:ldap /etc/openldap/certs\n</code></pre>\n<ul>\n<li>Now create ssl.ldif to configure OpenLDAP to use the LDAPS protocol:</li>\n</ul>\n<pre><code>dn: cn=config\nchangetype: modify\nreplace: olcTLSCertificateFile\nolcTLSCertificateFile: /etc/openldap/certs/auth.example.com.cert\n\ndn: cn=config\nchangetype: modify\nreplace: olcTLSCertificateKeyFile\nolcTLSCertificateKeyFile: /etc/openldap/certs/auth.example.com.key\n</code></pre>\n<ul>\n<li>Add the above file to LDAP directory</li>\n</ul>\n<pre><code>ldapmodify -Y EXTERNAL -H ldapi:/// -f ssl.ldif\n</code></pre>\n<ul>\n<li>Test SSL configuration using </li>\n</ul>\n<pre><code>slaptest -u\n</code></pre>\n<p>You have completed Openldap Setup in Centos 7</p>\n<p><em><a href=\"https://dev.to/tomahawkpilot/setup-an-openldap-in-centos-5hge\">This post is also available on DEV.</a></em></p>\n<script>\nconst parent = document.getElementsByTagName('head')[0];\nconst script = document.createElement('script');\nscript.type = 'text/javascript';\nscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.1.1/iframeResizer.min.js';\nscript.charset = 'utf-8';\nscript.onload = function() {\n    window.iFrameResize({}, '.liquidTag');\n};\nparent.appendChild(script);\n</script>    "},{"url":"/posts/mongodb-cluster-setup-centos-7-47hh/","relativePath":"posts/mongodb-cluster-setup-centos-7-47hh.md","relativeDir":"posts","base":"mongodb-cluster-setup-centos-7-47hh.md","name":"mongodb-cluster-setup-centos-7-47hh","frontmatter":{"title":"MongoDB Cluster Setup Centos","date":"2020-08-10T14:19:12.601Z","excerpt":"We will be setting up Mongo DB for high availability using 3 virtual machines   1) Mongo Primary (t3a...","thumb_img_path":"https://res.cloudinary.com/practicaldev/image/fetch/s--ZcaStyBD--/c_imagga_scale,f_auto,fl_progressive,h_420,q_auto,w_1000/https://dev-to-uploads.s3.amazonaws.com/i/bqijylyalckck382nujy.png","comments_count":0,"positive_reactions_count":4,"tags":["mongodb","centos","opensource","linux"],"canonical_url":"https://dev.to/tomahawkpilot/mongodb-cluster-setup-centos-7-47hh","template":"post"},"html":"<p>We will be setting up Mongo DB for high availability using 3 virtual machines </p>\n<ol>\n<li>Mongo Primary (t3a.medium)</li>\n<li>Mongo Secondary (t3a.medium)</li>\n<li>Mongo Arbiter (t3a.small)</li>\n</ol>\n<h2>Let's begin the system preparations</h2>\n<h3>The following setup has to be done in all 3 machines</h3>\n<ul>\n<li>login as sudo in each machine</li>\n</ul>\n<pre><code>sudo --login \n</code></pre>\n<ul>\n<li>Update centos packages to the latest version\nCentos 7</li>\n</ul>\n<pre><code>yum update -y\n</code></pre>\n<p>Centos 8</p>\n<pre><code>dnf update -y\n</code></pre>\n<ul>\n<li>install Nano editor (I am a Nano fan)\nCentos 7</li>\n</ul>\n<pre><code>yum install nano -y\n</code></pre>\n<p>Centos 8</p>\n<pre><code>dnf install nano -y\n</code></pre>\n<ul>\n<li>add hosts values\nedit the\n<code>nano /etc/hosts</code>\nfile to add the following entries</li>\n</ul>\n<pre><code>172.31.28.16 mongo1\n172.31.31.194 mongo2\n172.31.25.65 mongo3\n</code></pre>\n<h2>important Step</h2>\n<p>Disable SELinux as it has breaking effects  on internode connection\nedit\n<code>/etc/selinux/config</code></p>\n<p>change </p>\n<pre><code>SELINUX=disabled\n</code></pre>\n<p>do the above step in all 3 machines and make sure to do a reboot by running </p>\n<pre><code>reboot\n</code></pre>\n<h2>Now Install Mongo</h2>\n<ul>\n<li>Configure the package management system</li>\n</ul>\n<p>Create a\n<code>nano /etc/yum.repos.d/mongodb-org-4.4.repo</code>\nfile so that you can install MongoDB directly using yum</p>\n<p>Add the following content to it.</p>\n<pre><code>[mongodb-org-4.4]\nname=MongoDB Repository\nbaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.4/x86_64/\ngpgcheck=1\nenabled=1\ngpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc\n</code></pre>\n<ul>\n<li>Install Mongo DB latest Stable\nCentos 7</li>\n</ul>\n<pre><code>yum install -y mongodb-org\n</code></pre>\n<p>Centos 8</p>\n<pre><code>dnf install -y mongodb-org\n</code></pre>\n<p>Before we can begin cluster Setup lets prepare mongo</p>\n<h3>Enable Mongo Authentication</h3>\n<p>To add authentication to mongo add the following lines to </p>\n<p><code>nano /etc/mongod.conf</code></p>\n<pre><code>security:\n    authorization: enabled\n</code></pre>\n<p>Then do a restart </p>\n<pre><code>service mongod restart\n</code></pre>\n<ul>\n<li>let's create mongodb user\nOpen mongo shell</li>\n</ul>\n<p><code>mongo</code></p>\n<p>the following commands</p>\n<pre><code>use admin\n</code></pre>\n<pre><code>db.createUser({\n    user: \"tomahawk\",\n    pwd: \"tomahawkPilot\",\n    roles: [ \n        { \n            role: \"userAdminAnyDatabase\", \n            db: \"admin\" \n        },\n        {\n            role: \"clusterAdmin\",\n             db: \"admin\"\n        },\n        {\n            role: \"root,\n            db: \"admin\n        }\n    ]\n})\n</code></pre>\n<h2>Now let's Begin the Replication Configuration</h2>\n<ul>\n<li>Add replSet to mongod.conf in all 3 machines\nedit your\n<code>nano /etc/mongod.conf</code>\nfile </li>\n</ul>\n<pre><code>replication:\n  replSetName: rs0\n</code></pre>\n<h2>Keyfile Access Control on Replica Set</h2>\n<p>navigate to your mongo path</p>\n<pre><code>/var/lib/mongo in my case\n</code></pre>\n<p>Use the following command to generate a keyfile</p>\n<pre><code>openssl rand -base64 756 > keyfile\n</code></pre>\n<p>Copy the key file to all 3 machines\nadd Appropriate permissions</p>\n<pre><code>chmod 400 keyfile\nchown mongod:mongod keyfile\n</code></pre>\n<p>Now add the keyfile to your\n<code>nano /etc/mongod.conf</code>\nfile</p>\n<pre><code>security:\n    authorization: enabled\n    keyFile: /var/lib/mongo/keyfile\n</code></pre>\n<ul>\n<li>do a restart of all mongod services</li>\n</ul>\n<pre><code>systemctl restart mongod\n</code></pre>\n<p>for the changes in replication to take effect before initializing the replica</p>\n<ul>\n<li>On mongo1</li>\n</ul>\n<pre><code>use admin\ndb.auth(\"tomahawk\",\"tomahawkPilot\");\nrs.initiate(\n   {\n      _id: \"rs0\",\n      version: 1,\n      members: [\n         { _id: 0, host : \"mongo1:27017\" }\n      ]\n   }\n)\n</code></pre>\n<p>You can always run </p>\n<pre><code>mongo --port 27017 -u tomahawk --authenticationDatabase 'admin' -p tomahawkPilot\n</code></pre>\n<p>to directly login to the cluster</p>\n<p>Now let's create the replica set</p>\n<pre><code>rs.add(\"mongo2:27017\");\n</code></pre>\n<p>Check connection status by running</p>\n<pre><code>rs.status()\n</code></pre>\n<p>On Successful connection, you will get a response </p>\n<pre><code>rs.status()\n{\n        \"set\" : \"rs0\",\n        \"date\" : ISODate(\"2020-08-10T14:03:42.405Z\"),\n        \"myState\" : 1,\n        \"term\" : NumberLong(2),\n        \"syncSourceHost\" : \"\",\n        \"syncSourceId\" : -1,\n        \"heartbeatIntervalMillis\" : NumberLong(2000),\n        \"majorityVoteCount\" : 2,\n        \"writeMajorityCount\" : 2,\n        \"votingMembersCount\" : 2,\n        \"writableVotingMembersCount\" : 2,\n        \"optimes\" : {\n                \"lastCommittedOpTime\" : {\n                        \"ts\" : Timestamp(1597068221, 2),\n                        \"t\" : NumberLong(2)\n                },\n                \"lastCommittedWallTime\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"readConcernMajorityOpTime\" : {\n                        \"ts\" : Timestamp(1597068221, 2),\n                        \"t\" : NumberLong(2)\n                },\n                \"readConcernMajorityWallTime\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"appliedOpTime\" : {\n                        \"ts\" : Timestamp(1597068221, 2),\n                        \"t\" : NumberLong(2)\n                },\n                \"durableOpTime\" : {\n                        \"ts\" : Timestamp(1597068221, 2),\n                        \"t\" : NumberLong(2)\n                },\n                \"lastAppliedWallTime\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"lastDurableWallTime\" : ISODate(\"2020-08-10T14:03:41.727Z\")\n        },\n        \"lastStableRecoveryTimestamp\" : Timestamp(1597066170, 1),\n        \"electionCandidateMetrics\" : {\n                \"lastElectionReason\" : \"electionTimeout\",\n                \"lastElectionDate\" : ISODate(\"2020-08-10T14:03:41.721Z\"),\n                \"electionTerm\" : NumberLong(2),\n                \"lastCommittedOpTimeAtElection\" : {\n                        \"ts\" : Timestamp(0, 0),\n                        \"t\" : NumberLong(-1)\n                },\n                \"lastSeenOpTimeAtElection\" : {\n                        \"ts\" : Timestamp(1597066987, 1),\n                        \"t\" : NumberLong(1)\n                },\n                \"numVotesNeeded\" : 2,\n                \"priorityAtElection\" : 1,\n                \"electionTimeoutMillis\" : NumberLong(10000),\n                \"numCatchUpOps\" : NumberLong(0),\n                \"newTermStartDate\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"wMajorityWriteAvailabilityDate\" : ISODate(\"2020-08-10T14:03:41.898Z\")\n        },\n        \"members\" : [\n                {\n                        \"_id\" : 0,\n                        \"name\" : \"mongo1:27017\",\n                        \"health\" : 1,\n                        \"state\" : 1,\n                        \"stateStr\" : \"PRIMARY\",\n                        \"uptime\" : 454,\n                        \"optime\" : {\n                                \"ts\" : Timestamp(1597068221, 2),\n                                \"t\" : NumberLong(2)\n                        },\n                        \"optimeDate\" : ISODate(\"2020-08-10T14:03:41Z\"),\n                        \"syncSourceHost\" : \"\",\n                        \"syncSourceId\" : -1,\n                        \"infoMessage\" : \"\",\n                        \"electionTime\" : Timestamp(1597068221, 1),\n                        \"electionDate\" : ISODate(\"2020-08-10T14:03:41Z\"),\n                        \"configVersion\" : 2,\n                        \"configTerm\" : 2,\n                        \"self\" : true,\n                        \"lastHeartbeatMessage\" : \"\"\n                },\n                {\n                        \"_id\" : 1,\n                        \"name\" : \"mongo2:27017\",\n                        \"health\" : 1,\n                        \"state\" : 2,\n                        \"stateStr\" : \"SECONDARY\",\n                        \"uptime\" : 7,\n                        \"optime\" : {\n                                \"ts\" : Timestamp(1597066987, 1),\n                                \"t\" : NumberLong(1)\n                        },\n                        \"optimeDurable\" : {\n                                \"ts\" : Timestamp(1597066987, 1),\n                                \"t\" : NumberLong(1)\n                        },\n                        \"optimeDate\" : ISODate(\"2020-08-10T13:43:07Z\"),\n                        \"optimeDurableDate\" : ISODate(\"2020-08-10T13:43:07Z\"),\n                        \"lastHeartbeat\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                        \"lastHeartbeatRecv\" : ISODate(\"2020-08-10T14:03:42.261Z\"),\n                        \"pingMs\" : NumberLong(0),\n                        \"lastHeartbeatMessage\" : \"\",\n                        \"syncSourceHost\" : \"\",\n                        \"syncSourceId\" : -1,\n                        \"infoMessage\" : \"\",\n                        \"configVersion\" : 2,\n                        \"configTerm\" : 1\n                }\n        ],\n        \"ok\" : 1,\n        \"$clusterTime\" : {\n                \"clusterTime\" : Timestamp(1597068221, 2),\n                \"signature\" : {\n                        \"hash\" : BinData(0,\"17CdXYPWQ6I24TCLhxpQt8nGGPk=\"),\n                        \"keyId\" : NumberLong(\"6859346398467325956\")\n                }\n        },\n        \"operationTime\" : Timestamp(1597068221, 2)\n}\nrs0:PRIMARY> \n</code></pre>\n<h1>Setting up the Arbiter</h1>\n<pre><code>rs.addArb(\"mongo3:27017\");\n</code></pre>\n<pre><code>{\n        \"ok\" : 1,\n        \"$clusterTime\" : {\n                \"clusterTime\" : Timestamp(1597068567, 1),\n                \"signature\" : {\n                        \"hash\" : BinData(0,\"q5F6v883q8+1gBfmEJtwINbXAYY=\"),\n                        \"keyId\" : NumberLong(\"6859346398467325956\")\n                }\n        },\n        \"operationTime\" : Timestamp(1597068567, 1)\n}\n</code></pre>\n<p>Now check connection status by running</p>\n<pre><code>rs.status()\n</code></pre>\n<p>rs.status()</p>\n<pre><code>rs0:PRIMARY> rs.status()\n{\n        \"set\" : \"rs0\",\n        \"date\" : ISODate(\"2020-08-10T14:10:18.328Z\"),\n        \"myState\" : 1,\n        \"term\" : NumberLong(2),\n        \"syncSourceHost\" : \"\",\n        \"syncSourceId\" : -1,\n        \"heartbeatIntervalMillis\" : NumberLong(2000),\n        \"majorityVoteCount\" : 2,\n        \"writeMajorityCount\" : 2,\n        \"votingMembersCount\" : 3,\n        \"writableVotingMembersCount\" : 2,\n        \"optimes\" : {\n                \"lastCommittedOpTime\" : {\n                        \"ts\" : Timestamp(1597068611, 1),\n                        \"t\" : NumberLong(2)\n                },\n                \"lastCommittedWallTime\" : ISODate(\"2020-08-10T14:10:11.737Z\"),\n                \"readConcernMajorityOpTime\" : {\n                        \"ts\" : Timestamp(1597068611, 1),\n                        \"t\" : NumberLong(2)\n                },\n                \"readConcernMajorityWallTime\" : ISODate(\"2020-08-10T14:10:11.737Z\"),\n                \"appliedOpTime\" : {\n                        \"ts\" : Timestamp(1597068611, 1),\n                        \"t\" : NumberLong(2)\n                },\n                \"durableOpTime\" : {\n                        \"ts\" : Timestamp(1597068611, 1),\n                        \"t\" : NumberLong(2)\n                },\n                \"lastAppliedWallTime\" : ISODate(\"2020-08-10T14:10:11.737Z\"),\n                \"lastDurableWallTime\" : ISODate(\"2020-08-10T14:10:11.737Z\")\n        },\n        \"lastStableRecoveryTimestamp\" : Timestamp(1597068601, 1),\n        \"electionCandidateMetrics\" : {\n                \"lastElectionReason\" : \"electionTimeout\",\n                \"lastElectionDate\" : ISODate(\"2020-08-10T14:03:41.721Z\"),\n                \"electionTerm\" : NumberLong(2),\n                \"lastCommittedOpTimeAtElection\" : {\n                        \"ts\" : Timestamp(0, 0),\n                        \"t\" : NumberLong(-1)\n                },\n                \"lastSeenOpTimeAtElection\" : {\n                        \"ts\" : Timestamp(1597066987, 1),\n                        \"t\" : NumberLong(1)\n                },\n                \"numVotesNeeded\" : 2,\n                \"priorityAtElection\" : 1,\n                \"electionTimeoutMillis\" : NumberLong(10000),\n                \"numCatchUpOps\" : NumberLong(0),\n                \"newTermStartDate\" : ISODate(\"2020-08-10T14:03:41.727Z\"),\n                \"wMajorityWriteAvailabilityDate\" : ISODate(\"2020-08-10T14:03:41.898Z\")\n        },\n        \"members\" : [\n                {\n                        \"_id\" : 0,\n                        \"name\" : \"mongo1:27017\",\n                        \"health\" : 1,\n                        \"state\" : 1,\n                        \"stateStr\" : \"PRIMARY\",\n                        \"uptime\" : 850,\n                        \"optime\" : {\n                                \"ts\" : Timestamp(1597068611, 1),\n                                \"t\" : NumberLong(2)\n                        },\n                        \"optimeDate\" : ISODate(\"2020-08-10T14:10:11Z\"),\n                        \"syncSourceHost\" : \"\",\n                        \"syncSourceId\" : -1,\n                        \"infoMessage\" : \"\",\n                        \"electionTime\" : Timestamp(1597068221, 1),\n                        \"electionDate\" : ISODate(\"2020-08-10T14:03:41Z\"),\n                        \"configVersion\" : 3,\n                        \"configTerm\" : 2,\n                        \"self\" : true,\n                        \"lastHeartbeatMessage\" : \"\"\n                },\n                {\n                        \"_id\" : 1,\n                        \"name\" : \"mongo2:27017\",\n                        \"health\" : 1,\n                        \"state\" : 2,\n                        \"stateStr\" : \"SECONDARY\",\n                        \"uptime\" : 403,\n                        \"optime\" : {\n                                \"ts\" : Timestamp(1597068611, 1),\n                                \"t\" : NumberLong(2)\n                        },\n                        \"optimeDurable\" : {\n                                \"ts\" : Timestamp(1597068611, 1),\n                                \"t\" : NumberLong(2)\n                        },\n                        \"optimeDate\" : ISODate(\"2020-08-10T14:10:11Z\"),\n                        \"optimeDurableDate\" : ISODate(\"2020-08-10T14:10:11Z\"),\n                        \"lastHeartbeat\" : ISODate(\"2020-08-10T14:10:17.346Z\"),\n                        \"lastHeartbeatRecv\" : ISODate(\"2020-08-10T14:10:17.389Z\"),\n                        \"pingMs\" : NumberLong(0),\n                        \"lastHeartbeatMessage\" : \"\",\n                        \"syncSourceHost\" : \"mongo1:27017\",\n                        \"syncSourceId\" : 0,\n                        \"infoMessage\" : \"\",\n                        \"configVersion\" : 3,\n                        \"configTerm\" : 2\n                },\n                {\n                        \"_id\" : 2,\n                        \"name\" : \"mongo3:27017\",\n                        \"health\" : 1,\n                        \"state\" : 7,\n                        \"stateStr\" : \"ARBITER\",\n                        \"uptime\" : 50,\n                        \"lastHeartbeat\" : ISODate(\"2020-08-10T14:10:17.351Z\"),\n                        \"lastHeartbeatRecv\" : ISODate(\"2020-08-10T14:10:17.471Z\"),\n                        \"pingMs\" : NumberLong(0),\n                        \"lastHeartbeatMessage\" : \"\",\n                        \"syncSourceHost\" : \"\",\n                        \"syncSourceId\" : -1,\n                        \"infoMessage\" : \"\",\n                        \"configVersion\" : 3,\n                        \"configTerm\" : 2\n                }\n        ],\n        \"ok\" : 1,\n        \"$clusterTime\" : {\n                \"clusterTime\" : Timestamp(1597068611, 1),\n                \"signature\" : {\n                        \"hash\" : BinData(0,\"Pir6qAUNxIu6/AbFv6fCxpVVwOs=\"),\n                        \"keyId\" : NumberLong(\"6859346398467325956\")\n                }\n        },\n        \"operationTime\" : Timestamp(1597068611, 1)\n}\n</code></pre>\n<p>now run </p>\n<pre><code>rs.conf()\n</code></pre>\n<p>to see your config</p>\n<pre><code>rs0:PRIMARY> rs.conf()\n{\n        \"_id\" : \"rs0\",\n        \"version\" : 3,\n        \"term\" : 2,\n        \"protocolVersion\" : NumberLong(1),\n        \"writeConcernMajorityJournalDefault\" : true,\n        \"members\" : [\n                {\n                        \"_id\" : 0,\n                        \"host\" : \"mongo1:27017\",\n                        \"arbiterOnly\" : false,\n                        \"buildIndexes\" : true,\n                        \"hidden\" : false,\n                        \"priority\" : 1,\n                        \"tags\" : {\n\n                        },\n                        \"slaveDelay\" : NumberLong(0),\n                        \"votes\" : 1\n                },\n                {\n                        \"_id\" : 1,\n                        \"host\" : \"mongo2:27017\",\n                        \"arbiterOnly\" : false,\n                        \"buildIndexes\" : true,\n                        \"hidden\" : false,\n                        \"priority\" : 1,\n                        \"tags\" : {\n\n                        },\n                        \"slaveDelay\" : NumberLong(0),\n                        \"votes\" : 1\n                },\n                {\n                        \"_id\" : 2,\n                        \"host\" : \"mongo3:27017\",\n                        \"arbiterOnly\" : true,\n                        \"buildIndexes\" : true,\n                        \"hidden\" : false,\n                        \"priority\" : 0,\n                        \"tags\" : {\n\n                        },\n                        \"slaveDelay\" : NumberLong(0),\n                        \"votes\" : 1\n                }\n        ],\n        \"settings\" : {\n                \"chainingAllowed\" : true,\n                \"heartbeatIntervalMillis\" : 2000,\n                \"heartbeatTimeoutSecs\" : 10,\n                \"electionTimeoutMillis\" : 10000,\n                \"catchUpTimeoutMillis\" : -1,\n                \"catchUpTakeoverDelayMillis\" : 30000,\n                \"getLastErrorModes\" : {\n\n                },\n                \"getLastErrorDefaults\" : {\n                        \"w\" : 1,\n                        \"wtimeout\" : 0\n                },\n                \"replicaSetId\" : ObjectId(\"5f314b35458f8460ab22cda1\")\n        }\n}\n</code></pre>\n<p>Have an awesome day ahead</p>\n<p><em><a href=\"https://dev.to/tomahawkpilot/mongodb-cluster-setup-centos-7-47hh\">This post is also available on DEV.</a></em></p>\n<script>\nconst parent = document.getElementsByTagName('head')[0];\nconst script = document.createElement('script');\nscript.type = 'text/javascript';\nscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/iframe-resizer/4.1.1/iframeResizer.min.js';\nscript.charset = 'utf-8';\nscript.onload = function() {\n    window.iFrameResize({}, '.liquidTag');\n};\nparent.appendChild(script);\n</script>    "}],"site":{"siteMetadata":{"description":"Tomahawks Blog","header":{"title":"syamkumar","tagline":"Full Stack Developer and Devops SRE Engineer","background_img":"images/header-bg.jpg","has_nav":true,"nav_links":[{"label":"Home","url":"/","style":"link"},{"label":"Contact","url":"/contact/","style":"link"}],"has_social":true,"social_links":[{"label":"Twitter","url":"https://twitter.com/symkmr_syam","style":"icon","icon_class":"fa-twitter","new_window":true},{"label":"GitHub","url":"https://github.com/tomahawk-pilot","style":"icon","icon_class":"fa-github","new_window":true},{"label":"DEV","url":"https://dev.to/tomahawkpilot","style":"icon","icon_class":"fa-dev","new_window":true}]},"footer":{"content":"&copy; All rights reserved.","links":[{"label":"syam.dev","url":"https://syam.dev","style":"link","new_window":true}]},"palette":"yellow","title":"syam.dev"},"pathPrefix":"","data":{"data":{"author":{"name":"syamkumar","avatar":"https://res.cloudinary.com/practicaldev/image/fetch/s--CsiIUVL8--/c_fill,f_auto,fl_progressive,h_640,q_auto,w_640/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/285252/23378ef7-fb3e-4384-96f2-0e3a6ad0a80b.jpeg"},"social":{"devto":{"username":"tomahawkpilot"},"twitter":{"username":"symkmr_syam"},"github":{"username":"tomahawk-pilot"}}}}},"menus":{}}},"staticQueryHashes":[]}