CentOS下安装MongoDB
官网提供windows、Linux、OSX系统环境下的安装包,这里主要是记录一下在Linux下的安装。首先到官网下载安装包。这里下载的是4.0.28版本的。
·
CentOS下安装MongoDB
官网提供windows、Linux、OSX系统环境下的安装包,这里主要是记录一下在Linux下的安装。首先到官网下载安装包。这里下载的是4.0.28版本的。
官网地址:https://www.mongodb.com/
解压
tar -zxvf mongodb-linux-x86_64-rhel70-4.0.28.tgz
重命名
mv ./mongodb-linux-x86_64-rhel70-4.0.28 ./mongodb
添加data目录和logs目录
mkdir data
mkdir logs
添加配置文件
vi mongodb.conf
mongodb.conf
##auth = true # 先关闭, 创建好用户在启动
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
#path: /var/log/mongodb/mongod.log
path: /home/mongodb/logs/mongod.log
# Where and how to store data.
storage:
#dbPath: /var/lib/mongo
dbPath: /home/mongodb/data
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
#pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
pidFilePath: /home/mongodb/mongod.pid # location of pidfile
timeZoneInfo: /usr/share/zoneinfo
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting. # 为了让远端可以访问
参数解释:
- dbPath: 数据库存放位置
- path:日志存放位置
- port:监听端口
- fork:是否后台运行
配置环境变量,方便使用mongod命令
这里放置到home目录下
export MONGODB_HOME=/home/mongodb
export PATH=$PATH:${JAVA_PATH}:$MONGODB_HOME/bin
查看mongod版本
[root@localhost ~]# mongod -v
启动
./bin/mongod -f mongodb.conf
如果报错
ERROR:child process failed,exited with error number 48
则修复启动
./bin/mongod -f mongodb.conf --repair
如果出现successful则表示启动成功
检查服务是否启动
[root@localhost ~]# ps -ef|grep mongod
root 9579 1 0 7月27 ? 00:24:59 ./bin/mongod -f mongodb.conf
root 21523 11293 0 16:28 pts/0 00:00:00 grep --color=auto mongod
进入数据库
./mongo
或者
./mongo 127.0.0.1
或者
./mongo --port 27017 # 进入端口27017的mongod实例
查看数据列表
show dbs;
查看版本
db.version()
查看所有的用户
#查看所有用户
show users
查看当前数据库的用户
show users # 查看当前数据库的用户
更多推荐
已为社区贡献5条内容
所有评论(0)