Install mongodb3.4.9 under Linux

Environment: CentOS 7
database version: MongoDB 3.4.9 (it is recommended to install this version, the reason will be explained later)

1. Download and install MongoDB
1. First go to the official website of MongoDB to download MongoDB 3.4.9. Download address
Put the downloaded file in the /usr/local directory.
2. The default download path is to the Downloads directory under the user directory and unzip it

tar -zxvf mongodb-linux-x86_64-3.4.9.tgz

3. Move the decompressed folder to the mongodb directory of /usr/local/

mv -r mongodb-linux-x86_64-3.4.9 /usr/local/mongodb

4. Create a folder for storing data and log files, and modify its permissions to increase read and write permissions

cd /usr/local/mongodb
sudo mkdir db
sudo chmod -r 777 db
sudo mkdir logs
cd logs
touch mongodb.log

Configuration
5. Enter the bin directory, execute and edit the vi mongodb.conf file, the content is as follows:

dbpath=/usr/local/mongodb/db
logpath=/usr/local/mongodb/logs/mongodb.log
port=27017
fork=true
nohttpinterface=true

Test
6. Start the mongod database service and start it as a configuration file

cd /usr/local/mongodb/bin
./mongod -f mongodb.conf

7. Connect to mongodb database

./mongo

8. Configure system file profile

sudo vi /etc/profile

Insert the following:

export MONGODB_HOME=/usr/local/mongodb  
export PATH=$PATH:$MONGODB_HOME/bin

9. Pay attention to restart the system configuration after saving:

source /etc/profile

10. Set mongodb.service permissions

chmod 754 mongodb.service

11. The operating commands of the system mongodb.service are as follows:

#启动服务  
systemctl start mongodb.service  
#关闭服务  
systemctl stop mongodb.service  
#开机启动  
systemctl enable mongodb.service 

Congratulations, then the deployment is complete! If you encounter problems, please continue to see

2. Problems encountered during installation
1. . The mongod: error loading the while the Libraries Shared: libnetsnmpmibs.so.30: CAN not Open Shared Object File: No SUCH File or Directory
This error message saying can not find the corresponding library file, because at the beginning I was wrong installation package version , So you must pay attention to the version of your system when downloading

2. Start the service through the configuration file: mongod -f /etc/mongodb.conf
Error parsing INI config file: unrecognised option'nohttpinterface' try'./
This has been checked for a long time at the beginning, but it is because I downloaded the latest The version of mongodb, and the latest version does not seem to support starting the service in this configuration file, so I re-downloaded and installed the 3.2.12 version, and then started the service again and it was normal.
3. An error is reported when starting the service:
about to fork child process, waiting until server is ready for connections.
forked process: 11335
ERROR: child process failed, exited with error number 1

The reason for this error is the permission of the dbpath file, and the data and logs directories are added to write Permission is OK (change to 777)
4. Mongodb startup exception: about to fork child process, waiting until server is ready for connection
Use kill -9 to kill the process after mongodb restarts, and an error occurs:
about to fork child process, waiting until The server is ready for connection
error is shown in the figure:

Solution:
1. sudo kill -9 4018 to kill the child process
2. Enter the mongodb installation directory and delete the mongod.lock file in the data directory
3. In the bin directory: ./mongod --repair
4 Restart again:

sudo /usr/local/mongodb/bin/mongod --config /usr/local/mongodb/etc/mongodb.conf

Guess you like

Origin blog.csdn.net/wlc_1111/article/details/107110738