b07f1711e30f4c683fce0beba8c634927d53fc94
configuration/mongo_instance_setup/README
| ... | ... | @@ -0,0 +1,3 @@ |
| 1 | +Deploy the .mount and .service units to /etc/systemd/system. |
|
| 2 | +Deploy the ephemeralvolume script to /usr/local/bin |
|
| 3 | +Deploy mongod.conf to /etc |
configuration/mongo_instance_setup/chownvarlibmongo.service
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +[Unit] |
|
| 2 | +Description=Ensures all files under /var/lib/mongo are owned by mongod user/group |
|
| 3 | +Requires=var-lib-mongo.mount |
|
| 4 | +After=var-lib-mongo.mount |
|
| 5 | +Before=mongod.service |
|
| 6 | + |
|
| 7 | +[Install] |
|
| 8 | +RequiredBy=mongod.service |
|
| 9 | + |
|
| 10 | +[Service] |
|
| 11 | +Type=oneshot |
|
| 12 | +RemainAfterExit=true |
|
| 13 | +ExecStart=/bin/chown -R mongod /var/lib/mongo/ |
|
| 14 | +ExecStart=/bin/chgrp -R mongod /var/lib/mongo/ |
configuration/mongo_instance_setup/ephemeralvolume
| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | +#!/bin/bash |
|
| 2 | + |
|
| 3 | +# Script to deploy on an instance that has an ephemeral volume as /dev/nvme0n1 (adjust env var PARTITION if different) |
|
| 4 | +# Ensures the partition is xfs-formatted, any existing partition contents will be overwritten if formatted otherwise. |
|
| 5 | +# An existing xfs partition will be left alone. |
|
| 6 | + |
|
| 7 | +PARTITION=/dev/nvme0n1 |
|
| 8 | +FSTYPE=$(blkid -p $PARTITION -s TYPE -o value) |
|
| 9 | +if [ "$FSTYPE" != "xfs" ]; then |
|
| 10 | + echo FSTYPE was "$FSTYPE" but should have been xfs. Formatting $PARTITION... |
|
| 11 | + mkfs.xfs -f $PARTITION |
|
| 12 | +else |
|
| 13 | + echo FSTYPE was "$FSTYPE" which is just right :-\) |
|
| 14 | +fi |
configuration/mongo_instance_setup/ephemeralvolume.service
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +[Unit] |
|
| 2 | +Description=Ensures /dev/nvme0n1 is XFS-formatted |
|
| 3 | +Requires=-.mount |
|
| 4 | +After=-.mount |
|
| 5 | + |
|
| 6 | +[Install] |
|
| 7 | + |
|
| 8 | +[Service] |
|
| 9 | +Type=oneshot |
|
| 10 | +RemainAfterExit=true |
|
| 11 | +ExecStart=/usr/local/bin/ephemeralvolume |
configuration/mongo_instance_setup/mongod.conf
| ... | ... | @@ -0,0 +1,49 @@ |
| 1 | +# mongod.conf |
|
| 2 | + |
|
| 3 | +# for documentation of all options, see: |
|
| 4 | +# http://docs.mongodb.org/manual/reference/configuration-options/ |
|
| 5 | + |
|
| 6 | +# where to write logging data. |
|
| 7 | +systemLog: |
|
| 8 | + destination: file |
|
| 9 | + logAppend: true |
|
| 10 | + path: /var/log/mongodb/mongod.log |
|
| 11 | + |
|
| 12 | +# Where and how to store data. |
|
| 13 | +storage: |
|
| 14 | + dbPath: /var/lib/mongo |
|
| 15 | + journal: |
|
| 16 | + enabled: true |
|
| 17 | + directoryPerDB: true |
|
| 18 | +# engine: |
|
| 19 | +# mmapv1: |
|
| 20 | +# wiredTiger: |
|
| 21 | + |
|
| 22 | +# how the process runs |
|
| 23 | +processManagement: |
|
| 24 | + fork: true # fork and run in background |
|
| 25 | + pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile |
|
| 26 | + timeZoneInfo: /usr/share/zoneinfo |
|
| 27 | + |
|
| 28 | +# network interfaces |
|
| 29 | +net: |
|
| 30 | + port: 27017 |
|
| 31 | +# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces. |
|
| 32 | +# bindIp: 172.31.33.146 |
|
| 33 | + bindIp: 0.0.0.0 |
|
| 34 | + |
|
| 35 | +#security: |
|
| 36 | + |
|
| 37 | +#operationProfiling: |
|
| 38 | + |
|
| 39 | +replication: |
|
| 40 | + replSetName: live |
|
| 41 | + |
|
| 42 | +#sharding: |
|
| 43 | + |
|
| 44 | +## Enterprise-Only Options |
|
| 45 | + |
|
| 46 | +#auditLog: |
|
| 47 | + |
|
| 48 | +#snmp: |
|
| 49 | + |
wiki/info/landscape/creating-ec2-mongodb-image-from-scratch.md
| ... | ... | @@ -1,4 +1,4 @@ |
| 1 | -# Setting up an EC2 Image for a MongoDB Replica Set from Scratch |
|
| 1 | +Setting up an EC2 Image for a MongoDB Replica Set from Scratch |
|
| 2 | 2 | |
| 3 | 3 | ## Image and Basic Packages |
| 4 | 4 | |
| ... | ... | @@ -88,35 +88,13 @@ replication: |
| 88 | 88 | #snmp: |
| 89 | 89 | ``` |
| 90 | 90 | |
| 91 | -Before being able to start the mongod service, more configuration is required. The ephemeral volume needs to be probed for an existing file system: |
|
| 91 | +To deal with the set-up of the ephemeral volume, there are a number of ``systemd`` units that can be found in the git repository at ``configuration/mongo_instance_setup``. The ``ephemeralvolume.service`` ensures that the volume exists and is formatted with the XFS file system. This service uses the ``/usr/local/bin/ephemeralvolume`` script to do so. After that, the volume is mounted to ``/var/lib/mongo`` using the ``var-lib-mongo.mount`` unit. The ownerships are adjusted after that by the ``chownvarlibmongo.service`` unit to the ``mongod`` user. This is then also the last unit required to run before the ``mongod.service``. |
|
| 92 | 92 | |
| 93 | -``` |
|
| 94 | -blkid -p /dev/nvme0n1 -s TYPE -o value |
|
| 95 | -``` |
|
| 96 | -This will output ``xfs`` if the partition contains an XFS file system already. Otherwise, formatting it is required: |
|
| 97 | -``` |
|
| 98 | -mkfs.xfs /dev/nvme0n1 |
|
| 99 | -``` |
|
| 100 | -Afterwards, the volume can be mounted, and the ownerships can be adjusted so the MongoDB daemon can write to it: |
|
| 101 | -``` |
|
| 102 | -mount /dev/nvme0n1 /var/lib/mongo |
|
| 103 | -chown mongod /var/lib/mongo/ |
|
| 104 | -chgrp mongod /var/lib/mongo/ |
|
| 105 | -``` |
|
| 106 | - |
|
| 107 | -Then execute ``systemctl start mongod.service`` to launch the MongoDB process. |
|
| 93 | +Then execute ``systemctl enable mongod.service`` to launch the MongoDB process and ensure it is always launched when the instance (re-)boots. |
|
| 108 | 94 | |
| 109 | 95 | ## MongoDB Replica Set Configuration |
| 110 | 96 | |
| 111 | 97 | Connect to the MongoDB on that instance, then issue the command ``rs.initiate()`` in order to turn the instance into the "seed" of a replica set. You can then, for the time being, ``quit()`` the mongo shell. Re-connecting, e.g., with ``mongo "mongodb://localhost:27017/?replicaSet=live"``, will show the ``PRIMARY`` of the new replica set. |
| 112 | 98 | |
| 113 | 99 | |
| 114 | -TODO: not functional yet; clients don't see the PRIMARY because it wants to re-direct to localhost/127.0.0.1. rs.config() shows the issue: |
|
| 115 | - |
|
| 116 | -``` |
|
| 117 | - "members" : [ |
|
| 118 | - { |
|
| 119 | - "_id" : 0, |
|
| 120 | - "host" : "localhost:27017", |
|
| 121 | - ... |
|
| 122 | -``` |
|
| 100 | +TODO: automate the initialization and replica set extension using "Addition Details" in the instance; create a MongoDB script that is executed during start-up; if no replica set exists and no user detail specifies where the primary is, run ``rs.initiate()``. If a replica set already exists, leave things unchanged. If no replica set exists and in a user detail something like ``REPLICA_SET_NAME=...`` and ``REPLICA_SET_PRIMARY=...`` is provided, add the local node as a secondary to the primary / replica set specified. |