mongodb 初学 意外 连接服务器异常(Connection refused)
啦啦啦
这种情况
root@localhost:/# mongo MongoDB shell version: 3.2.13 connecting to: test 2017-05-31T07:40:34.548-0700 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused 2017-05-31T07:40:34.549-0700 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
由于直接kill掉的进程,不知道为什么服务再启动时options:{}为空。虽启动时指定-dbpath 参数
mongod -dbpath "/var/lib/mongodb/"
但是这样必须保证服务窗口不能关闭。
使用配置文件方式启动
mongod -f /etc/mongod.conf
这样也必须保证服务窗口不能关闭。
采用守护进程方式启动:Daemon
–fork参数可以将mongodb的服务放在后台运行
root@localhost:/# mongod -fork -f /etc/mongod.conf about to fork child process, waiting until server is ready for connections. forked process: 1163 child process started successfully, parent exiting
mongod.log
2017-05-31T07:42:28.242-0700 I CONTROL [main] ***** SERVER RESTARTED ***** 2017-05-31T07:42:28.249-0700 I CONTROL [initandlisten] MongoDB starting : pid=1163 port=27017 dbpath=/var/lib/mongodb 64-bit host=localhost 2017-05-31T07:42:28.250-0700 I CONTROL [initandlisten] db version v3.2.13 2017-05-31T07:42:28.250-0700 I CONTROL [initandlisten] git version: 23899209cad60aaafe114f6aea6cb83025ff51bc 2017-05-31T07:42:28.251-0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016 2017-05-31T07:42:28.251-0700 I CONTROL [initandlisten] allocator: tcmalloc 2017-05-31T07:42:28.251-0700 I CONTROL [initandlisten] modules: none 2017-05-31T07:42:28.251-0700 I CONTROL [initandlisten] build environment: 2017-05-31T07:42:28.252-0700 I CONTROL [initandlisten] distmod: ubuntu1604 2017-05-31T07:42:28.252-0700 I CONTROL [initandlisten] distarch: x86_64 2017-05-31T07:42:28.252-0700 I CONTROL [initandlisten] target_arch: x86_64 2017-05-31T07:42:28.252-0700 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27017 }, processManagement: { fork: true }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } } 2017-05-31T07:42:28.276-0700 I - [initandlisten] Detected data files in /var/lib/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2017-05-31T07:42:28.276-0700 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), 2017-05-31T07:42:28.461-0700 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2017-05-31T07:42:28.462-0700 I CONTROL [initandlisten] 2017-05-31T07:42:28.462-0700 I CONTROL [initandlisten] 2017-05-31T07:42:28.462-0700 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. 2017-05-31T07:42:28.462-0700 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-05-31T07:42:28.462-0700 I CONTROL [initandlisten] 2017-05-31T07:42:28.463-0700 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'. 2017-05-31T07:42:28.463-0700 I CONTROL [initandlisten] ** We suggest setting it to 'never' 2017-05-31T07:42:28.463-0700 I CONTROL [initandlisten] 2017-05-31T07:42:28.466-0700 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data' 2017-05-31T07:42:28.466-0700 I NETWORK [initandlisten] waiting for connections on port 27017 2017-05-31T07:42:28.467-0700 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker 2017-05-31T07:43:01.201-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:56034 #1 (1 connection now open)
啦啦啦
啦啦啦