{"id":761,"date":"2013-05-02T00:21:29","date_gmt":"2013-05-01T15:21:29","guid":{"rendered":"http:\/\/www.nightmare-yk.com\/?p=761"},"modified":"2016-02-24T08:17:52","modified_gmt":"2016-02-23T23:17:52","slug":"mongodb3%e5%8f%b0%e3%81%ae%e3%83%ac%e3%83%97%e3%83%aa%e3%82%b1%e3%83%bc%e3%82%b7%e3%83%a7%e3%83%b3","status":"publish","type":"post","link":"http:\/\/www.nightmare-yk.com\/?p=761","title":{"rendered":"MongoDB(3\u53f0\u306e\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3)"},"content":{"rendered":"<p>OSS\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u6709\u540d\u306a\u3082\u306e\u3068\u3057\u3066\u306f\u3001MySQL\u3084PostgreSQL\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u3001MongoDB\u3068\u3044\u3046\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u6271\u3063\u3066\u307f\u307e\u3059\u3002\u8a2d\u5b9a\u306f\u6bd4\u8f03\u7684\u7c21\u5358\u3067\u3057\u305f\u304c\u3001\u307e\u3060\u6697\u8a18\u3092\u3057\u305f\u308f\u3051\u3067\u306f\u306a\u3044\u306e\u3067\u3001\u30e1\u30e2\u30e1\u30e2\u3006(.. )<\/p>\n<p>MySQL\u306e\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u610f\u5916\u3068\u5927\u5909\u306a\u3093\u3067\u3059\u3088\u306d\u3002\u6163\u308c\u305f\u4eba\u306b\u306f\u7c21\u5358\u306a\u306e\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3002\u3002\u3002<br \/>\nMongoDB\u306f\u304b\u306a\u308a\u7c21\u5358\u306b\u3067\u304d\u307e\u3057\u305f\u3002\u81ea\u52d5\u30d5\u30a7\u30fc\u30eb\u30aa\u30fc\u30d0\u30fc\u3082\u3057\u307e\u3059\u3057\u3001\u3084\u3063\u3066\u3044\u3066\u9762\u767d\u304b\u3063\u305f\u3067\u3059\u3002<br \/>\n\u3067\u306f\u65e9\u901f\u4ee5\u4e0b\u306b\u307e\u3068\u3081\u307e\u3059\u3002<\/p>\n<p>\u30bd\u30fc\u30b9\u304b\u3089\u5165\u308c\u3066\u3082\u3044\u3044\u306e\u3067\u3059\u304c\u3001\u305b\u3063\u304b\u304f\u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u5b58\u5728\u3057\u3066\u3044\u308b\u306e\u3067\u3001yum\u304b\u3089\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u266a<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre># yum install mongodb-server<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<br \/>\n\u3068\u308a\u3042\u3048\u305a\u8d77\u52d5\u3092\u3057\u307e\u3059\u3002\u305d\u306e\u307e\u307e\u8d77\u52d5\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u3001\u3001\u3061\u306a\u307f\u306b\u7ba1\u7406\u4eba\u306f\u554f\u984c\u306a\u304f\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre># \/etc\/init.d\/mongod start\r\n\uff5e\r\nmongod \u3092\u8d77\u52d5\u4e2d:                                           [  OK  ]\r\n\uff5e<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<br \/>\n\u30d7\u30ed\u30bb\u30b9\u3092\u898b\u3066\u307f\u308b\u3068\u3001\u8d77\u52d5\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308b\u306f\u305a\u3067\u3059\u3002\u3053\u308c\u3067\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u3059\u3093\u306a\u308a\u3044\u3051\u30705\u5206\u3082\u304b\u304b\u308a\u307e\u305b\u3093\u3088\u306df(^^;)<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre># ps -ef | grep mongod\r\n\uff5e\r\nmongodb   7375     1  0 10:08 ?        00:00:00 \/usr\/bin\/mongod --quiet -f \/etc\/mongodb.conf run\r\n\uff5e<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u3053\u308c\u3067\u4e0b\u6e96\u5099\u306fOK\u2606\u3053\u3053\u304b\u3089\u304c\u3001\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a\u3068\u306a\u308a\u307e\u3059\u3002\u9806\u756a\u306b\u3084\u3063\u3066\u3044\u3051\u3070\u3067\u304d\u308b\u3068\u601d\u3044\u307e\u3059\uff01<br \/>\n1, \u305d\u308c\u305e\u308c\u306e\u8a2d\u5b9a\u3092\u5909\u66f4<br \/>\n\u203b bind_ip\u306f\u30ea\u30c3\u30b9\u30f3\u3059\u308bIP\u30a2\u30c9\u30ec\u30b9\u3001replSet\u306f\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3059\u308b\u969b\u306b\u8a2d\u5b9a\u3059\u308b\u30b0\u30eb\u30fc\u30d7\u306e\u540d\u524d\u306e\u3088\u3046\u306a\u3082\u306e\u3067\u3059\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre># vi \/etc\/mongodb.conf\r\n\uff5e\r\nbind_ip = 192.168.0.10\r\nreplSet=rep\r\n\uff5e<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>2, \u8a2d\u5b9a\u3092\u53cd\u6620<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre># \/etc\/init.d\/mongod restart<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>3, \u30ea\u30c3\u30b9\u30f3\u306e\u78ba\u8a8d<br \/>\n\u203b \u3061\u306a\u307f\u306b\u4eca\u56de\u306f3\u53f0\u306e\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u3057\u305f\u306e\u3067\u30013\u53f0\u8a2d\u5b9a\u3092\u3057\u307e\u3057\u305f\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre># netstat -ant\r\n\uff5e\r\nActive Internet connections (servers and established)\r\nProto Recv-Q Send-Q Local Address               Foreign Address             State\r\ntcp        0      0 192.168.0.10:27017         0.0.0.0:*                   LISTEN\r\n\uff5e<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>4, \u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u8a2d\u5b9a<br \/>\n\u203b &#8211;host\u3067\u6307\u5b9a\u3059\u308b\u3068\u3001\u305d\u306e\u30b5\u30fc\u30d0\u306eMongoDB\u306b\u30ed\u30b0\u30a4\u30f3\u3067\u304d\u307e\u3059\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre># mongo --host 192.168.0.10\r\n> config = {_id: \"rep\", members: [\r\n&nbsp;&nbsp;{_id: 0, host: '192.168.0.10:27017' },\r\n&nbsp;&nbsp;{_id: 1, host: '192.168.0.20:27017' },\r\n&nbsp;&nbsp;{_id: 2, host: '192.168.0.30:27017' }]\r\n}<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<br \/>\n5, \u8a2d\u5b9a\u3092\u66f8\u304d\u8fbc\u307f<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre>> rs.initiate(config);\r\n{\r\n&nbsp;&nbsp;\"info\" : \"Config now saved locally.  Should come online in about a minute.\",\r\n&nbsp;&nbsp;\"ok\" : 1\r\n}<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>6, \u6700\u5f8c\u306b\u8a2d\u5b9a\u3092\u78ba\u8a8d<br \/>\n\u203b \u30d7\u30e9\u30a4\u30de\u30ea\u3068\u30bb\u30ab\u30f3\u30c0\u30ea\u306b\u306a\u3063\u3066\u3044\u308b\u3053\u3068\u304c\u5206\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<table style=\"table-layout:fixed;\">\n<tr>\n<td>\n<div style=\"overflow-x:auto;\">\n<pre># mongo --host 192.168.0.10\r\nrep:PRIMARY> rs.status()\r\n{\r\n&nbsp;&nbsp;\"set\" : \"rep\",\r\n&nbsp;&nbsp;\"date\" : ISODate(\"2013-04-26T02:43:07Z\"),\r\n&nbsp;&nbsp;\"myState\" : 1,\r\n&nbsp;&nbsp;\"members\" : [\r\n&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"_id\" : 0,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"name\" : \"192.168.0.10:27017\",\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"health\" : 1,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"state\" : 1,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"stateStr\" : \"PRIMARY\",\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"uptime\" : 169,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"optime\" : {\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"t\" : 1366944049000,\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"i\" : 1\r\n&nbsp;&nbsp;&nbsp;&nbsp;},\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"optimeDate\" : ISODate(\"2013-04-26T02:40:49Z\"),\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"self\" : true\r\n&nbsp;&nbsp;},\r\n&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"_id\" : 1,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"name\" : \"192.168.0.20:27017\",\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"health\" : 1,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"state\" : 2,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"stateStr\" : \"SECONDARY\",\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"uptime\" : 128,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"optime\" : {\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"t\" : 1366944049000,\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"i\" : 1\r\n&nbsp;&nbsp;&nbsp;&nbsp;},\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"optimeDate\" : ISODate(\"2013-04-26T02:40:49Z\"),\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"lastHeartbeat\" : ISODate(\"2013-04-26T02:43:07Z\"),\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"pingMs\" : 0\r\n&nbsp;&nbsp;},\r\n&nbsp;&nbsp;{\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"_id\" : 2,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"name\" : \"192.168.0.30:27017\",\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"health\" : 1,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"state\" : 2,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"stateStr\" : \"SECONDARY\",\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"uptime\" : 126,\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"optime\" : {\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"t\" : 1366944049000,\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"i\" : 1\r\n&nbsp;&nbsp;&nbsp;&nbsp;},\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"optimeDate\" : ISODate(\"2013-04-26T02:40:49Z\"),\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"lastHeartbeat\" : ISODate(\"2013-04-26T02:43:07Z\"),\r\n&nbsp;&nbsp;&nbsp;&nbsp;\"pingMs\" : 0\r\n&nbsp;&nbsp;&nbsp;&nbsp;}\r\n&nbsp;&nbsp;],\r\n&nbsp;&nbsp;\"ok\" : 1\r\n}<\/pre>\n<\/p><\/div>\n<\/td>\n<\/tr>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u30d7\u30e9\u30a4\u30de\u30ea\u306eMongoDB\u3092\u505c\u6b62\u3057\u305f\u3089\u4ed6\u306e\u30b5\u30fc\u30d0\u304c\u81ea\u52d5\u7684\u306b\u30d7\u30e9\u30a4\u30de\u30ea\u306b\u306a\u308a\u307e\u3057\u305fw(\uffe3o\uffe3)w \uff75\uff75\uff70!<br \/>\n\u307e\u3060\u5168\u7136\u3055\u308f\u3063\u3066\u306a\u3044\u306e\u3067\u3044\u308d\u3044\u308d\u3084\u3063\u3066\u307f\u305f\u3044\u3067\u3059\u306d\u3002<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"http:\/\/www.nightmare-yk.com\/?p=761\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"http:\/\/www.nightmare-yk.com\/?p=761\" ><\/g:plusone><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>OSS\u306e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u6709\u540d\u306a\u3082\u306e\u3068\u3057\u3066\u306f\u3001MySQL\u3084PostgreSQL\u304c\u3042\u308a\u307e\u3059\u3002 \u4eca\u56de\u306f\u3001MongoDB\u3068\u3044\u3046\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u3092\u6271\u3063\u3066\u307f\u307e\u3059\u3002\u8a2d\u5b9a\u306f\u6bd4\u8f03\u7684\u7c21\u5358\u3067\u3057\u305f\u304c\u3001\u307e\u3060\u6697\u8a18\u3092\u3057\u305f\u308f\u3051\u3067\u306f\u306a\u3044\u306e\u3067\u3001\u30e1\u30e2\u30e1\u30e2\u3006(.. ) MySQL\u306e\u30ec\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\u610f\u5916\u3068\u5927\u5909\u306a\u3093\u3067\u3059\u3088\u306d\u3002\u6163\u308c\u305f\u4eba\u306b\u306f\u7c21\u5358\u306a\u306e\u304b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[3],"tags":[22,94],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/posts\/761"}],"collection":[{"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=761"}],"version-history":[{"count":15,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions"}],"predecessor-version":[{"id":773,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=\/wp\/v2\/posts\/761\/revisions\/773"}],"wp:attachment":[{"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=761"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.nightmare-yk.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}