{"id":13780597,"url":"https://github.com/sous-chefs/sc-mongodb","last_synced_at":"2025-04-09T14:09:54.637Z","repository":{"id":31745633,"uuid":"35311705","full_name":"sous-chefs/sc-mongodb","owner":"sous-chefs","description":"Development repository for the sc-mongodb cookbook","archived":false,"fork":false,"pushed_at":"2024-07-15T16:32:48.000Z","size":838,"stargazers_count":75,"open_issues_count":37,"forks_count":91,"subscribers_count":24,"default_branch":"main","last_synced_at":"2024-10-29T21:32:00.272Z","etag":null,"topics":["chef","chef-cookbook","chef-resource","hacktoberfest","managed-by-terraform","sc-mongodb"],"latest_commit_sha":null,"homepage":"https://supermarket.chef.io/cookbooks/sc-mongodb","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sous-chefs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"sous-chefs"}},"created_at":"2015-05-09T02:27:17.000Z","updated_at":"2024-07-15T16:32:51.000Z","dependencies_parsed_at":"2024-04-12T14:38:58.305Z","dependency_job_id":"6fd7249a-8301-4795-96e8-4f0ca5a59db2","html_url":"https://github.com/sous-chefs/sc-mongodb","commit_stats":{"total_commits":730,"total_committers":130,"mean_commits":5.615384615384615,"dds":0.863013698630137,"last_synced_commit":"e850042f320eb907430a3e92ea7775cd1d726320"},"previous_names":[],"tags_count":62,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sous-chefs%2Fsc-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sous-chefs%2Fsc-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sous-chefs%2Fsc-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sous-chefs%2Fsc-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sous-chefs","download_url":"https://codeload.github.com/sous-chefs/sc-mongodb/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247351955,"owners_count":20925183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chef","chef-cookbook","chef-resource","hacktoberfest","managed-by-terraform","sc-mongodb"],"created_at":"2024-08-03T18:01:17.630Z","updated_at":"2025-04-09T14:09:54.612Z","avatar_url":"https://github.com/sous-chefs.png","language":"Ruby","funding_links":["https://opencollective.com/sous-chefs"],"categories":["Cookbooks"],"sub_categories":["Database"],"readme":"# sc-MongoDB Cookbook\n\n[![Cookbook Version](https://img.shields.io/cookbook/v/sc-mongodb.svg)](https://supermarket.chef.io/cookbooks/sc-mongodb)\n[![CI State](https://github.com/sous-chefs/mongodb/workflows/ci/badge.svg)](https://github.com/sous-chefs/mongodb/actions?query=workflow%3Aci)\n[![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers)\n[![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors)\n[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0)\n\nInstalls and configures MongoDB\n\n## Maintainers\n\nThis cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit [sous-chefs.org](https://sous-chefs.org/) or come chat with us on the Chef Community Slack in [#sous-chefs](https://chefcommunity.slack.com/messages/C2V7B88SF).\n\n## Supports\n\n- Single MongoDB instance\n- Replication\n- Sharding\n- Replication and Sharding\n- MongoDB Monitoring System\n\n## Requirements\n\n### Cookbooks\n\n- none\n\n### Chef Infra Client\n\n- Chef Infra Client 14+\n\n### Platform\n\nCurrently we 'actively' test using test-kitchen on Ubuntu, Debian, CentOS, Redhat\n\n## Definitions\n\nThis cookbook contains a definition `mongodb_instance` which can be used to configure\na certain type of mongodb instance, like the default mongodb or various components\nof a sharded setup.\n\nFor examples see the USAGE section below.\n\n## Attributes\n\n### MongoDB setup\n\n- `default['mongodb']['install_method']` - This option can be \"mongodb-org\" or \"none\" - Default (\"mongodb-org\")\n\n### MongoDB Configuration\n\nThe `node['mongodb']['config']` is split into 2 keys, `mongod` and `mongos` (i.e. node['mongodb']['config']['mongod']). They attributes are rendered out as a yaml config file. All settings defined in the Configuration File Options documentation page can be added to the `node['mongodb']['config'][\u003csetting\u003e]` attribute: [https://docs.mongodb.com/manual/reference/configuration-options/](https://docs.mongodb.com/manual/reference/configuration-options/)\n\nSeveral important attributes to note:\n\n- `node['mongodb']['config']['mongod']['net']['bindIp']` - Configure from which address to accept connections\n- `node['mongodb']['config']['mongod']['net']['port']` - Port the mongod listens on, default is 27017\n- `node['mongodb']['config']['mongod']['replication']['oplogSizeMB']` - Specifies a maximum size in megabytes for the replication operation log\n- `node['mongodb']['config']['mongod']['storage']['dbPath']` - Location for mongodb data directory, defaults to \"/var/lib/mongodb\"\n- `node['mongodb']['config']['mongod']['storage']['engine']` - Storage engine to use, default is `\"wiredTiger\"`\n- `node['mongodb']['config']['mongod']['systemLog']['path']` - Path for the logfiles, default is `\"/var/lib/mongo\"` for `rhel` and `fedora` and `\"/var/log/mongodb/mongod.log\"` for all others\n- `node['mongodb']['config']['mongod'][\u003csetting\u003e]` - General MongoDB Configuration File option\n\n### Cookbook specific attributes\n\n- `node['mongodb']['reload_action']` - Action to take when MongoDB conf files are modified, default is `\"restart\"`\n- `node['mongodb']['package_version']` - Version of the MongoDB package to install, default is nil\n- `node['mongodb']['client_roles']` - Role identifying all external clients which should have access to a mongod instance\n\n### Sharding and replication attributes\n\n- `node['mongodb']['config']['mongod']['replication']['replSetName']` - Define name of replicaset\n- `node['mongodb']['cluster_name']` - Name of the cluster, all members of the cluster must reference to the same name, as this name is used internally to identify all members of a cluster.\n- `node['mongodb']['shard_name']` - Name of a shard, default is \"default\"\n- `node['mongodb']['sharded_collections']` - Define which collections are sharded\n- `node['mongodb']['replica_arbiter_only']` - Set to true to make node an [arbiter](http://docs.mongodb.org/manual/reference/replica-configuration/#local.system.replset.members[n].arbiterOnly).\n- `node['mongodb']['replica_build_indexes']` - Set to false to omit [index creation](http://docs.mongodb.org/manual/reference/replica-configuration/#local.system.replset.members[n].buildIndexes).\n- `node['mongodb']['replica_hidden']` - Set to true to [hide](http://docs.mongodb.org/manual/reference/replica-configuration/#local.system.replset.members[n].hidden) node from replicaset.\n- `node['mongodb']['replica_slave_delay']` - Number of seconds to [delay slave replication](http://docs.mongodb.org/manual/reference/replica-configuration/#local.system.replset.members[n].slaveDelay).\n- `node['mongodb']['replica_priority']` - Node [priority](http://docs.mongodb.org/manual/reference/replica-configuration/#local.system.replset.members[n].priority).\n- `node['mongodb']['replica_tags']` - Node [tags](http://docs.mongodb.org/manual/reference/replica-configuration/#local.system.replset.members[n].tags).\n- `node['mongodb']['replica_votes']` - Number of [votes](http://docs.mongodb.org/manual/reference/replica-configuration/#local.system.replset.members[n].votes) node will cast in an election.\n\n### shared MMS Agent attributes\n\n- `node['mongodb']['mms_agent']['api_key']` - MMS Agent API Key. No default, required.\n- `node['mongodb']['mms_agent']['automation']['config'][\u003csetting\u003e]` - General MongoDB MMS Automation Agent configuration file option.\n- `node['mongodb']['mms_agent']['backup']['config'][\u003csetting\u003e]` - General MongoDB MMS Monitoring Agent configuration file option.\n- `node['mongodb']['mms_agent']['monitoring']['config'][\u003csetting\u003e]` - General MongoDB MMS Monitoring Agent configuration file option.\n\n#### Automation Agent Settings\n\nThe defaults values installed by the package are:\n\n```toml\nmmsBaseUrl=https://mms.mongodb.com\nlogFile=/var/log/mongodb-mms-automation/automation-agent.log\nmmsConfigBackup=/var/lib/mongodb-mms-automation/mms-cluster-config-backup.json\nlogLevel=INFO\nmaxLogFiles=10\nmaxLogFileSize=268435456\n```\n\n#### Backup Agent Settings\n\nThe defaults values installed by the package are:\n\n```toml\nmothership=api-backup.mongodb.com\nhttps=true\n```\n\n#### Monitoring Agent Settings\n\nThe defaults values installed by the package are:\n\n```toml\nmmsBaseUrl=https://mms.mongodb.com\n```\n\n### User management attributes\n\n- `node['mongodb']['config']['auth']` - Require authentication to access or modify the database (`True` or `False`), Default is `nil`\n- `node['mongodb']['admin']` - The admin user with userAdmin privileges that allows user management\n- `node['mongodb']['users']` - Array of users to add when running the user management recipe\n\n## Usage\n\n### Single mongodb instance\n\nSimply add\n\n```ruby\ninclude_recipe \"sc-mongodb::default\"\n```\n\nto your recipe. This will run the mongodb instance as configured by your distribution.\nYou can change the dbpath, logpath and port settings (see ATTRIBUTES) for this node by\nusing the `mongodb_instance` definition:\n\n```ruby\nmongodb_instance \"mongodb\" do\n  port node['application']['port']\nend\n```\n\nThis definition also allows you to run another mongod instance with a different\nname on the same node\n\n```ruby\nmongodb_instance \"my_instance\" do\n  port node['mongodb']['port'] + 100\nend\n```\n\nThe result is a new system service with\n\n```shell\n  /etc/init.d/my_instance \u003cstart|stop|restart|status\u003e\n```\n\n### Replicasets\n\nAdd `sc-mongodb::replicaset` (instead of `sc-mongodb::default`) to the node's run_list. Also choose a name for your\nreplicaset cluster and set the value of `node['mongodb']['cluster_name']` for each\nmember to this name.\n\nThe recipe will try to configure the replicaset with the instances already registered in your chef-server with the same\n`node['mongodb']['cluster_name']`, to configure various machines with the replicaset you'll need to deactivate the\nautomatic configuration with `node['mongodb']['auto_configure']['replicaset'] = false` and enable that flag only on the last\ninstance of the replicaset.\n\n### Sharding\n\nYou need a few more components, but the idea is the same: identification of the\nmembers with their different internal roles (mongos, configserver, etc.) is done via\nthe `node['mongodb']['cluster_name']` and `node['mongodb']['shard_name']` attributes.\n\nLet's have a look at a simple sharding setup, consisting of two shard servers, one\nconfig server and one mongos.\n\nFirst, we would like to configure the two shards. For doing so, just use\n`sc-mongodb::shard` in the node's run_list and define a unique `mongodb['shard_name']`\nfor each of these two nodes, say \"shard1\" and \"shard2\".\n\nThen configure a node to act as a config server - by using the `sc-mongodb::configserver`\nrecipe.\n\nAnd finally, you need to configure the mongos. This can be done by using the\n`sc-mongodb::mongos` recipe. The mongos needs some special configuration, as these\nmongos are actually doing the configuration of the whole sharded cluster.\nMost importantly you need to define what collections should be sharded by setting the\nattribute `mongodb['sharded_collections']`:\n\n```ruby\n{\n  \"mongodb\": {\n    \"sharded_collections\": {\n      \"test.addressbook\": \"name\",\n      \"mydatabase.calendar\": \"date\"\n    }\n  }\n}\n```\n\nNow mongos will automatically enable sharding for the \"test\" and the \"mydatabase\"\ndatabase. Also, the \"addressbook\" and the \"calendar\" collection will be sharded,\nwith sharding key \"name\" resp. \"date\".\nIn the context of a sharding cluster always keep in mind to use a single role\nwhich is added to all members of the cluster to identify all member nodes.\nAlso, shard names are important to distinguish the different shards.\nThis is esp. important when you want to replicate shards.\n\n### Sharding + Replication\n\nThe setup is not much different from the one described above. All you have to do is add the\n`sc-mongodb::replicaset` recipe to all shard nodes, and make sure that all shard\nnodes which should be in the same replicaset have the same shard name.\n\nFor more details, you can find a [tutorial for Sharding + Replication](https://github.com/edelight/chef-mongodb/wiki/MongoDB%3A-Replication%2BSharding) in the wiki.\n\n### MMS Agent\n\nThis cookbook also includes support for\n[MongoDB Monitoring System (MMS)](https://mms.mongodb.com/)\nagent. MMS is a hosted monitoring service, provided by MongoDB, Inc. Once\nthe small agent program is installed on the MongoDB host, it\nautomatically collects the metrics and uploads them to the MMS server.\nThe graphs of these metrics are shown on the web page. It helps a lot\nfor tackling MongoDB related problems, so MMS is the baseline for all\nproduction MongoDB deployments.\n\nTo setup MMS, simply set your keys in\n`node['mongodb']['mms_agent']['api_key']` and then add the\n`sc-mongodb::mms_monitoring_agent` recipe to your run list. Your current keys\nshould be available at your [MMS Settings page](https://mms.mongodb.com/settings).\n\nThe agent install and configurations is also available via a custom resource for\nwrapper cookbooks.  This allows for further customization outside of this\ncookbook\n\n```ruby\nmongodb_agent 'monitoring' do\n  config {} # Key and value pairs that will be in the config file\n  group 'group' # Group to own the config file\n  package_url 'package_url' # Download URL of the agent package\n  user 'user' # User to own the config file\nend\n```\n\n### User Management\n\n--NOTE:-- Using the `sc-mongodb::user_management` is not secure since passwords are stored plain\ntext in your node attributes.  Please concider using a wrapper recipe with encrypted data bags\nwhen using this cookbook in production.\n\nAn optional recipe is `sc-mongodb::user_management` which will enable authentication in\nthe configuration file by default and create any users in the `node['mongodb']['users']`.\nThe users array expects a hash of username, password, roles, and database. Roles should be\nan array of roles the user should have on the database given.\n\nBy default, authentication is not required on the database. This can be overridden by setting\nthe `node['mongodb']['config']['auth']` attribute to true in the chef json.\n\nIf the auth configuration is true, it will try to create the `node['mongodb']['admin']` user, or\nupdate them if they already exist. Before using on a new database, ensure you're overwriting\nthe `node['mongodb']['authentication']['username']` and `node['mongodb']['authentication']['password']` to\nsomething besides their default values.\n\nTo update the admin username or password after already having deployed the recipe with authentication\nas required, simply change `node['mongodb']['admin']['password']` to the new password while keeping the\nvalue of `node['mongodb']['authentication']['password']` the old value. After the recipe runs successfully,\nbe sure to change the latter variable to the new password so that subsequent attempts to authenticate will\nwork.\n\nThere's also a user resource which has the actions `:add`, `:modify` and `:delete`. If modify is\nused on a user that doesn't exist, it will be added. If add is used on a user that exists, it\nwill be modified.\n\nIf using this recipe with replication and sharding, ensure that the `node['mongodb']['key_file_content']`\nis set. All nodes must have the same key file in order for the replica set to initialize successfully\nwhen authentication is required. For mongos instances, set `node['mongodb']['mongos_create_admin']` to\n`true` to force the creation of the admin user on mongos instances.\n\n## Contributors\n\nThis project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890\u0026button=false)\n\n### Backers\n\nThank you to all our backers!\n\n![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600\u0026avatarHeight=40)\n\n### Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website.\n\n![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100)\n![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsous-chefs%2Fsc-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsous-chefs%2Fsc-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsous-chefs%2Fsc-mongodb/lists"}