0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MongoDB 起動時に Got signal: 7 (Bus error) でクラッシュが発生するようになったのを復旧した

Posted at

はじめに

誤って GROWI を動かしていたラズパイの電源を引っこ抜いてしまい、MongoDB が正常起動しなくなってしまったのを復旧した時の作業ログです。

先に結論を書いてしまうと MongoDB を再インストールしただけなのですが、ところどころ躓いたので、そのあたりの備忘録として作成しました。

環境

  • Raspberry Pi 4 Model B 4GB (32GB MicroSD)
  • Ubuntu Server 19.10.1 (64bit)
  • MongoDB 3.6.8

基本的に super ユーザで作業。

起きた事象

表題の通り、起動時に Got signal:7 (Bus error) が発生し、クラッシュするようになってしまった (電断起因と思われる) 。
実際のログは以下のような内容。

起動ログ (Bus error)
/var/log/mongod.log
 I CONTROL  [main] ***** SERVER RESTARTED *****
 I CONTROL  [initandlisten] MongoDB starting : pid=11552 port=27017 dbpath=/var/lib/mongodb 64-bit host=ubuntu
 I CONTROL  [initandlisten] db version v3.6.8
 I CONTROL  [initandlisten] git version: 8e540c0b6db93ce994cc548f000900bdc740f80a
 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1c  28 May 2019
 I CONTROL  [initandlisten] allocator: tcmalloc
 I CONTROL  [initandlisten] modules: none
 I CONTROL  [initandlisten] build environment:
 I CONTROL  [initandlisten]     distarch: aarch64
 I CONTROL  [initandlisten]     target_arch: aarch64
 I CONTROL  [initandlisten] options: { config: "/etc/mongodb.conf", net: { bindIp: "127.0.0.1", unixDomainSocket: { pathPrefix: "/run/mongodb" } }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongodb.log" } }
 W -        [initandlisten] Detected unclean shutdown - /var/lib/mongodb/mongod.lock is not empty.
 I -        [initandlisten] Detected data files in /var/lib/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
 I STORAGE  [initandlisten] 
 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1383M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),cache_cursors=false,compatibility=(release="3.0",require_max="3.0"),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
 I STORAGE  [initandlisten] WiredTiger message [1662171225:956355][11552:0xffffb5746010], txn-recover: Main recovery loop: starting at 9/20165504
 F -        [initandlisten] Invalid access at address: 0xaaaad803aca0
 F -        [initandlisten] Got signal: 7 (Bus error).

 0xaaaad93ed824 0xaaaad93ecc98 0xaaaad93ecedc 0xffffb621d5b0 0xaaaad803aca0 0xaaaad803b158 0xaaaad803b5e8 0xaaaad7feaf70 0xaaaad8045428 0xaaaad7fdddf0 0xaaaad7fdb0fc 0xaaaad7fb0b68 0xaaaad7f997f4 0xaaaad816a044 0xaaaad7f75344 0xaaaad7f791d8 0xaaaad7f02114 0xffffb57e43ec 0xaaaad7f66d78
