在打开mongod之后如果不用了就按ctrl + c ,就不会出现以下的问题了
执行mongod报错
mongod
2016-08-03T14:31:15.691+0800 I CONTROL [initandlisten] MongoDB starting : pid=13659 port=27017 dbpath=/data/db 64-bit host=yishiyaonie.local
2016-08-03T14:31:15.691+0800 I CONTROL [initandlisten] db version v3.2.8
2016-08-03T14:31:15.691+0800 I CONTROL [initandlisten] git version: ed70e33130c977bda0024c125b56d159573dbaf0
2016-08-03T14:31:15.691+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2h 3 May 2016
2016-08-03T14:31:15.691+0800 I CONTROL [initandlisten] allocator: system
2016-08-03T14:31:15.692+0800 I CONTROL [initandlisten] modules: none
2016-08-03T14:31:15.692+0800 I CONTROL [initandlisten] build environment:
2016-08-03T14:31:15.692+0800 I CONTROL [initandlisten] distarch: x86_64
2016-08-03T14:31:15.692+0800 I CONTROL [initandlisten] target_arch: x86_64
2016-08-03T14:31:15.692+0800 I CONTROL [initandlisten] options: {}
2016-08-03T14:31:15.692+0800 E NETWORK [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2016-08-03T14:31:15.692+0800 E NETWORK [initandlisten] addr already in use
2016-08-03T14:31:15.692+0800 E STORAGE [initandlisten] Failed to set up sockets during startup.
2016-08-03T14:31:15.692+0800 I CONTROL [initandlisten] dbexit: rc: 48
原因是端口被占用了
咋办呢?
➜ xushukui ps -aux | grep mongod
root 17820 2.7 1.3 277020 52520 pts/19 Tl 20:24 0:00 mongod
root 17857 0.0 0.0 15984 984 pts/19 S+ 20:24 0:00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mongod
➜ xushukui kill -9 17820
[1] + 17820 killed mongod
然后重启ok了:
mongod
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] MongoDB starting : pid=17904 port=27017 dbpath=/data/db 64-bit host=xushukui-Lenovo-Erazer-Z41-70
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] db version v3.2.19
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] git version: a9f574de6a566a58b24d126b44a56718d181e989
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] allocator: tcmalloc
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] modules: none
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] build environment:
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] distmod: ubuntu1604
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] distarch: x86_64
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-03-19T20:25:05.986+0800 I CONTROL [initandlisten] options: {}
2018-03-19T20:25:06.017+0800 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-03-19T20:25:06.017+0800 W - [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
2018-03-19T20:25:06.017+0800 W STORAGE [initandlisten] Recovering data from the last clean checkpoint.
2018-03-19T20:25:06.017+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),verbose=(recovery_progress),
2018-03-19T20:25:06.257+0800 I STORAGE [initandlisten] WiredTiger [1521462306:257852][17904:0x7f1bca6a5c80], txn-recover: Main recovery loop: starting at 6/128
2018-03-19T20:25:06.258+0800 I STORAGE [initandlisten] WiredTiger [1521462306:258184][17904:0x7f1bca6a5c80], txn-recover: Recovering log 6 through 7
2018-03-19T20:25:06.273+0800 I STORAGE [initandlisten] WiredTiger [1521462306:273354][17904:0x7f1bca6a5c80], file:index-1-3052586711455020830.wt, txn-recover: Recovering log 7 through 7
2018-03-19T20:25:07.021+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-03-19T20:25:07.022+0800 I CONTROL [initandlisten]
2018-03-19T20:25:07.022+0800 I CONTROL [initandlisten]
2018-03-19T20:25:07.022+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2018-03-19T20:25:07.022+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-03-19T20:25:07.022+0800 I CONTROL [initandlisten]
2018-03-19T20:25:07.022+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2018-03-19T20:25:07.022+0800 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2018-03-19T20:25:07.022+0800 I CONTROL [initandlisten]
2018-03-19T20:25:07.023+0800 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2018-03-19T20:25:07.023+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2018-03-19T20:25:07.023+0800 I NETWORK [initandlisten] waiting for connections on port 27017