{"id":3376,"date":"2019-04-05T12:24:37","date_gmt":"2019-04-05T04:24:37","guid":{"rendered":"http:\/\/ros.tw\/wp\/?p=3376"},"modified":"2019-04-05T12:37:38","modified_gmt":"2019-04-05T04:37:38","slug":"unifi-controller-mongodb-%e6%90%8d%e6%af%80%e7%84%a1%e6%b3%95%e5%95%9f%e5%8b%95","status":"publish","type":"post","link":"https:\/\/ros.tw\/wp\/?p=3376","title":{"rendered":"UniFi Controller MongoDB \u640d\u6bc0\u7121\u6cd5\u555f\u52d5"},"content":{"rendered":"<h3><strong>\u5982\u679c\u4f60\u7684<\/strong><strong>Cloud Key\u6216\u662f<\/strong><strong>Debian UniFi Controller \u56e0\u70ba\u67d0\u4e9b\u539f\u56e0\u5c0e\u81f4 MongoDB\u00a0\u8cc7\u6599\u5eab\u640d\u6bc0\u800c\u7121\u6cd5\u6b63\u5e38\u555f\u52d5<\/strong><\/h3>\n<h3><strong>\u8a66\u8a66\u5e95\u4e0b<a href=\"https:\/\/help.ubnt.com\/hc\/en-us\/articles\/360006634094#3\">\u5b98\u65b9<\/a>\u7684\u4fee\u5fa9\u547d\u4ee4\u80fd\u8b93\u4f60\u7684UniFi Controller\u518d\u6d3b\u904e\u4f86.<\/strong><\/h3>\n<ol>\n<li><a href=\"https:\/\/help.ubnt.com\/hc\/en-us\/articles\/360006634094#2\">Repairing a Database on Cloud Key<\/a><\/li>\n<li><a href=\"https:\/\/help.ubnt.com\/hc\/en-us\/articles\/360006634094#3\">Repairing a Database on Debian-based Linux<\/a><\/li>\n<li><a href=\"https:\/\/help.ubnt.com\/hc\/en-us\/articles\/360006634094#5\">Repairing a Database on Windows<\/a><\/li>\n<\/ol>\n<p><!--more--><\/p>\n<h1><strong>How to Repair a Database on Cloud Key (\u5b98\u65b9\u786c\u9ad4\u63a7\u5236\u5668)<\/strong><\/h1>\n<p>1. Download the mongo pruning script. As written, the script will only keep entries from the past 7 days. It will not remove entries that are required for UniFi administration. Do so by running the following command:<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">cd \/tmp\/\r\nwget <a href=\"https:\/\/help.ubnt.com\/hc\/en-us\/article_attachments\/360008640574\/CK_repair.js\">https:\/\/help.ubnt.com\/hc\/en-us\/article_attachments\/360008640574\/CK_repair.js<\/a><\/pre>\n<\/div>\n<p>2. Stop the UniFi service<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">service unifi stop<\/pre>\n<\/div>\n<p>3. The UniFi service will shut down the mongo process. Make sure that the UniFi service has been completely shut down. Repair the database to compact the data entries and free unused disk space\u00a0field that is included in the query criteria.<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">mongod --dbpath \/usr\/lib\/unifi\/data\/db --smallfiles --logpath \/usr\/lib\/unifi\/logs\/server.log --repair<\/pre>\n<\/div>\n<div class=\"table-wrapper-outer\">\n<div class=\"table-wrapper\">\n<table class=\"article-notice-box box--blue\">\n<tbody>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/help-center-assets.ubnt.com\/info.svg\" \/><\/td>\n<td>\n<div class=\"node--head\"><span class=\"node--head-title\"><strong>NOTE:\u00a0<\/strong><\/span>Steps 4-7 are optional if you need to prune back the database to conserve disk space.<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>4. Restart mongo with this command:<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">mongod --dbpath \/usr\/lib\/unifi\/data\/db --smallfiles --logpath \/usr\/lib\/unifi\/logs\/server.log --journal --fork<\/pre>\n<\/div>\n<div class=\"table-wrapper-outer\">\n<div class=\"table-wrapper\">\n<table class=\"article-notice-box box--blue\">\n<tbody>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/help-center-assets.ubnt.com\/info.svg\" \/><\/td>\n<td>\n<div class=\"node--head\"><span class=\"node--head-title\"><strong>NOTE:\u00a0<\/strong>Journaling may not be have been enabled in your mongo database. If so, then remove the &#8211;journal option in the above command.<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>5. Execute the script to prune the\u00a0<code>stat<\/code>\u00a0collections that are causing the problem:<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">mongo &lt; \/tmp\/CK_repair.js<\/pre>\n<\/div>\n<p>6. Shut down the mongo server with this command:<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">mongod --dbpath \/usr\/lib\/unifi\/data\/db --smallfiles --logpath \/usr\/lib\/unifi\/logs\/server.log --shutdown<\/pre>\n<\/div>\n<div class=\"table-wrapper-outer\">\n<div class=\"table-wrapper\">\n<table class=\"article-notice-box box--blue\">\n<tbody>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/help-center-assets.ubnt.com\/info.svg\" \/><\/td>\n<td>\n<div class=\"node--head\"><span class=\"node--head-title\"><strong>NOTE:\u00a0<\/strong>The last command in the CK_repair.js script is &#8220;db.repairDatabase()&#8221;. It may result in an error if the stats collections have already grown too large to be repaired while the mongo server is running. If you see such an error running the script then you will need to repair the database from the command line once again by running the command in step 3.<\/span><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>7. Finally, restart the UniFi service:<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">service unifi start<\/pre>\n<\/div>\n<hr \/>\n<p><!--more--><\/p>\n<h1><strong>How to Repair a Database on Debian-based Linux\u00a0<\/strong><strong>(<\/strong><strong>D<\/strong><strong>ebian \u63a7\u5236\u5668)<\/strong><\/h1>\n<hr \/>\n<p>1. Stop the UniFi service<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">service unifi stop<\/pre>\n<\/div>\n<p>2. Repair the database with this command:<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">mongod --dbpath \/usr\/lib\/unifi\/data\/db --smallfiles --logpath \/usr\/lib\/unifi\/logs\/server.log --repair<\/pre>\n<\/div>\n<p>3. Finally, restart the UniFi service:<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\">service unifi start<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3379\" src=\"http:\/\/ros.tw\/wp\/wp-content\/uploads\/2019\/04\/20190323_215706-276x300.jpg\" alt=\"\" width=\"276\" height=\"300\" srcset=\"https:\/\/ros.tw\/wp\/wp-content\/uploads\/2019\/04\/20190323_215706-276x300.jpg 276w, https:\/\/ros.tw\/wp\/wp-content\/uploads\/2019\/04\/20190323_215706.jpg 750w\" sizes=\"auto, (max-width: 276px) 100vw, 276px\" \/><\/p>\n<p>&nbsp;<\/p>\n<div class=\"pre-wrapper\">\n<pre class=\"copyable\"><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u7684Cloud Key\u6216\u662fDebian UniFi Controller \u56e0 &hellip; <a href=\"https:\/\/ros.tw\/wp\/?p=3376\">\u95b1\u8b80\u5168\u6587 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"gallery","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3376","post","type-post","status-publish","format-gallery","hentry","category-ros","post_format-post-format-gallery"],"_links":{"self":[{"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3376"}],"version-history":[{"count":5,"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3376\/revisions"}],"predecessor-version":[{"id":3382,"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=\/wp\/v2\/posts\/3376\/revisions\/3382"}],"wp:attachment":[{"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ros.tw\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}