----- BEGIN BACKTRACE -----
{"backtrace":[{"b":"AAAAD76C3000","o":"1D2A824","s":"_ZN5mongo15printStackTraceERSo"},{"b":"AAAAD76C3000","o":"1D29C98"},{"b":"AAAAD76C3000","o":"1D29EDC"},{"b":"FFFFB621D000","o":"5B0","s":"__kernel_rt_sigreturn"},{"b":"AAAAD76C3000","o":"977CA0"},{"b":"AAAAD76C3000","o":"978158"},{"b":"AAAAD76C3000","o":"9785E8","s":"__wt_thread_group_create"},{"b":"AAAAD76C3000","o":"927F70","s":"__wt_evict_create"},{"b":"AAAAD76C3000","o":"982428","s":"__wt_txn_recover"},{"b":"AAAAD76C3000","o":"91ADF0","s":"__wt_connection_workers"},{"b":"AAAAD76C3000","o":"9180FC","s":"wiredtiger_open"},{"b":"AAAAD76C3000","o":"8EDB68","s":"_ZN5mongo18WiredTigerKVEngineC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_PNS_11ClockSourceES8_mbbbb"},{"b":"AAAAD76C3000","o":"8D67F4"},{"b":"AAAAD76C3000","o":"AA7044","s":"_ZN5mongo20ServiceContextMongoD29initializeGlobalStorageEngineEv"},{"b":"AAAAD76C3000","o":"8B2344"},{"b":"AAAAD76C3000","o":"8B61D8","s":"_ZN5mongo11mongoDbMainEiPPcS1_"},{"b":"AAAAD76C3000","o":"83F114","s":"main"},{"b":"FFFFB57C0000","o":"243EC","s":"__libc_start_main"},{"b":"AAAAD76C3000","o":"8A3D78"}],"processInfo":{ "mongodbVersion" : "3.6.8", "gitVersion" : "8e540c0b6db93ce994cc548f000900bdc740f80a", "compiledModules" : [], "uname" : { "sysname" : "Linux", "release" : "5.3.0-1030-raspi2", "version" : "#32-Ubuntu SMP Sun Jul 12 21:20:28 UTC 2020", "machine" : "aarch64" }, "somap" : [ { "b" : "AAAAD76C3000", "elfType" : 3, "buildId" : "760C6C83C730D442B368AAD1098F42FD57BF3B16" }, { "b" : "FFFFB621D000", "path" : "linux-vdso.so.1", "elfType" : 3, "buildId" : "4330D28706CF921272BBDDE9A124C975BB88F24C" }, { "b" : "FFFFB6188000", "path" : "/lib/aarch64-linux-gnu/libstemmer.so.0d", "elfType" : 3, "buildId" : "D1E2D7209AC9E057A61EA670471C436BB1F12251" }, { "b" : "FFFFB615E000", "path" : "/lib/aarch64-linux-gnu/libz.so.1", "elfType" : 3, "buildId" : "740421F24A81932D219E61C4A2D770E400702FB8" }, { "b" : "FFFFB6146000", "path" : "/lib/aarch64-linux-gnu/libsnappy.so.1", "elfType" : 3, "buildId" : "292C757BC635939CFBA06838976FA79E07DB298C" }, { "b" : "FFFFB60D8000", "path" : "/lib/aarch64-linux-gnu/libyaml-cpp.so.0.6", "elfType" : 3, "buildId" : "735AA352D6AC326D975692953BC4198AD1BE1B7A" }, { "b" : "FFFFB60BF000", "path" : "/lib/aarch64-linux-gnu/libpcrecpp.so.0", "elfType" : 3, "buildId" : "D86B0D60D0D72B626DE2E53AD185DBC16C945502" }, { "b" : "FFFFB6031000", "path" : "/lib/aarch64-linux-gnu/libboost_program_options.so.1.67.0", "elfType" : 3, "buildId" : "56D94CF9610C1F60B7595AFAA6E5A37EAFB361A4" }, { "b" : "FFFFB6007000", "path" : "/lib/aarch64-linux-gnu/libboost_filesystem.so.1.67.0", "elfType" : 3, "buildId" : "981C0BFEE678C6F6F9B41EBBF193ED39217EEC77" }, { "b" : "FFFFB5FF2000", "path" : "/lib/aarch64-linux-gnu/libboost_system.so.1.67.0", "elfType" : 3, "buildId" : "F06507B139257DB3AE8A68B7FB28C5A82B0B20B1" }, { "b" : "FFFFB5F72000", "path" : "/lib/aarch64-linux-gnu/libtcmalloc.so.4", "elfType" : 3, "buildId" : "C46CBDDB77E0062FD58FF187125C17DB48007516" }, { "b" : "FFFFB5F4C000", "path" : "/lib/aarch64-linux-gnu/libresolv.so.2", "elfType" : 3, "buildId" : "6AA72F75A45B6BCB923CA7D957260D14B1AD9BE9" }, { "b" : "FFFFB5CC4000", "path" : "/lib/aarch64-linux-gnu/libcrypto.so.1.1", "elfType" : 3, "buildId" : "F093F1362B98E3683E8C4AECBF78247334FCCD1A" }, { "b" : "FFFFB5C2B000", "path" : "/lib/aarch64-linux-gnu/libssl.so.1.1", "elfType" : 3, "buildId" : "DE174B0BED40475F978608018D2E17D4EEDC84D7" }, { "b" : "FFFFB5C15000", "path" : "/lib/aarch64-linux-gnu/libdl.so.2", "elfType" : 3, "buildId" : "8F8EC5284E988C1C288CAB72A144DA04D59CA525" }, { "b" : "FFFFB5A2F000", "path" : "/lib/aarch64-linux-gnu/libstdc++.so.6", "elfType" : 3, "buildId" : "903F1AC291E6FB80A389155F441DFEB67D6A3CD4" }, { "b" : "FFFFB5986000", "path" : "/lib/aarch64-linux-gnu/libm.so.6", "elfType" : 3, "buildId" : "C50C9378B838D3038D91A47AB66C41727DE2B5A9" }, { "b" : "FFFFB5962000", "path" : "/lib/aarch64-linux-gnu/libgcc_s.so.1", "elfType" : 3, "buildId" : "D10910008831D7D7A654879D9683B743B5F1F1AA" }, { "b" : "FFFFB5932000", "path" : "/lib/aarch64-linux-gnu/libpthread.so.0", "elfType" : 3, "buildId" : "9F9B20F3B49FD1B737A993EFB204F9E508E44BCA" }, { "b" : "FFFFB57C0000", "path" : "/lib/aarch64-linux-gnu/libc.so.6", "elfType" : 3, "buildId" : "A47375030F947ADAF1C2F9FE0FDFE315F27A57B3" }, { "b" : "FFFFB61EE000", "path" : "/lib/ld-linux-aarch64.so.1", "elfType" : 3, "buildId" : "0E29FEAC0C1C24570FB9D5165A6C277AB8320942" }, { "b" : "FFFFB574B000", "path" : "/lib/aarch64-linux-gnu/libpcre.so.3", "elfType" : 3, "buildId" : "9E72776B3C212045536672C26406D943234E1FAF" } ] }}
 mongod(_ZN5mongo15printStackTraceERSo+0x44) [0xaaaad93ed824]
 mongod(+0x1D29C98) [0xaaaad93ecc98]
 mongod(+0x1D29EDC) [0xaaaad93ecedc]
 linux-vdso.so.1(__kernel_rt_sigreturn+0x0) [0xffffb621d5b0]
 mongod(+0x977CA0) [0xaaaad803aca0]
 mongod(+0x978158) [0xaaaad803b158]
 mongod(__wt_thread_group_create+0xE8) [0xaaaad803b5e8]
 mongod(__wt_evict_create+0x68) [0xaaaad7feaf70]
 mongod(__wt_txn_recover+0x718) [0xaaaad8045428]
 mongod(__wt_connection_workers+0x40) [0xaaaad7fdddf0]
 mongod(wiredtiger_open+0x1B54) [0xaaaad7fdb0fc]
 mongod(_ZN5mongo18WiredTigerKVEngineC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_PNS_11ClockSourceES8_mbbbb+0x640) [0xaaaad7fb0b68]
 mongod(+0x8D67F4) [0xaaaad7f997f4]
 mongod(_ZN5mongo20ServiceContextMongoD29initializeGlobalStorageEngineEv+0x544) [0xaaaad816a044]
 mongod(+0x8B2344) [0xaaaad7f75344]
 mongod(_ZN5mongo11mongoDbMainEiPPcS1_+0x550) [0xaaaad7f791d8]
 mongod(main+0xC) [0xaaaad7f02114]
 libc.so.6(__libc_start_main+0xE4) [0xffffb57e43ec]
 mongod(+0x8A3D78) [0xaaaad7f66d78]
