kali安装mongodb

kali安装mongodb

1. 从官网下载需要的安装包

官网下载地址:https://www.mongodb.com/download-center/community

 

 

 

下载完后可以直接用xshell登录kali,用rz命令传输到服务器上或者直接下载到kali里面。

2. 解压安装

tar zxf mongodb-linux-x86_64-debian10-4.2.2
mkdir /usr/local/mongodb
cd mongodb-linux-x86_64-debian10-4.2.2/
mv * /usr/local/mongodb/

3. 创建文件夹

cd /usr/local/mongodb/
mkdir data
cd data/
mkdir db logs

创建配置文件

cd /usr/local/mongodb/bin
vim mongodb.conf
dbpath=/usr/local/mongodb/data/db #数据文件存放目录
logpath=/usr/local/mongodb/data/logs/mongodb.log #日志文件存放目录
port=27017   #数据库端口
fork=true   #以守护方式运行,在后天运行
#auth=true   #需要认证。如果放开注释,就必须创建MongoDB的账号,使用账号与密码才可远程访问,第一次安装建议注释
bind_ip=0.0.0.0 #允许远程访问,或者直接注释,127.0.0.1只允许本地访问

4. 启动和关闭服务

开启服务

root@kali:/usr/local/mongodb/bin# ./mongod  -f  mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 3607
child process started successfully, parent exiting

mongodb的使用

root@kali:/usr/local/mongodb/bin# mongo

关闭服务

root@kali:/usr/local/mongodb/bin# mongod  -f  mongodb.conf --shutdown
2020-01-03T11:40:22.516+0800 I CONTROL [main] log file "/usr/local/mongodb/data/logs/mongodb.log" exists; moved to "/usr/local/mongodb/data/logs/mongodb.log.2020-01-03T03-40-22".
killing process with pid: 3607

配置到系统环境变量

vi /etc/profile
export PATH=$PATH:/usr/local/mongodb/bin   #在最后一行添加

错误解决

root@kali:/usr/local/mongodb/bin# mongo
MongoDB shell version v4.2.2
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-01-03T11:40:35.920+0800 E QUERY   [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-01-03T11:40:35.927+0800 F -       [main] exception: connect failed
2020-01-03T11:40:35.927+0800 E -       [main] exiting with code 1

报这个错误证明服务没有开启,重启服务就好了。

posted @ 2020-01-03 14:31  情殇王子  阅读(4263)  评论(0编辑  收藏  举报