Run a mongodb ReplicaSet on a Mac using `brew services`

Viewed 24

I try to run a mongodb ReplicaSet consisting of three machines on a MacBook with M1 chip. This requires three daemons of mongod with different ports. I need this for development only, since standalone versions do NOT support database transactions and I need to debug my code.

I am not familiar with homebrew internals, I am just a user of it. The problem I have so far is, that I have no idea, how I can create three different mongodb-community formulae, which seems to be necessary to avoid name clashes.

What I have done so far:

  • created a folder where I store my individual versions of the homebrew.mxcl.mongodb-community.plist property files.
  • added three plist files named homebrew.mxcl.mongodb-community-rs1-0.plist, homebrew.mxcl.mongodb-community-rs1-1.plist, homebrew.mxcl.mongodb-community-rs1-2.plist each pointing in the ProgrammArguments tag to an individual conf files for each instance. (rs1-0 means ReplicaSet 1 node 0, rs1-1 means ReplicaSet 1 node 1, etc)
  • created a shell script which should start the entire ReplicaSet and another one to stop it.
#!/bin/zsh

# Start the mongodb replica set as services
brew services run mongodb-community --file=~/services/mongodb/runtime-config/homebrew.mxcl.mongodb-community-rs0.plist
brew services run mongodb-community --file=~/services/mongodb/runtime-config/homebrew.mxcl.mongodb-community-rs1.plist
brew services run mongodb-community --file=~/services/mongodb/runtime-config/homebrew.mxcl.mongodb-community-rs2.plist

The problem is, that this script starts the same formulae mongodb-community and I have no idea how I can give these different names. I should start them like brew service run mongodb-community-rs10 --file...., brew service run mongodb-community-rs11 --file...., etc.

The result of the above script is:

[mongodb] ./startMongoDbReplicaSet.zsh
==> Successfully ran `mongodb-community` (label: homebrew.mxcl.mongodb-community)
Service `mongodb-community` already running, use `brew services restart mongodb-community` to restart.
Service `mongodb-community` already running, use `brew services restart mongodb-community` to restart.

Does anybody know how I can get my replicaset going on a MAC?

Any help is greatly appreciated!


UPDATE: as requested the *.plist file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>homebrew.mxcl.mongodb-community</string>
  <key>ProgramArguments</key>
  <array>
    <string>/opt/homebrew/opt/mongodb-community/bin/mongod</string>
    <string>--config</string>
    <string>~/services/mongodb/mongod_rs1-0.conf</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
  <key>KeepAlive</key>
  <false/>
  <key>WorkingDirectory</key>
  <string>/opt/homebrew</string>
  <key>StandardErrorPath</key>
  <string>/opt/homebrew/var/log/mongodb/output.log</string>
  <key>StandardOutPath</key>
  <string>/opt/homebrew/var/log/mongodb/output.log</string>
  <key>HardResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>64000</integer>
  </dict>
  <key>SoftResourceLimits</key>
  <dict>
    <key>NumberOfFiles</key>
    <integer>64000</integer>
  </dict>
</dict>
</plist>

The three files only differ on line 11 where I load different .conf files (these are the config file parameters, each line in ONE of the three files) :

<string>~/services/mongodb/mongod_rs1-0.conf</string>
<string>~/services/mongodb/mongod_rs1-1.conf</string>
<string>~/services/mongodb/mongod_rs1-2.conf</string>

And here is a sample of a .conf file:

# mongod.conf suitable for MACOSX on APPLE SILICON machines only

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  logRotate: reopen
  path: /opt/homebrew/var/log/mongodb/mongod_rs0-0.log

# Where and how to store data.
storage:
  dbPath: /opt/homebrew/var/mongodb/mongod_rs0-0
  journal:
    enabled: true
    commitIntervalMs: 100
  directoryPerDB: true
  engine: "wiredTiger"
  wiredTiger:
    engineConfig:
      cacheSizeGB: 1
      journalCompressor: none
      directoryForIndexes: false
    collectionConfig:
      blockCompressor: none
    indexConfig:
      prefixCompression: false

#  mmapv1:

# how the process runs
#processManagement:
#  fork: true  # fork and run in background
#  pidFilePath: /var/run/mongodb/mongod_rs0-0.pid  # location of pidfile
#  timeZoneInfo: /usr/share/zoneinfo

# network interfaces
net:
  port: 37017
  bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

#security:

#operationProfiling:

replication:
  replSetName: "dev_pinklady_rs0"
  oplogSizeMB: 128

#sharding:

## Enterprise-Only Options

#auditLog:

#snmp:

These config files differ in the following values:

  • log path
  • database path
  • network port

Just as a remark: I got this working for about two years on Linux systems (CentOS7, Rocky 8 and Fedora). But I like to avoid installing a Hypervisor to run Linux as VM on my MacBook Air M2, since it only has 24GB RAM.

0 Answers
Related