-----  END BACKTRACE  -----

アクセス違反のようだが、スタックトレースを見てもなにがなんだか分からない。
私の脳みそでは「WiredTrigger なるものの open 処理がうまくいっていないんだなあ」程度のことしか読み取れなかったので、これを真面目に解読するのは諦めた。

やってみたこと

repair オプション付き起動【効果なし】

Detected unclean shutdown - /var/lib/mongodb/mongod.lock is not empty. なるログも出ていたので、まずはデータベースの破損を疑って、 repair オプションによる修復を試みてみたが、特に効果はなし。

$ mongod --dbpath /var/lib/mongod/ --repair

mongod.lock を手動除去して起動【効果なし】

以下のような記事を見かけたので、 /var/lib/mongod/mongod.lock を削除 (リネーム) してから、 repair オプションによる修復も試してみたが、こちらも効果なし。

新規に作成したデータベースフォルダを指定して起動【効果なし】

適当なフォルダ (/home/hogehoge/mongod/) を作成して、そちらを dbpath に指定して起動してみたが、クラッシュの仕方は変化なし。

$ mkdir /home/hogehoge/mongod/
$ mongod --dbpath /home/hogehoge/mongod/

仮にデータベース新規作成時に必要な何かしら手続きが抜けていたとしても、落ち方が変わらないのは違和感がある。
これ、データベース側の問題ではなく、システム側が破損しているのでは?

