官網下載地址:https://www.mongodb.com/download-center/communitylinux
下載完後能夠直接用xshell登陸kali,用rz命令傳輸到服務器上或者直接下載到kali裏面。mongodb
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/
cd /usr/local/mongodb/
mkdir data
cd data/
mkdir db logs
建立配置文件shell
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只容許本地訪問
開啓服務數據庫
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的使用vim
root@kali:/usr/local/mongodb/bin# mongo
關閉服務api
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
spa