在 ubuntu 16.04 上为 mongodb 3.2 调试 systemd — sig 15 killing

在 ubuntu 16.04 上为 mongodb 3.2 调试 systemd — sig 15 killing

我已按照 mongodb.org 上的说明安装了 mongodb-org 和 mongodb-org-server(尽管适用于 ubuntu 14.x)

此时直接运行mongodb就可以了;

sudo -H -u mongodb bash -c "/usr/bin/mongod -f /etc/mongod.conf"

在 /var/log/mongodb.log 中

2016-06-15T00:57:10.718Z I NETWORK  [initandlisten] waiting for connections on port 27017

我已经构建了一个 /lib/systemd/system/mongodb.service (类似于https://gist.github.com/sgnn7/54146c8a13c8b5ca2201

[Unit]
Description=High-performance, schema-free document-oriented database
After=syslog.target network.target

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod -f /etc/mongod.conf
ExecStop=/usr/bin/mongod -f /etc/mongod.conf --shutdown

[Install]
WantedBy=multi-user.target

在 mongodb.log 中这是结果;

2016-06-15T00:47:53.748Z I CONTROL  [initandlisten] MongoDB starting : pid=5592 port=27017 dbpath=/data/wiredtiger 64-bit host=neptune
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten] db version v3.2.7
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten] git version: 4249c1d2b5999ebbf1fdf3bc0e0e3b3ff5c0aaf2
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g-fips  1 Mar 2016
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten] allocator: tcmalloc
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten] modules: none
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten] build environment:
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten]     distmod: ubuntu1404
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten]     distarch: x86_64
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten]     target_arch: x86_64
2016-06-15T00:47:53.748Z I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017, unixDomainSocket: { enabled: true, filePermissions: 329, pathPrefix: "/data/wiredtiger" } }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongodb.pid" }, setParameter: { failIndexKeyTooLong: "false" }, storage: { dbPath: "/data/wiredtiger", directoryPerDB: true, engine: "wiredTiger", journal: { enabled: true }, wiredTiger: { collectionConfig: { blockCompressor: "snappy" }, engineConfig: { cacheSizeGB: 1, directoryForIndexes: true } } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongodb.log", timeStampFormat: "iso8601-utc" } }
2016-06-15T00:47:53.770Z I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(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),
2016-06-15T00:47:54.257Z I CONTROL  [initandlisten] 
2016-06-15T00:47:54.257Z I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-06-15T00:47:54.257Z I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-06-15T00:47:54.257Z I CONTROL  [initandlisten] 
2016-06-15T00:47:54.257Z I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-06-15T00:47:54.257Z I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-06-15T00:47:54.257Z I CONTROL  [initandlisten] 
2016-06-15T00:47:54.270Z I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/wiredtiger/diagnostic.data'
2016-06-15T00:47:54.271Z I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-06-15T00:47:54.271Z I NETWORK  [initandlisten] waiting for connections on port 27017
2016-06-15T00:47:54.305Z I CONTROL  [main] ***** SERVER RESTARTED *****
2016-06-15T00:47:54.310Z I CONTROL  [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
2016-06-15T00:47:54.310Z I FTDC     [signalProcessingThread] Shutting down full-time diagnostic data capture
2016-06-15T00:47:54.310Z I CONTROL  [signalProcessingThread] now exiting
2016-06-15T00:47:54.310Z I NETWORK  [signalProcessingThread] shutdown: going to close listening sockets...
2016-06-15T00:47:54.310Z I NETWORK  [signalProcessingThread] closing listening socket: 6
2016-06-15T00:47:54.310Z I NETWORK  [signalProcessingThread] closing listening socket: 7
2016-06-15T00:47:54.310Z I NETWORK  [signalProcessingThread] removing socket file: /data/wiredtiger/mongodb-27017.sock
2016-06-15T00:47:54.310Z I NETWORK  [signalProcessingThread] shutdown: going to flush diaglog...
2016-06-15T00:47:54.310Z I NETWORK  [signalProcessingThread] shutdown: going to close sockets...
2016-06-15T00:47:54.310Z I STORAGE  [signalProcessingThread] WiredTigerKVEngine shutting down
 2016-06-15T00:47:54.436Z I STORAGE  [signalProcessingThread] shutdown: removing fs lock...
 2016-06-15T00:47:54.436Z I CONTROL  [signalProcessingThread] dbexit:  rc: 0

作为设置 systemd 服务的一部分,我运行了

systemctl --system daemon-reload
systemctl unmask mongodb.service
systemctl enable mongodb.service
systemctl start mongodb.service

mongodb 的所有数据、日志和运行目录均归 mongodb.mongodb 所有 - 并且我创建了 /var/run 的 mongodb 子目录(归 mongodb 所有)

启动后立即杀死 systemd 版本是什么?

我还可以尝试其他什么吗?(​​我在[服务]中尝试过“LimitNOFILE=64000”)

谢谢!

答案1

进程管理:{ fork:true, pidFilePath:"/var/run/mongodb/mongodb.pid" }

这是你的问题。 processManagement.fork应该false(这也是默认的)在你的mongod.conf文件中。

因为这是真的,所以 mongod 完全没有必要进行分叉。由于它是分叉的,systemd 认为主守护进程已意外退出,并且正在清理服务使其恢复到停止状态。它通过明确终止服务留下的所有子进程来实现这一点。因此发出了信号。

这是就绪协议不匹配。MongoDB 不支持分叉就绪协议,将 systemd 服务单元改为支持该协议是错误的。正确的做法是更改 MongoDB 的配置,使其不会完全不必要地分叉。

进一步阅读

答案2

通常,离开 20 分钟后,我会回来继续工作几个小时并找到解决方案。

Type=forking

/lib/systemd/system/mongodb.service 文件中需要。现在看起来像;

[Unit]
Description=High-performance, schema-free document-oriented database
After=syslog.target network.target

[Service]
Type=forking
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod -f /etc/mongod.conf
ExecStop=/usr/bin/mongod -f /etc/mongod.conf --shutdown

[Install]
WantedBy=multi-user.target

希望这能帮助别人!

相关内容