1.安装centos系统
没有安装的小伙伴可以看一下 centos详细安装步骤
2.下载mongodb-linux版安装包
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.1.tgz
3.下载完成之后放到你的linux文件下进行解压
tar -zxvf mongodb-linux-x86_64-rhel70-4.0.1.tgz -C /opt/
可以修改一下安装夹的名称
mv mongodb-linux-x86_64-rhel70-4.0.0 mongodb
4.创建数据存储目录和日志文件目录
mkdir -p /opt/mongodb/data/db
mkdir -p /opt/mongodb/logs
5、编辑MongoDB启动配置文件
在/opt/mongodb/bin文件夹下创建一个mongodb.conf文件,手动创建并编辑。
vim /opt/mongodb/bin/mongodb.conf
添加上下面配置
dbpath = /opt/mongodb/data/db //数据存储目录
logpath =/opt/mongodb/logs/mongodb.log //日志文件目录
fork = true //后台运行
auth=true
bind_ip=0.0.0.0
6、添加到 PATH 路径
vim /etc/profile
export MONGODB_HOME=/opt/mongodb
export PATH=$PATH:$MONGODB_HOME/bin
source /etc/profile //重新加载环境变量
7、启动MongoDB
进入MongoDB启动
cd /opt/mongodb/bin
mongod -f mongodb.conf
一般这里会报错
2021-07-29T14:31:33.220+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
about to fork child process, waiting until server is ready for connections.
forked process: 16751
ERROR: child process failed, exited with error number 1
To see additional information in this output, start without the "--fork" option.
解决方案:
指向data文件和log日志文件的问题 运行下边脚本就OK
/opt/mongodb/bin/mongod --dbpath /opt/mongodb/data/db/ --logpath /opt/mongodb/log/mongod.log --fork
然后进入
cd /opt/mongodb/bin
运行命令
./mongo