1. Startseite
  2. Anleitungen
  3. Ausführen von MongoDB

Ausführen von MongoDB

Übersicht

MongoDB is fast, document-oriented NoSQL server. It’s complementary to key-value cache stores like Redis or Memcached and is suitable when necessary. It is available on newer platforms (v6+) without any additional compilation from source. Accounts with terminal access are eligible to use MongoDB.

Schnellstart

  1. From the Terminal, first create a directory to store MongoDB data:
    • mkdir ~/mongodb
      • A directory named mongodb within your home directory will be created. If the user logged is in named example, then a directory named /home/example/mongodb will be created
  2. Now start the server. Substitute PORT for a preassigned port for your account:
    • mongod --bind_ip 127.0.0.1 --port PORT --dbpath ~/mongodb --logpath ~/mongo.log --pidfilepath ~/mongodb.pid --fork
    • MongoDB is now running, accessible by a local TCP/IP socket bound to port PORT.

Hinweis: use 127.0.0.1 to prevent outside network activity. 127.0.0.1 will only allow traffic that originates from the same server. A better solution, if using Node.js oder Schiene application, is to specify --unixSocketPrefix /tmp/mongodb.sock anstelle von --bind_ip/--port to specify a local UNIX domain socket instead of a TCP socket.

Configuring & Daemonizing

Now with MongoDB up and running, you can create a long-term solution that starts up with the server and always runs in the background. Start with the configuration template provided above, making sure to update the port parameter to a port assigned to your account.

Note: as with most configuration files, any line that begins with a octothorpe/pound/hash symbol (#) denotes a comment. These are never interpreted by an application, but serve as guidance. The following configuration omits these helpful comments for brevity.

Copy and paste the following content to a file named mongodb.conf in your home directory:

bind_ip = 127.0.0.1 
############
# Substitute with a PORT assigned to your account
############
port = PORT 
# run as a service
fork = true 
############
# Substitute /home/example for your HOME DIRECTORY
############
pidfilepath = /home/example/mongod.pid 
logpath = /home/example/mongodb.log 
dbpath = /home/example/mongodb 
journal = true
nohttpinterface = true

A quick and easy way to do this is with Vim, a text-editor available through the terminal:

  1. vim ~/mongodb.conf
  2. Type i on the keyboard to switch to “Insert” mode
    • Depending upon client, paste the text through CTRL + V, Shift + INS, or a suitable key combination
  3. Hit the Esc(ape) key.
  4. Type :wq
  5. Done!

Now to start MongoDB using the configuration, type: mongod -f ~/mongodb.conf

Starting on Start-up

  1. Visit DevTask Scheduler innerhalb der Bedienfeld to schedule a new task.
  2. Under Command, enter mongodb ~/mongodb.conf
  3. Under Scheduling, select Server Start
  4. Click Add

Siehe auch

Aktualisiert am März 7, 2021

Verwandte Artikel