呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜呜
吓死我了还以为自己要删库跑路了
关闭mongodb不可以使用kill -9!!!!
不可以使用kill -9!!!!!!!!
不可以使用kill -9!!!!!!!!!
但是一不小心使用了怎么办呢,慢慢恢复吧orz
参考了很多大佬的文章:
http://blog.itpub.net/26995414/viewspace-733012/
https://www.cnblogs.com/ctypyb2002/p/9793055.html
kill -9之后发现启动失败!搞了半天!终于搞好了!吓得我一身冷汗
其实主要原因是由于是非正常退出,mongo把它的数据库锁死了 不让用了。
注意:以下大部分操作需要管理员权限
进入管理员权限:
sudo -s然后输密码就进去了。
试探性开启数据库
一般情况下数据库放置在 /var/lib/mongodb 下,被我kill -9 锁死的数据库是这个路径
但是mongod 的默认路径是 /data/db 所以直接输入
/usr/bin/mongod是可以正常运行的。/data/db 没被锁死。 只不过 /data/db 里面也没有数据啊orz
尝试使用原先的数据库运行:
/usr/bin/mongod --dbpath /var/lib/mongodb/失败了。那就是这个数据库有问题。
删除上锁的文件并进行恢复
这里按照大佬操作,删掉 mongod.lock 和 storage.bson。mongod.lock的内容是被我kill掉的那个进程号。
cd /var/lib/mongodb
rm mongod.lock
rm storage.bson
mongod --dbpath /var/lib/mongodb --repair 一般情况下这样就好了。然后直接去重启mongodb就可以了。
然后大佬有一个我没用上的操作:
# cd ./journal # ls -l 总用量 84904 -rw-r--r-- 1 mongodb mongodb 86924928 2月 23 20:47 WiredTigerLog.0000260433 -rw-r--r-- 1 mongodb mongodb 128 2月 23 20:47 WiredTigerLog.0000260434 -rw-r--r-- 1 mongodb mongodb 128 2月 23 20:47 WiredTigerLog.0000260435 -rw-r--r-- 1 root root 128 2月 23 20:47 WiredTigerLog.0000260436 # chown mongodb:mongodb WiredTigerLog.0000260436
这个操作是因为,./journal 下的数据里面,有一个是root的权限,大佬把那个root的权限文件改成了mongodb,让mongodb可以用。
我这里面所有的文件都是mongodb的权限,就不需要这一步了。
然后重启服务。
正确的mongo关闭姿势:
记一下记一下。。。呜呜呜
输入mongo命令:
zzh@server1:~/mongolog$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
Server has startup warnings:
2019-09-26T11:25:52.180+0800 I STORAGE [initandlisten]
2019-09-26T11:25:52.180+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2019-09-26T11:25:52.180+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten]
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten]
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2019-09-26T11:25:58.512+0800 I CONTROL [initandlisten]
2019-09-26T11:25:58.514+0800 I CONTROL [initandlisten]
2019-09-26T11:25:58.514+0800 I CONTROL [initandlisten] ** WARNING: You are running on a NUMA machine.
2019-09-26T11:25:58.514+0800 I CONTROL [initandlisten] ** We suggest launching mongod like this to avoid performance problems:
2019-09-26T11:25:58.514+0800 I CONTROL [initandlisten] ** numactl --interleave=all mongod [other options]
2019-09-26T11:25:58.514+0800 I CONTROL [initandlisten]
>
一堆警告,可以不看,最后进入monggo的命令行,输入use admin
2019-09-26T11:25:58.514+0800 I CONTROL [initandlisten]
> use admin
然后在输入db.shutdownServer();
如果db.shutdownServer();显示权限不够失败了,就登录一下root获取权限。
然后等待就可以了,ctrl+C退出。别急,我等了十几秒吧它才退出的。。。
下面红色的是要你输入的
2019-09-26T11:25:58.514+0800 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.auth("root","password")
1
> db.shutdownServer();
server should be down...
2019-09-26T11:28:08.308+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2019-09-26T11:28:08.308+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2019-09-26T11:28:08.308+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
> ^C
bye
还会跟你说bye,怪可爱的
然后查看一下进程:
zzh@server1:~/mongolog$ ps -efa |grep mongo
zzh 28155 14104 0 12:08 pts/18 00:00:00 grep --color=auto mongo
确实关掉了。