Here is a script I created to quickly spin up MongoDB.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#! /bin/sh # Miscellaneous B=`tput bold` N=`tput sgr0` # Create database store mkdir /data/db chmod 775 /data/db # Download MongoDB and install cd /tmp wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.6.tgz tar zxvfz mongodb-linux-x86_64-rhel70-3.4.6.tgz mkdir -p /usr/local/mongodb mv mongodb-linux-x86_64-rhel70-3.4.6/* /usr/local/mongodb echo "${B}MongoDB${N} has been installed successfully!" echo "Starting ${B}MongoDB${N} database server" # Start MongoDB server cd /usr/local/mongodb/bin ./mongod |
Notes
By default, MongoDB will store data in /data/db
.
The script creates a /data/db
directory and configures permissions to allow only the root user and group with read, write and execute (7) permissions. Others have read and execute(5).
I recommended that you tailor permissions to your requirements.
The script then downloads MongoDB (Community Server) to the/tmp directory, unzips and moves the files to a newly created /usr/local/mongodb directory.
After this, the database server is then started.
By default, MongoDB listens on port 27017.
Now open another terminal window and start the shell.
cd /usr/local/mongodb/bin
./mongo
This will connect you to your database server. By default, you will be connected to an empty database called test.
Please note that mongod
is what is used to run the database server. mongo
is the MongoDB shell which can be used to connect to the database.