MongoDB を再インストール【解決】

システムが破損してるなら、再インストールするのが手っ取り早かろう。

$ systemctl disable mongodb # サービス無効化
$ tar zcvf /home/hogehoge/mongod-backup.tar.gz /var/lib/mongod/* # DB バックアップ
$ apt purge mongodb* # MongoDB アンインストール (設定ファイルも削除)
$ apt install mongodb-server # MongoDB インストール

可能であればそのまま使いたかったので、 /var/lib/mongod/ 自体の削除はしなかった。

再インストール (ちょっとハマったので後述) 後、サービスを立ち上げてみると…、

$ systemctl start mongodb
$ systemctl status mongodb
● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code)
     Docs: man:mongod(1)
 Main PID: 15146 (code=exited, status=100)

スルッと失敗した。

ログを見てみる。

起動ログ (read-only)
/var/log/mongod.log
 I CONTROL  [main] ***** SERVER RESTARTED *****
 I CONTROL  [initandlisten] MongoDB starting : pid=14837 port=27017 dbpath=/var/lib/mongodb 64-bit host=ubuntu
 I CONTROL  [initandlisten] db version v3.6.8
 I CONTROL  [initandlisten] git version: 8e540c0b6db93ce994cc548f000900bdc740f80a
 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1c  28 May 2019
 I CONTROL  [initandlisten] allocator: tcmalloc
 I CONTROL  [initandlisten] modules: none
 I CONTROL  [initandlisten] build environment:
 I CONTROL  [initandlisten]     distarch: aarch64
 I CONTROL  [initandlisten]     target_arch: aarch64
 I CONTROL  [initandlisten] options: { config: "/etc/mongodb.conf", net: { bindIp: "127.0.0.1", unixDomainSocket: { pathPrefix: "/run/mongodb" } }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongodb.log" } }
 I STORAGE  [initandlisten] exception in initAndListen: IllegalOperation: Attempted to create a lock file on a read-only directory: /var/lib/mongodb, terminating
 I CONTROL  [initandlisten] now exiting
 I CONTROL  [initandlisten] shutting down with code:100

どうやら /var/lib/mongodb/ が read-only になっているらしい。
ls -la /var/lib/mongodb/ で見てみると一部ファイルの所有権が root になっていたので、 chown で所有権を mongodb に変えて再実行してみた。

$ chown -hR mongodb:mongodb /var/lib/mongodb/
$ systemctl start mongodb
$ systemctl status mongodb
● mongodb.service - An object/document-oriented database
   Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
   Active: active (running)
     Docs: man:mongod(1)
 Main PID: 15331 (mongod)
    Tasks: 23 (limit: 4435)
   CGroup: /system.slice/mongodb.service
           └─15331 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf

動いた!やったー。

(余談) Ubuntu 19.10 のサポート切れでハマった

MongoDB 再インストール時に 404 Not Found が出てちょっとハマった。
Ubuntu 19.10 は LTS でないので、とっくの昔 (2020/07) にサポート切れになっていたというオチ。

本来は OS のアップグレードをすべきだろうが、問題の切り分けがしづらくなるのが嫌だったので、こちらの記事を参考に /etc/apt/sources.list のリポジトリ URL を書き換える形で暫定対応。

$ sed -i -e 's/ports.ubuntu.com\/ubuntu-ports/old-releases.ubuntu.com\/ubuntu/g' /etc/apt/sources.list
$ apt-get update
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?