Home
Packages
Forums
Wiki
GitLab
Security
AUR
Download
コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
目次
コミュニティに貢献
最近の出来事
おまかせ表示
特別ページ
交流
ヘルプ
貢献
最近の更新
最近の議論
新しいページ
統計
リクエスト
ArchWiki
検索
検索
表示
アカウント作成
ログイン
個人用ツール
アカウント作成
ログイン
MongoDBのソースを表示
ページ
議論
日本語
閲覧
ソースを閲覧
履歴を表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
ソースを閲覧
履歴を表示
全般
リンク元
関連ページの更新状況
ページ情報
表示
サイドバーに移動
非表示
←
MongoDB
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループに属する利用者のみが実行できます:
登録利用者
。
このページのソースの閲覧やコピーができます。
[[Category:データベース管理システム]] [[en:MongoDB]] [[zh-hans:MongoDB]] MongoDB (由来は hu'''mongo'''us から) はオープンソースのドキュメント指向データベースです。[http://www.mongodb.com/ MongoDB Inc. (旧 10gen)] によって開発・サポートされています。MongoDB はデータベースシステムの NoSQL ファミリーの一員です。"古典的"なリレーショナルデータベースでそうあるように、データをテーブルに保存する代わりに、MongoDB は動的なスキーマ (MongoDB では [http://bsonspec.org/ BSON] と呼称されるフォーマット) によって JSON ライクなドキュメントとして構造的データを保存して、特定のタイプのアプリケーションでデータを簡単かつ高速に扱えるようにします。 == インストール == {{AUR|mongodb}} あるいは {{AUR|mongodb-bin}} パッケージをインストールしてください。また、{{AUR|mongodb-tools}} か {{AUR|mongodb-tools-bin}} をインストールすることで {{ic|mongoimport}}, {{ic|mongoexport}}, {{ic|mongodump}}, {{ic|mongorestore}} などのツールを使うことができます。 {{Note|{{AUR|mongodb}} パッケージを [[AUR ヘルパー]] や [[makepkg]] を使いインストールするには 260GB 以上の空き容量が、{{Pkg|devtools}} を使ったインストールには 20GB 程度の空き容量が必要です。}} {{ic|mongodb.service}} デーモンを[[systemd#ユニットを使う|起動・有効化]]します。 mongodb サービスの最初の起動時に、巨大なファイルが作成され、(ジャーナルなどのデータのための) 予約領域が割り当てられます [https://docs.mongodb.com/manual/faq/storage/#preallocated-data-files]。ファイルの作成には時間がかかり、その間、データベースシェルを使うことはできません。 == 使用方法 == [[Start]]/[[Enable]] the {{ic|mongodb.service}} daemon. {{Note|During the first startup of the mongodb service, it will [https://docs.mongodb.com/manual/faq/storage/#preallocated-data-files pre-allocate space], by creating large files (for its journal and other data). This step may take a while, during which the MongoDB shell is unavailable.}} データベースシェルにアクセスするには、ターミナルに以下を入力: $ mongo Or, if authentication is configured: $ mongo -u ''userName'' == Configuration == === File Format === MongoDB 2.6 introduced a YAML-based configuration file format. The 2.4 configuration file format remains for backward compatibility [https://docs.mongodb.com/manual/reference/configuration-options/#file-format]: {{hc|/etc/mongodb.conf|2= systemLog: destination: file path: "/var/log/mongodb/mongod.log" logAppend: true storage: journal: enabled: true processManagement: fork: true net: bindIp: 127.0.0.1 port: 27017 setParameter: enableLocalhostAuthBypass: false .. }} See https://docs.mongodb.com/manual/reference/configuration-options/ for available configuration options. === Requiring Authentication === {{warning|By default, MongoDB does not require any authentication. Although MongoDB only listens on the localhost interface by default, this still allows any local user to connect without authenticating and may exposes the database(s). It is recommended to enable access control to prevent any unwanted access.}} To create a MongoDB user account with administrator access [https://docs.mongodb.com/manual/tutorial/enable-authentication/]: {{hc|$ mongo| use admin db.createUser( { user: "myUserAdmin", pwd: "abc123", roles: [ { role: "userAdminAnyDatabase", db: "admin" }, "readWriteAnyDatabase" ] } )}} If your {{ic|/etc/mongodb.conf}} uses the new YAML format, [[append]]: {{hc|/etc/mongodb.conf| security: authorization: "enabled" }} If it uses the v2.4 format, add: {{hc|/etc/mongodb.conf|2= auth = true }} [[Restart]] {{ic|mongodb.service}}. === NUMA === Running MongoDB with Non-Uniform Access Memory (NUMA) can significantly impact performance. [https://docs.mongodb.com/manual/administration/production-notes/#mongodb-and-numa-hardware] To see if your system uses NUMA: $ dmesg | grep -i numa Also, {{ic|/var/log/mongodb/mongod.log}} will show warnings if NUMA is in use and MongoDB is not started through {{ic|numactl}}. (The {{ic|mongo}} shell will also show this, but only if you do not have authentication enabled.) If your system uses NUMA, to improve performance, you should make MongoDB start through {{ic|numactl}}: # cp /usr/lib/systemd/system/mongodb.service /etc/systemd/system And change how {{ic|/etc/systemd/system/mongodb.service}} starts MongoDB. If using {{aur|mongodb}}, change it from: ExecStart=/usr/bin/mongod $OPTIONS To: ExecStart='''/usr/bin/numactl --interleave=all''' /usr/bin/mongod $OPTIONS If using {{aur|mongodb-bin}}, change it from: ExecStart=/usr/bin/mongod --quiet --config /etc/mongodb.conf To: ExecStart='''/usr/bin/numactl --interleave=all''' /usr/bin/mongod --quiet --config /etc/mongodb.conf Zone claim also needs to be disabled, but on arch, {{ic|/proc/sys/vm/zone_reclaim_mode}} defaults to {{ic|0}}. [[Systemd#Replacement unit files|Reenable]] and [[Restart]] {{ic|mongodb.service}}. (Merely restarting it will not switch to the {{ic|/etc}} version.) === Clean Start and Stop === By default, [[systemd]] immediately kills anything after asking it to start or stop, if it has not finished doing so within 90 seconds. {{aur|mongodb}} makes [[systemd]] wait as long as it takes for MongoDB to start, but {{aur|mongodb-bin}} does not. Both packages allow [[systemd]] to kill MongoDB after it's asked to stop, if it hasn't finished within 90 seconds. Large MongoDB databases can take a considerable amount of time to cleanly shut down, especially if swap is being used. (An active 450GB database on a top of the line NVMe with 64GB RAM and 16GB swap can take an hour to shut down.) By default, MongoDB uses journaling. [https://docs.mongodb.com/manual/reference/configuration-options/#storage-options] With journaling, an unclean shutdown should not pose a risk of data loss. But, if not shutdown cleanly, large MongoDB databases can take a considerable amount of time to start back up. In this case, choosing whether to require a clean shutdown is a choice of a slower shutdown versus a slower startup. [https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/mongodb-user/KjBU_GcNcmw/gR2UxRIFAgAJ] {{warning|If you disable journaling, failing to require a clean shutdown severely risks data loss, so you really need to require a clean shutdown. [https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/]}} To prevent [[systemd]] from killing MongoDB after 90 seconds, make and then [[edit]] your own {{ic|.service}} file, i.e.: # cp /usr/lib/systemd/system/mongodb.service /etc/systemd/system To allow MongoDB to cleanly shutdown, [[append]] to the {{ic|[Service]}} section: (On large databases, this may substantially slow down your system shutdown time, but speeds up your next MongoDB start time) TimeoutStopSec=infinity If MongoDB needs a long time to start back up, it can be very problematic for [[systemd]] to keep killing and restarting it every 90 seconds [https://jira.mongodb.org/browse/SERVER-38086], so {{aur|mongodb}} prevents this. If using {{aur|mongodb-bin}}, to make [[systemd]] wait as long as it takes for MongoDB to start, [[append]] to the {{ic|[Service]}} section: TimeoutStartSec=infinity == トラブルシューティング == === MongoDB が起動しない === データベースのパスが正しく設定されているか確認してください: $ cat /usr/lib/systemd/system/mongodb.service "ExecStart" 行に "--dbpath /var/lib/mongodb" を追加してください: ExecStart=/usr/bin/numactl --interleave=all mongod --quiet --config /etc/mongodb.conf --dbpath /var/lib/mongodb 最低でも (ジャーナルファイル用の) 3GB の空き容量があることを確認してください。容量が足りない場合 MongoDB が起動できないことがあります (その場合ユーザーにメッセージは表示されません): $ df -h /var/lib/mongodb/ ロックファイルが存在しないかどうか確認: # ls -lisa /var/lib/mongodb ロックファイルが存在する場合、{{ic|mongodb.service}} を停止してください。データベースのパスを指定してデータベースの修復を実行します (Arch Linux では {{ic|/var/lib/mongodb/}} がデフォルトの --dbpath です): # mongod --dbpath /var/lib/mongodb/ --repair 修復が完了すると、dbpath に修復されたデータファイルと空の mongod.lock ファイルが作られます。 {{Warning|ファイルを削除して、破損したファイルを使ってデータベースを起動して、データベースからデータの復旧を試みることもできます。ただし、データベースの状態を予想することはできません。詳しくは [https://docs.mongodb.com/manual/tutorial/recover-data-following-unexpected-shutdown/ 上流のドキュメント] を見てください。}} root で修復を実行後、ファイルの所有者は root ユーザーになりますが、Arch Linux は別のユーザーで MongoDB を実行します。chown を使ってファイルの所有者を適切なユーザーに戻す必要があります (詳しくは [http://earlz.net/view/2011/03/11/0015/mongodb-and-arch-linux こちら] を参照): # chown -R mongodb: /var/{log,lib}/mongodb/ mongodb の [https://docs.mongodb.com/manual/reference/configuration-options/ ドキュメント] から設定ファイルをコピーした場合、以下の2行を削除して {{ic|mongodb.service}} を再起動してください: {{hc|/etc/mongodb.conf|<nowiki> processManagement: fork: true </nowiki>}} === transparent_hugepage のカーネル設定について MongoDB がエラーを吐く === MongoDB の起動後、transparent_hugepage に関する警告が表示される場合、以下のファイルを編集することでシステム設定を永続的に無効化することができます ([https://www.freedesktop.org/software/systemd/man/tmpfiles.d.html FreeDesktop tmpfiles.d マニュアル] を参照): {{hc|/etc/tmpfiles.d/local.conf|<nowiki> w /sys/kernel/mm/transparent_hugepage/enabled - - - - never w /sys/kernel/mm/transparent_hugepage/defrag - - - - never </nowiki>}} [[sysctl]] を使ったり以下のように echo コマンドを使うことで一時的に無効化することもできます: # echo never > /sys/kernel/mm/transparent_hugepage/enabled # echo never > /sys/kernel/mm/transparent_hugepage/defrag === Warning about Soft rlimits too low === If you are using systemd service, then edit the unit file by {{ic|systemctl edit mongodb.service}}: [Service] # Other directives omitted # (file size) LimitFSIZE=infinity # (cpu time) LimitCPU=infinity # (virtual memory size) LimitAS=infinity # (locked-in-memory size) LimitMEMLOCK=infinity # (open files) LimitNOFILE=64000 # (processes/threads) LimitNPROC=64000 See following link for further details: [https://docs.mongodb.com/manual/reference/ulimit/#review-and-set-resource-limits Further reference]
このページで使用されているテンプレート:
テンプレート:AUR
(
ソースを閲覧
)
テンプレート:Aur
(
ソースを閲覧
)
テンプレート:Hc
(
ソースを閲覧
)
テンプレート:Ic
(
ソースを閲覧
)
テンプレート:Note
(
ソースを閲覧
)
テンプレート:Warning
(
ソースを閲覧
)
MongoDB
に戻る。
検索
検索
MongoDBのソースを表示
話題を追加