本文共 1455 字,大约阅读时间需要 4 分钟。
在CentOS 7环境下安装MongoDB,首先需要从MongoDB官网下载适合系统版本的安装包。本文基于MongoDB 3.6.4进行安装。访问MongoDB官网,选择合适的版本下载安装包,下载链接如下:
cd /data/softwarewget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.6.4.tgz
下载完成后,解压并重命名文件夹为mongodb:
tar -zxf mongodb-linux-x86_64-3.6.4.tgzmv mongodb-linux-x86_64-3.6.4.tgz mongodb
接下来,创建必要的目录结构:
cd mongodbmkdir dbmkdir logsmkdir conf
创建完成后,目录结构如下:
[root@bigdata1 mongodb]# llsdrwxr-xr-x. 2 root root 248 May 5 10:25 ..drwxr-xr-x. 2 root root 26 May 5 10:48 confdrwxr-xr-x. 4 root root 4096 May 5 10:55 db...
在conf目录下新建配置文件mongodb.conf,并设置以下内容:
cd conftouch mongodb.confvi mongodb.conf
配置内容如下:
# 端口号(默认端口)port = 27017# 数据库目录dbpath = /data/software/mongodb/db# 日志目录logpath = /data/software/mongodb/logs/mongodb.log# 日志文件自动追加logappend = true# 以守护进程方式运行fork = true# 禁止HTTP管理接口(如需启用,请注释该行)# nohttpinterface = true# 绑定IP(如需指定接口)bind_ip = 10.153.4.555
通过脚本启动MongoDB:
cd /data/software/mongodb./bin/mongod -f conf/mongodb.conf --fork
验证启动状态:
ps -ef | grep mongodb
使用MongoDB客户端工具连接:
./bin/mongo 10.153.4.555:27017
进入MongoDB REPL并执行基本操作:
use admindb.runoob.insert({"name":"菜鸟教程"})db.runoob.find().pretty() 建议通过MongoDB shell命令关闭:
db.shutdownServer()
kill -9或15信号:这可能导致数据丢失,建议使用mongod --shutdown或mongo --eval 'db.shutdownServer()'。通过以上步骤,用户可以在CentOS 7上成功安装并配置MongoDB,确保数据库运行稳定。
转载地址:http://jmefk.baihongyu.com/