Mongodb
無法使用 sytemd 將 mongodb 作為服務啟動
我有以下 mongod.service 文件:
[Unit] Description=High-performance, schema-free document-oriented database After=network.target Documentation=https://docs.mongodb.org/manual [Service] User=mongodb Group=mongodb ExecStart=/usr/bin/mongod --quiet --fork --config /etc/mongod.conf # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # total threads (user+kernel) TasksMax=infinity TasksAccounting=false # Recommended limits for for mongod as specified in # http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings [Install] WantedBy=multi-user.target
當我嘗試使用 systemd 啟動服務時,它崩潰了,這是我在日誌文件中可以看到的:
2018-01-18T14:20:07.380+0100 I CONTROL [main] ***** SERVER RESTARTED ***** 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] MongoDB starting : pid=6223 port=27017 dbpath=/var/lib/mongodb 64-bit host=atsjenkins 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] db version v3.6.2 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] allocator: tcmalloc 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] modules: none 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] build environment: 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] distmod: ubuntu1604 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] distarch: x86_64 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] target_arch: x86_64 2018-01-18T14:20:07.403+0100 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, processManagement: { fork: true, timeZoneInfo: "/usr/share/zoneinfo" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } } 2018-01-18T14:20:07.404+0100 I - [initandlisten] Detected data files in /var/lib/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2018-01-18T14:20:07.404+0100 I STORAGE [initandlisten] 2018-01-18T14:20:07.404+0100 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2018-01-18T14:20:07.404+0100 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem 2018-01-18T14:20:07.404+0100 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1463M,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),statistics_log=(wait=0),verbose=(recovery_progress), 2018-01-18T14:20:07.617+0100 I STORAGE [initandlisten] WiredTiger message [1516281607:617760][6223:0x7f5505f409c0], txn-recover: Main recovery loop: starting at 18/6144 2018-01-18T14:20:07.732+0100 I STORAGE [initandlisten] WiredTiger message [1516281607:732326][6223:0x7f5505f409c0], txn-recover: Recovering log 18 through 19 2018-01-18T14:20:07.798+0100 I STORAGE [initandlisten] WiredTiger message [1516281607:798817][6223:0x7f5505f409c0], txn-recover: Recovering log 19 through 19 2018-01-18T14:20:07.863+0100 I CONTROL [initandlisten] 2018-01-18T14:20:07.863+0100 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2018-01-18T14:20:07.863+0100 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2018-01-18T14:20:07.863+0100 I CONTROL [initandlisten] 2018-01-18T14:20:07.876+0100 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data' 2018-01-18T14:20:07.877+0100 I NETWORK [initandlisten] waiting for connections on port 27017 2018-01-18T14:21:02.288+0100 I CONTROL [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends 2018-01-18T14:21:02.288+0100 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets... 2018-01-18T14:21:02.288+0100 I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock 2018-01-18T14:21:02.289+0100 I FTDC [signalProcessingThread] Shutting down full-time diagnostic data capture 2018-01-18T14:21:02.291+0100 I STORAGE [signalProcessingThread] WiredTigerKVEngine shutting down 2018-01-18T14:21:02.357+0100 I STORAGE [signalProcessingThread] shutdown: removing fs lock... 2018-01-18T14:21:02.357+0100 I CONTROL [signalProcessingThread] now exiting 2018-01-18T14:21:02.358+0100 I CONTROL [signalProcessingThread] shutting down with code:0
但使用以下命令通過終端啟動它:
sudo -u mongodb mongod --quiet --fork --config /etc/mongod.conf --port 27017
工作。我無法弄清楚為什麼會發生這種情況,因此任何提示/指針都將不勝感激。以下是已安裝 mongod 的版本開關的輸出:$:~ mongod --version db version v3.6.2 git version: 489d177dbd0f0420a8ca04d39fd78d0a2c539420 OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016 allocator: tcmalloc modules: none build environment: distmod: ubuntu1604 distarch: x86_64 target_arch: x86_64
我在 Ubuntu 16.04.3 LTS
您需要
Type=forking
在[Service]
標題下添加。殺死mongod的是服務看門狗。檢查這個。
將 rhel 7.7 更新到 7.8 後,我遇到了同樣的問題。在更新之前,我在 mongod.conf 中自定義了 mongo PID 文件的位置,但沒有在指向預設位置的 mongod.service 文件中更改它。似乎 systemd 不喜歡那樣。感謝@JJussi 的提示。