1, 下载
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.6.3.tgz
2, 解压
tar zxvf mongodb-linux-x86_64-amazon-3.6.3.tgz
3, 移动
mv mongodb-linux-x86_64-amazon-3.6.3 /usr/local/mongodb
备注: 不用编译, 本身就是编译后的二进制执行文件
4, 添加配置文件
vim /usr/local/mongodb/bin/mongodb.conf
复制下面代码
- # 数据库文件路径
- dbpath=/usr/local/mongodb/data/db/
- # 日志文件路径
- logpath=/usr/local/mongodb/data/log/mongodb.log
- # 是否追加日志
- logappend=true
- # 端口
- port=27017
- # 是否后台程序启动
- fork=true
- # 是否启动授权认证
- auth=true
备注: 需创建数据库, 日志目录
5, 配置 mongodb 服务
vim /lib/systemd/system/mongodb.service
复制如下代码
- [Unit]
- Description=mongodb
- After=network.target remote-fs.target nss-lookup.target
- [Service]
- Type=forking
- ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf
- ExecReload=/bin/kill -s HUP $MAINPID
- ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/bin/mongodb.conf
- PrivateTmp=true
- [Install]
- WantedBy=multi-user.target
6, 开机启动
- # 开机启动
- systemctl enable mongodb.service
- # 启动服务
- systemctl start mongodb.service
- # 停止服务
- systemctl stop mongodb.service
来源: http://www.bubuko.com/infodetail-2697629.html