Centos7上搭建MongoDB
1. 下载Mongodb
2.解压并移动到指定目录
tar -zxf mongodb-linux-x86_64-rhel70-3.6.23.tgz mv mongodb-linux-x86_64-rhel70-3.6.23 soft/mongodb
3.配置环境变量并测试
#mongodb 修改/etc/profile
export MONGODB_HOME=/opt/soft/mongodb
export PATH=$PATH:$MONGODB_HOME/bin #激活配置文件后测试 mongod -version
4.配置mongodb
#在/opt/soft/mongodb下创建mongo.conf port=27017 dbpath=/opt/soft/mongodb/data/db logpath=/opt/soft/mongodb/data/log/mongod.log logappend=true fork=true
#创建文件夹和日志文件
mkdir -p /opt/soft/mongodb/data/db mkdir -p /opt/soft/mongodb/data/log touch /opt/soft/mongodb/data/log/mongod.log
5.将Mongodb包装成linux服务
cd /lib/systemd/system touch mongodb.service #在 mongodb.service文件中写入
[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/opt/soft/mongodb/bin/mongod --config /opt/soft/mongodb/mongo.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/opt/soft/mongodb/bin/mongod --shutdown --config /opt/soft/mongodb/mongo.conf PrivateTmp=true [Install] WantedBy=multi-user.target
文件授权:
chmod 754 mongodb.service
6.启动停止开机启动命令
#查看状态
service mongodb.service status
#启动服务
systemctl start mongodb.service
#关闭服务
systemctl stop mongodb.service
#开机启动
systemctl enable mongodb.service
本文来自博客园,作者:{理想三旬},转载请注明原文链接:{https://www.cnblogs.com/zyp0519/}