#下载MongoDB源文件: wgethttps://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.4.7-tgzNote: wget download is slow here, it is recommended to use FTP upload after downloading with other clients#解压下载的文件tar-zxvf mongodb-linux-x86_64-rhel70-3.4.7.tgz# Rename the extracted files mv mongodb-linux-x86_64-rhel70-3.4.7 mongodb# Create a data file and log file directory for MongoDB mkdir-p/data/dbmkdir-p/data/logsNote: The file directory created here is in the root directory#进入mongodb的bin目录cd mongodb/bin# Create MongoDB configuration file Vi./mongodb.conf# Add the following information DBPath =/data/db #数据文件存放目录logpath =/data/logs/ Mongodb.log #日志文件存放目录port = 27017 #端口fork = True #以守护程序的方式启用, that is, run in the background nohttpinterface = true# Save, start mongodb./ Mongod--config mongodb.conf Setup mongodb Boot # create Mongodb.service file under/lib/systemd/system folder vi/lib/systemd/ system/mongodb.service# Add the following [unit] description=mongodb after= Network.target remote-fs.target nss-lookup.target [service] type= forking execstart=/home/mongodb/bin/mongod --config /home/mongodb/bin/mongodb.conf ExecReload=/bin/kill -s HUP $MAINPID execstop=/home/mongodb/bin/mongod -- shutdown --config /home/mongodb/bin/mongodb.conf privatetmp=true [Install] WantedBy=multi-user.target #为mongodb. Service Set Permissions chmod 754 mongodb.service #设置开机启动systemctl enable mongodb.service# to open the service systemctl restart Mongodb.service Note: If it has been started after the installation of MongoDB, starting the service here may be an error, since Port 27017 is already in use, as long as the server is restarted, and the MongoDB service will start automatically
CentOS 7 Server Configuration--Install MongoDB