MongoDB資料庫的兩種正確停庫方法
介紹兩種正常停止MongoDB資料庫的方法:
方法1:
kill -2法:
實驗如下:
bash-4.2$ ps -ef | grep mongo
................................................................................
mongo 3847 1 0 17:03 ? 00:00:00 /usr/libexec/gconfd-2
mongo 3898 3219 0 17:03 ? 00:00:00 /usr/bin/gnome-software --gapplication-service
mongo 3902 1 0 17:03 ? 00:00:00 /usr/libexec/tracker-store
mongo 3909 1 0 17:03 ? 00:00:03 /usr/bin/vmtoolsd -n vmusr
mongo 3954 1 0 17:03 ? 00:00:00 /usr/libexec/gvfsd-trash --spawner :1.3 /org/gtk/gvfs/exec_spaw/0
mongo 3976 3498 0 17:03 ? 00:00:00 /usr/libexec/ibus-engine-simple
mongo 3982 1 0 17:03 ? 00:00:00 /usr/libexec/evolution-calendar-factory
mongo 4226 1 0 17:04 ? 00:00:00 /usr/libexec/dconf-service
mongo 4252 3470 1 17:05 ? 00:00:56 /usr/lib64/firefox/firefox
mongo 4764 1 0 17:20 ? 00:00:00 /usr/libexec/gvfsd-metadata
mongo 5409 1 0 17:27 ? 00:00:02 /usr/libexec/gnome-terminal-server
mongo 5412 5409 0 17:27 ? 00:00:00 gnome-pty-helper
mongo 5413 5409 0 17:27 pts/0 00:00:00 bash
mongo 6173 1 0 17:29 ? 00:00:14 mongod --config /etc/mongodb.conf --rest
mongo 8388 5413 0 18:07 pts/0 00:00:00 ps -ef
mongo 8389 5413 0 18:07 pts/0 00:00:00 grep mongo
找到mongod --config那一行對應的pid,然後執行:
bash-4.2$ kill -2 6173
注意:不能使用kill -9 PID 殺死程式,這樣可能導致MongoDB資料庫損壞。
再次連線MongoDB發現報錯:
bash-4.2$ mongo
MongoDB shell version: 3.2.7-39-g8da92ea
connecting to: test
2016-07-01T18:07:54.741+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-07-01T18:07:54.741+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6
exception: connect failed
bash-4.2$
方法2:
用命令db.shutdownServer(),實驗如下:
再次啟動mongodb
bash-4.2$ mongod --config /etc/mongodb.conf --rest
about to fork child process, waiting until server is ready for connections.
forked process: 8570
child process started successfully, parent exiting
bash-4.2$ mongo
MongoDB shell version: 3.2.7-39-g8da92ea
connecting to: test
Server has startup warnings:
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten]
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten]
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.shutdownServer();
server should be down...
2016-07-01T18:13:09.344+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-07-01T18:13:09.345+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-07-01T18:13:09.345+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
>
>
>
再次連線MongoDB發現報錯:
bash-4.2$ mongo
MongoDB shell version: 3.2.7-39-g8da92ea
connecting to: test
2016-07-01T18:13:36.603+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-07-01T18:13:36.603+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6
exception: connect failed
方法1:
kill -2法:
實驗如下:
bash-4.2$ ps -ef | grep mongo
................................................................................
mongo 3847 1 0 17:03 ? 00:00:00 /usr/libexec/gconfd-2
mongo 3898 3219 0 17:03 ? 00:00:00 /usr/bin/gnome-software --gapplication-service
mongo 3902 1 0 17:03 ? 00:00:00 /usr/libexec/tracker-store
mongo 3909 1 0 17:03 ? 00:00:03 /usr/bin/vmtoolsd -n vmusr
mongo 3954 1 0 17:03 ? 00:00:00 /usr/libexec/gvfsd-trash --spawner :1.3 /org/gtk/gvfs/exec_spaw/0
mongo 3976 3498 0 17:03 ? 00:00:00 /usr/libexec/ibus-engine-simple
mongo 3982 1 0 17:03 ? 00:00:00 /usr/libexec/evolution-calendar-factory
mongo 4226 1 0 17:04 ? 00:00:00 /usr/libexec/dconf-service
mongo 4252 3470 1 17:05 ? 00:00:56 /usr/lib64/firefox/firefox
mongo 4764 1 0 17:20 ? 00:00:00 /usr/libexec/gvfsd-metadata
mongo 5409 1 0 17:27 ? 00:00:02 /usr/libexec/gnome-terminal-server
mongo 5412 5409 0 17:27 ? 00:00:00 gnome-pty-helper
mongo 5413 5409 0 17:27 pts/0 00:00:00 bash
mongo 6173 1 0 17:29 ? 00:00:14 mongod --config /etc/mongodb.conf --rest
mongo 8388 5413 0 18:07 pts/0 00:00:00 ps -ef
mongo 8389 5413 0 18:07 pts/0 00:00:00 grep mongo
找到mongod --config那一行對應的pid,然後執行:
bash-4.2$ kill -2 6173
注意:不能使用kill -9 PID 殺死程式,這樣可能導致MongoDB資料庫損壞。
再次連線MongoDB發現報錯:
bash-4.2$ mongo
MongoDB shell version: 3.2.7-39-g8da92ea
connecting to: test
2016-07-01T18:07:54.741+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-07-01T18:07:54.741+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6
exception: connect failed
bash-4.2$
方法2:
用命令db.shutdownServer(),實驗如下:
再次啟動mongodb
bash-4.2$ mongod --config /etc/mongodb.conf --rest
about to fork child process, waiting until server is ready for connections.
forked process: 8570
child process started successfully, parent exiting
bash-4.2$ mongo
MongoDB shell version: 3.2.7-39-g8da92ea
connecting to: test
Server has startup warnings:
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten]
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten]
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-07-01T18:12:42.307+0800 I CONTROL [initandlisten]
> use admin
switched to db admin
> db.shutdownServer();
server should be down...
2016-07-01T18:13:09.344+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-07-01T18:13:09.345+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-07-01T18:13:09.345+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
>
>
>
再次連線MongoDB發現報錯:
bash-4.2$ mongo
MongoDB shell version: 3.2.7-39-g8da92ea
connecting to: test
2016-07-01T18:13:36.603+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-07-01T18:13:36.603+0800 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:229:14
@(connect):1:6
exception: connect failed
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15498/viewspace-2121355/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL建立資料庫的兩種方法MySql資料庫
- ASP建立SQL Server資料庫的兩種方法SQLServer資料庫
- Java連線oracle資料庫的兩種常用方法JavaOracle資料庫
- Dedecms資料庫恢復與備份的兩種方法資料庫
- 教你兩種資料庫覆蓋式資料匯入方法資料庫
- 兩種啟動資料庫的方式資料庫
- 資料庫連線的方法種種資料庫
- python資料庫連線池的正確用法Python資料庫
- MongoDB資料庫MongoDB資料庫
- 資料庫的效能調優:如何正確的使用索引?資料庫索引
- 兩種簡單分析和優化MySQL資料庫表的方法優化MySql資料庫
- 解決MySQL的主從資料庫沒有同步的兩種方法MySql資料庫
- 50種優化資料庫的方法優化資料庫
- 訪問資料庫的幾種方法資料庫
- MongoDB 資料庫操作MongoDB資料庫
- mongodb資料庫操作MongoDB資料庫
- oracle 資料庫兩種引數檔案Oracle資料庫
- 新建Oracle資料庫三種方法Oracle資料庫
- nodejs操作mongodb資料庫(mongodb)NodeJSMongoDB資料庫
- laravel、lumen等.env檔案資料庫密碼配置正確,連不上資料庫Laravel資料庫密碼
- 連線MySQL資料庫的兩種方式介紹MySql資料庫
- 在ABAP裡取得一個資料庫表記錄數的兩種方法資料庫
- mongodb資料庫中插入資料MongoDB資料庫
- MongoDB、Cassandra 和 HBase 三種 NoSQL 資料庫比較MongoDBSQL資料庫
- 初試MongoDB資料庫MongoDB資料庫
- mongodb 如何建立資料庫MongoDB資料庫
- 快速掌握 MongoDB 資料庫MongoDB資料庫
- MongoDB資料庫安裝MongoDB資料庫
- 學習MongoDB資料庫MongoDB資料庫
- mongoDB資料庫之聚合MongoDB資料庫
- MongoDB資料庫備份MongoDB資料庫
- MongoDB資料庫入門MongoDB資料庫
- MongoDB資料庫簡介MongoDB資料庫
- Mongodb資料庫連線MongoDB資料庫
- 資料庫——MongoDB——>Java篇資料庫MongoDBJava
- MongoDB資料庫效能分析MongoDB資料庫
- 啟動MongoDB資料庫MongoDB資料庫
- 資料庫_SQL-MongoDB資料庫SQLMongoDB