一角寸、安裝步驟一切ok
啟動時
$ sudo service mongodb start
#報錯
couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
#停止時
$ sudo service mongodb stop
#報錯
unknown instance
搜了下有人這樣解決了:
- Step 1: Remove lock file.sudo rm /var/lib/mongodb/mongod.lock
- Step 2: Repair mongodb. sudo mongod --repair
- Step 3: start mongodb.sudo start mongodb orsudo service mongodb start
- Step 4: Check status of mongodb.sudo status mongodb or sudo service mongodb status
- Step 5: Start mongo console.mongo
但我也試了宅静,卻沒有解決...
卸載之前裝的mongodb
$ sudo apt-get purge mongodb-org
$ sudo apt-get autoremoveRemove the old mongodb.list you created
$ sudo rm /etc/apt/sources.list.d/mongodb.list
準備重新安裝批钠,由失敗到成功结序,整理了一下:
- 執(zhí)行命令
sudo apt-get install mongodb-server
- 進入目錄
vim ~/.bashrc
- 添加此句
$ export PATH=/home/yhl/mongodb-linux/bin:$PATH
- 查看版本號
$ mongod -version
$ mkdir data
$ mkdir log
$ mongod --dbpath data/ --logpath log/mongodb.log -logappend --fork
- 最后將啟動命令保存在start中梅掠,方便下次啟動使用(親測成功)
$ echo "mongod --dbpath data/ --logpath log/mongodb.log -logappend --fork">> [start.sh](http://start.sh/)
二圆存、補充一下之前遇到的問題:
sudo service mongod start
Failed to start mongod.service: Unit mongod.service failed to load:
No such file or directory.
添加以下內(nèi)容:
[Unit]
Description=High-performance, schema-free document-oriented database
Documentation=man:mongod(1)
After=network.target
[Service]
Type=forking
User=mongodb
Group=mongodbRuntime
Directory=mongodPIDFile=/var/run/mongod/mongod.pid
ExecStart=/usr/bin/mongod -f /etc/mongod.conf --pidfilepath /var/run/mongod/mongod.pid --fork
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
就可以解決了。