Setting up MongoDB on Windows seemed straightforward, but encountering various issues during the Linux installation process warrants a detailed walkthrough.
Begin by downloading the latest stable release from the official website, then extract it to a designated directory like /usr/local/mongodb.
After navigating into the MongoDB directory, create dedicated folders for data storage and log files.
Installation Process:
- Navigate to the
/usr/localdirectory -
cd /usr/local - Create the MongoDB installation directory
mkdir mongodb - Extract the downloaded archive and move to the target folder
tar -zxvf mongodb-linux-x86_64-2.6.7.tgz - Transfer all extracted contents to the MongoDB directory
cd mongodb-linux-x86_64-2.6.7 mv * /usr/local/mongodb - Establish data storage and logging directories
cd /usr/local/mongodb mkdir data touch logs
Adjust file permissions if insufficient access rights exist.
Starting the MongoDB Service
cd bin
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs
Common Error: ./mongod: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory
Resolution:
- When executing 32-bit applications on 64-bit systems encounter
/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory, install glibc:
yum install glibc.i686
- For error:
error while loading shared libraries: libz.so.1: cannot open shared object file: No such file or directory
yum install zlib.i686
Resume the MongoDB startup process:
cd bin
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs
Another Common Error: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
Solution: Execute command yum whatprovides libstdc++.so.6
yum whatprovides libstdc++.so.6
Example output:
[root@iZ2ze7dyjfik9i0bgl5o1cZ mongodb]# yum whatprovides libstdc++.so.6
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
libstdc++-4.4.7-18.el6.i686 : GNU Standard C++ Library
Repo : base
Matched from:
Other : libstdc++.so.6
libstdc++-4.4.7-18.el6.i686 : GNU Standard C++ Library
Repo : installed
Matched from:
Other : Provides-match: libstdc++.so.6
Attempting to install may produce the following error:
Error: Multilib version problems found. This typically indicates that the root cause stems from elsewhere and multilib version checking simply highlights existing conflicts. Examples include:
-
An upgrade exists for libstdc++ but lacks dependencies required by other packages. Yum attempts resolution by installing an older version of libstdc++ with different architecture. Excluding the problematic architecture reveals the underlying issue.
-
Multiple architectures of libstdc++ exist simultaneously, but yum detects updates for only one architecture.
-
Duplicate versions of libstdc++ remain installed.
This occurs due to library conflict between multiple architectures.
Resolution:
[root@iZ2ze7dyjfik9i0bgl5o1cZ mongodb]# yum install libstdc++-4.4.7-3.el6.i686 --setopt=protected_multilib=false
Initiate MongoDB once more:
cd bin
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs
Installation complete!
Background Service Startup
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs --fork
Background Startup with Authentication
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs --fork --auth
MongoDB should now start successfully. If already running, terminate first, configure, then restart.
Note that manual startup using mongod requires re-execution after system shutdown. To avoid this repetitive task, add mongod to auto-start services so the MongoDB service launches automatically upon system boot.
Edit /etc/rc.local and insert the following code before saving:
#add MongoDB service
rm -rf /data/mongodb_data/*
&& /usr/local/mongodb/bin/mongod --dbpath=/data/mongodb_data/ --logpath=/data/mongodb_log/mongodb.log --logappend&
Reboot the system and verify MongoDB startup. After rebooting, the mongo command should execute successfully.
Additionally, using the mongo command to connect to MongoDB requires navigating to the mongo directory and executing ./mongo. To simplify this process, copy the command file to /usr/bin, enabling mongo command usage from any directory.
Terminating Processes
netstat -anp
Identify MongoDB's process ID (e.g., 3303)
kill -9 3303
This terminates the process.