{"id":5035,"date":"2024-01-13T19:29:27","date_gmt":"2024-01-13T11:29:27","guid":{"rendered":"https:\/\/www.kenpai.com\/cms\/5035\/"},"modified":"2024-01-13T19:29:27","modified_gmt":"2024-01-13T11:29:27","slug":"%e6%b5%8b%e8%af%95%e4%b8%80%e4%b8%aaconfig-server-%e6%9c%8d%e5%8a%a1%e5%99%a8%e6%8c%82%e6%9c%ba%e5%90%8e%ef%bc%8c%e9%9b%86%e7%be%a4%e6%98%af%e5%90%a6%e8%83%bd%e8%af%bb%e5%86%99%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/www.kenpai.com\/cms\/5035\/","title":{"rendered":"\u6d4b\u8bd5\u4e00\u4e2aconfig server \u670d\u52a1\u5668\u6302\u673a\u540e\uff0c\u96c6\u7fa4\u662f\u5426\u80fd\u8bfb\u5199\u6570\u636e"},"content":{"rendered":"<\/p>\n<p>\u6d4b\u8bd5\u67b6\u6784\uff1a<\/p>\n<p>\u6d4b\u8bd5\u76ee\u7684\uff1a<\/p>\n<p>\u6d4b\u8bd5\u4e00\u4e2aconfig server \u670d\u52a1\u5668\u6302\u673a\u540e\uff0c\u96c6\u7fa4\u662f\u5426\u80fd\u8bfb\u5199\u6570\u636e\u3002<\/p>\n<p>\u6d4b\u8bd5\u539f\u56e0\uff1a<\/p>\n<p>\u4e0a\u5468\u56e0\u4e3a\u5185\u5b58\u5403\u7d27\uff0c\u51c6\u5907\u6dfb\u52a0\u5185\u5b58\u3002\u5728\u67e5\u770b\u670d\u52a1\u5668\u65f6\uff0c\u628a\u4e00\u53f0\u670d\u52a1\u5668\u5173\u673a\u68c0\u67e5\u3002<br \/>\u5173\u673a\u540e\uff0cWEB \u7aef\u5e94\u7528\u51fa\u9519\uff0c\u7528\u6237\u65e0\u6cd5\u767b\u5f55\uff0c\u6240\u6709\u90fd\u51fa\u9519\u3002<\/p>\n<p>\u4f46\u5728\u6211\u7406\u89e3\uff0c\u56e0\u4e3aCONFIG\u662f3\u53f0\u5197\u4f59\u7684\uff0c\u4e00\u53f0\u5173\u673a\uff0c\u5e94\u8be5\u4e0d\u4f1a\u4ea7\u751f\u5f71\u54cd\u624d\u5bf9\uff0c\u6216\u8005\u8bf4\u4e0d\u4f1a\u5f71\u54cd\u5230\u65e0\u6cd5<br \/>\u767b\u5f55\uff0c\u5e94\u7528\u4e0d\u80fd\u6b63\u5e38\u8fd0\u884c\u3002\u53ea\u662f\u4f1a\u6709\u6570\u636e\u4e0d\u5747\u8861\u554a\u3002<\/p>\n<p>\u4f46\u6211\u4f7f\u7528mongochef \u767b\u5f55\uff0c\u786e\u5b9e\u767b\u5f55\u6570\u636e\u5e93\u4e0d\u6210\u529f\u3002<\/p>\n<p>\u6d4b\u8bd5\u7ed3\u679c\uff1a<\/p>\n<p>\u7ecf\u4e0b\u9762\u7684\u6d4b\u8bd5\uff0c\u5370\u8bc1\u4e86\u6211\u7684\u7406\u89e3\uff0c\u4e00\u53f0config \u5b95\u673a\uff0c\u53ea\u662f\u4f1a\u63d0\u793a\u8fde\u63a5config \u51fa\u9519\uff0c<br \/>\u4f46\u80fd\u767b\u5f55\u6570\u636e\u5e93\uff0c\u63d2\u5165\u6570\u636e\u7684\u4ee3\u7801\uff08mongo -port 28000 \u767b\u5f55\u540e\u8fd0\u884c\u7684JS \u4ee3\u7801\uff09\uff0c\u8fd8\u80fd\u6b63\u5e38\u8fd0\u884c\u4e0b\u53bb\u3002<\/p>\n<p>\u4f46\u4e3a\u4ec0\u4e48\u5f53\u65f6WEB \u7aef\u4f1a\u51fa\u9519\uff0c\u6211\u770b\u5230\u4ed6\u4eecphp \u914d\u7f6e\u6587\u4ef6\u4e2d\u5982\u4e0b\uff1a<br \/>$connect = new MongoClient(&quot;mongodb:\/\/192.168.2.188:28000,192.168.2.132:28000&quot;, array(&quot;replicaSet&quot; =&gt; &quot;myReplSet&quot;));<\/p>\n<p>\u5374\u6ca1\u52a0MongoConnectionException\u3002 \u5bb9\u9519\u51fa\u9519\u6ca1\u6709\u7684\u8bdd\uff0c\u5f53\u6b63\u5728\u64cd\u4f5c\u65f6\uff0c\u4e00\u4e2acollection\u6253\u5f00\u51fa\u9519\uff0c\u4e0d\u4f1a\u518d\u91cd\u65b0\u8fde\u63a5\u6570\u636e\u5e93\uff0c<br \/>\u5c31\u62a5\u9519\u4e86\u3002\u5982\u679c\u8fd9\u65f6\u80fd\u91cd\u65b0\u8fde\u63a5\u6570\u636e\u5e93\uff0c\u5e94\u8be5\u80fd\u518d\u627e\u5230\u53e6\u5916\u6b63\u5e38\u7684\u8282\u70b9\u8fde\u63a5\u7684\u3002<\/p>\n<p>\u6d4b\u8bd5\u73af\u5883\u4e3a\uff1a mongodb3.0.3<br \/>2\u4e2ashard\uff0c3\u4e2a\u914d\u7f6econfig\uff0c3\u4e2amongos<\/p>\n<p>set  host\uff1aport   stateStr             <br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>shard1  192.168.2.188:28011  PRIMARY     <br \/>shard1  192.168.2.132:28011  SECONDARY    <br \/>shard1  192.168.2.134:28011  SECONDARY    <\/p>\n<p>shard2  192.168.2.188:28012  SECONDARY    <br \/>shard2  192.168.2.132:28012  SECONDARY    <br \/>shard2  192.168.2.134:28012  PRIMARY     <\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br \/>192.168.2.188:28010  config       <br \/>192.168.2.188:28000  mongos       <\/p>\n<p>192.168.2.132:28010  config       <br \/>192.168.2.132:28000  mongos       <\/p>\n<p>192.168.2.134:28010  config       <br \/>192.168.2.134:28000  mongos      <\/p>\n<p>#\u5907\u7528\u670d\u52a1\u5668\uff0c\u5f53134\u6302\u673a\u540e\uff0c\u628a134 \u5bf9\u5e94\u7684t3 \u670d\u52a1\u5668\u540d\u79f0\u4fee\u6539\u4e3a 135<\/p>\n<p>192.168.2.135:28010  config       <\/p>\n<p>\u5404\u670d\u52a1\u5668\u7684hosts \u6587\u4ef6\uff1a<br \/>[root@localhost bin]# cat \/etc\/hosts<br \/>192.168.2.188 t1<br \/>192.168.2.132 t2<br \/>192.168.2.134 t3<\/p>\n<p>192.168.2.135 t4<\/p>\n<p>\u4e00\u3001\u914d\u7f6e\u96c6\u7fa4\uff1a<\/p>\n<p>\u521d\u59cb\u5316replica set shard1<br \/>\u7528mongo \u8fde\u63a5\u5176\u4e2d\u4e00\u4e2a\u8282\u70b9\uff1a \u6bd4\u5982\uff1ashard11 \u6267\u884c\u4ee5\u4e0b\uff1a<\/p>\n<p>&gt; config = {_id: \\\\\\&#8217;shard1\\\\\\&#8217;, members: [<br \/>{_id: 0, host:\\\\\\&#8217;t1:28011\\\\\\&#8217;}]<br \/>}<\/p>\n<p>&gt; rs.initiate(config);<\/p>\n<p>rs.add({_id: 1, host:\\\\\\&#8217;t2:28011\\\\\\&#8217;})<br \/>rs.add({_id: 2, host:\\\\\\&#8217;t3:28011\\\\\\&#8217;})<\/p>\n<p>\u521d\u59cb\u5316replica set shard2<br \/>\u7528mongo \u8fde\u63a5\u5176\u4e2d\u4e00\u4e2a\u8282\u70b9\uff1a \u6bd4\u5982\uff1ashard11 \u6267\u884c\u4ee5\u4e0b\uff1a<\/p>\n<p>&gt; config = {_id: \\\\\\&#8217;shard2\\\\\\&#8217;, members: [<br \/>{_id: 0, host:\\\\\\&#8217;t1:28012\\\\\\&#8217;}]<br \/>}<\/p>\n<p>&gt; rs.initiate(config);<\/p>\n<p>rs.add({_id: 1, host:\\\\\\&#8217;t2:28012\\\\\\&#8217;})<br \/>rs.add({_id: 2, host:\\\\\\&#8217;t3:28012\\\\\\&#8217;})<\/p>\n<p>#\u9047\u5230\u5982\u4e0b\u9519\u8bef<br \/>shard2:PRIMARY&gt; rs.add({_id: 1, host:\\\\\\&#8217;t2:28012\\\\\\&#8217;})<br \/>{<br \/>&quot;ok&quot; : 0,<br \/>&quot;errmsg&quot; : &quot;Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: t1:28012; the following nodes did not respond affirmatively: t2:28012 failed with Failed attempt to connect to  t2:28012; couldn\\\\\\&#8217;t connect to server t2:28012 (192.168.2.132), connection attempt failed&quot;,<br \/>&quot;code&quot; : 74<br \/>}<br \/>#\u539f\u56e0\uff1a\u6709\u9632\u706b\u5899<br \/>#\u5173\u95ed\u9632\u706b\u5899<br \/>[root@t2 ~]# chkconfig iptables off<br \/>[root@t2 ~]# service iptables stop<br \/>iptables\uff1a\u6e05\u9664\u9632\u706b\u5899\u89c4\u5219\uff1a [\u786e\u5b9a]<br \/>iptables\uff1a\u5c06\u94fe\u8bbe\u7f6e\u4e3a\u653f\u7b56 ACCEPT\uff1anat mangle filter [\u786e\u5b9a]<br \/>iptables\uff1a\u6b63\u5728\u5378\u8f7d\u6a21\u5757\uff1a [\u786e\u5b9a]<br \/>[root@t2 ~]# <\/p>\n<p>\u4e8c\u3001\u914d\u7f6e\u5206\u7247<\/p>\n<p>1\uff1a\u914d\u7f6e\u4e00\u4e0b\u65f6\u95f4\u4e00\u81f4\uff0c\u4e0d\u7136\u65e0\u6cd5\u5efa\u7acb\u5206\u7247\u96c6\u7fa4\uff1a<\/p>\n<p>*\/5 * * * * \/usr\/sbin\/ntpdate -u ntp.sjtu.edu.cn<\/p>\n<p>2.mongos \u8fd0\u884c\u65f6\u7684\u53c2\u6570\u5982\u4e0b\uff1a<br \/>\/opt\/mongodb3.0.3\/bin\/mongos &#8211;configdb t1:28010,t2:28010,t3:28010 &#8211;port 28000 &#8211;logpath \/opt\/mongodb3.0.3\/logs\/mongos.log &#8211;logappend &#8211;fork<\/p>\n<p>3.\u8fde\u63a5\u5230\u5176\u4e2d\u4e00\u4e2amongos\u8fdb\u7a0b\uff0c\u5e76\u5207\u6362\u5230admin\u6570\u636e\u5e93\u505a\u4ee5\u4e0b\u914d\u7f6e<br \/>3.1. \u8fde\u63a5\u5230mongs\uff0c\u5e76\u5207\u6362\u5230admin<br \/>.\/mongo 192.168.20.11:28000\/admin<br \/>&gt;db<br \/>Admin<br \/>3.2. \u52a0\u5165shards<br \/>\u547d\u4ee4\u683c\u5f0f\uff1a<br \/>replicaSetName\/[:port] [,serverhostname2[:port],&hellip;]<\/p>\n<p>\u6267\u884c\u5982\u4e0b\uff1a<br \/>&gt;use admin;<br \/>&gt;db.runCommand({addshard:&quot;shard1\/t1:28011,t2:28011,t3:28011&quot;});<br \/>&gt;db.runCommand({addshard:&quot;shard2\/t1:28012,t2:28012,t3:28012&quot;});<\/p>\n<p>\u6dfb\u52a0\u5206\u7247\u540e\uff0c\u628achunksize \u6539\u6210 1M\uff0c\u4ee5\u65b9\u4fbf\u6d4b\u8bd5<br \/>&gt;use config<br \/>mongos&gt; db.shards.find()<br \/>{ &quot;_id&quot; : &quot;shard1&quot;, &quot;host&quot; : &quot;shard1\/t1:28011,t2:28011,t3:28011&quot; }<br \/>{ &quot;_id&quot; : &quot;shard2&quot;, &quot;host&quot; : &quot;shard2\/t1:28012,t2:28012,t3:28012&quot; }<br \/>mongos&gt; db.settings.find()<br \/>{ &quot;_id&quot; : &quot;chunksize&quot;, &quot;value&quot; : 64 }<br \/>mongos&gt; db.settings.update({_id:\\\\\\&#8217;chunksize\\\\\\&#8217;},{$set:{value:1}})<br \/>WriteResult({ &quot;nMatched&quot; : 1, &quot;nUpserted&quot; : 0, &quot;nModified&quot; : 1 })<br \/>mongos&gt; db.settings.find()<br \/>{ &quot;_id&quot; : &quot;chunksize&quot;, &quot;value&quot; : 1 }<br \/>mongos&gt; <\/p>\n<p>\u5230\u6b64\u5206\u7247\u96c6\u7fa4\u914d\u7f6e\u5df2\u5b8c\u6210<\/p>\n<p>\u4e09\u3001\u6dfb\u52a0\u6570\u636e<\/p>\n<p>db.runCommand({&quot;enablesharding&quot;:&quot;test&quot;}) <br \/>db.runCommand({shardcollection:&quot;test.customer&quot;,key:{_id:1}});<\/p>\n<p>#\u8868\u4e2d\u63d2\u5165\u6570\u636e\uff1a<br \/>use test;<br \/>for (i = 1; i &lt;= 90000; i  ){<br \/>db.customer.insert({_id:i,name:\\\\\\&#8217; test name test name test name test name test name test name test name test name test name end\\\\\\&#8217;,<br \/>address:\\\\\\&#8217;address test customer al;dkjfa;lsdfjsal;#^end\\\\\\&#8217;,province:\\\\\\&#8217;test customer province\\\\\\&#8217;,city:\\\\\\&#8217;test customer city\\\\\\&#8217;});<br \/>}<\/p>\n<p>\u7528\u4e8e\u6d4b\u8bd5\u65f6\u67e5\u770b\u5404\u6570\u636e\u6240\u5728\u7684\u5206\u7247\u3002<\/p>\n<p>\u4ece\u4e0b\u9762\u7684\u67e5\u8be2\u4e2d\uff0c\u53ef\u4ee5\u770b\u5230test.customer\u6570\u636e\u5df2\u5206\u7247\u5230shard1,shard2<\/p>\n<p>mongos&gt; db.chunks.find()<br \/>{ &quot;_id&quot; : &quot;test.customer-_id_MinKey&quot;, &quot;lastmod&quot; : Timestamp(2, 1), &quot;lastmodEpoch&quot; : ObjectId(&quot;55b99f3ff5ddb9333eda7464&quot;), &quot;ns&quot; : &quot;test.customer&quot;, &quot;min&quot; : { &quot;_id&quot; : { &quot;$minKey&quot; : 1 } }, &quot;max&quot; : { &quot;_id&quot; : 2 }, &quot;shard&quot; : &quot;shard2&quot; }<br \/>{ &quot;_id&quot; : &quot;test.customer-_id_2.0&quot;, &quot;lastmod&quot; : Timestamp(1, 2), &quot;lastmodEpoch&quot; : ObjectId(&quot;55b99f3ff5ddb9333eda7464&quot;), &quot;ns&quot; : &quot;test.customer&quot;, &quot;min&quot; : { &quot;_id&quot; : 2 }, &quot;max&quot; : { &quot;_id&quot; : 6 }, &quot;shard&quot; : &quot;shard2&quot; }<br \/>{ &quot;_id&quot; : &quot;test.customer-_id_6.0&quot;, &quot;lastmod&quot; : Timestamp(2, 2), &quot;lastmodEpoch&quot; : ObjectId(&quot;55b99f3ff5ddb9333eda7464&quot;), &quot;ns&quot; : &quot;test.customer&quot;, &quot;min&quot; : { &quot;_id&quot; : 6 }, &quot;max&quot; : { &quot;_id&quot; : 2120 }, &quot;shard&quot; : &quot;shard1&quot; }<br \/>{ &quot;_id&quot; : &quot;test.customer-_id_2120.0&quot;, &quot;lastmod&quot; : Timestamp(2, 3), &quot;lastmodEpoch&quot; : ObjectId(&quot;55b99f3ff5ddb9333eda7464&quot;), &quot;ns&quot; : &quot;test.customer&quot;, &quot;min&quot; : { &quot;_id&quot; : 2120 }, &quot;max&quot; : { &quot;_id&quot; : 4579 }, &quot;shard&quot; : &quot;shard1&quot; }<br \/>{ &quot;_id&quot; : &quot;test.customer-_id_4579.0&quot;, &quot;lastmod&quot; : Timestamp(2, 5), &quot;lastmodEpoch&quot; : ObjectId(&quot;55b99f3ff5ddb9333eda7464&quot;), &quot;ns&quot; : &quot;test.customer&quot;, &quot;min&quot; : { &quot;_id&quot; : 4579 }, &quot;max&quot; : { &quot;_id&quot; : 6693 }, &quot;shard&quot; : &quot;shard1&quot; }<br \/>{ &quot;_id&quot; : &quot;test.customer-_id_6693.0&quot;, &quot;lastmod&quot; : Timestamp(2, 6), &quot;lastmodEpoch&quot; : ObjectId(&quot;55b99f3ff5ddb9333eda7464&quot;), &quot;ns&quot; : &quot;test.customer&quot;, &quot;min&quot; : { &quot;_id&quot; : 6693 }, &quot;max&quot; : { &quot;_id&quot; : 9371 }, &quot;shard&quot; : &quot;shard1&quot; }<br \/>{ &quot;_id&quot; : &quot;test.customer-_id_9371.0&quot;, &quot;lastmod&quot; : Timestamp(2, 7), &quot;lastmodEpoch&quot; : ObjectId(&quot;55b99f3ff5ddb9333eda7464&quot;), &quot;ns&quot; : &quot;test.customer&quot;, &quot;min&quot; : { &quot;_id&quot; : 9371 }, &quot;max&quot; : { &quot;_id&quot; : { &quot;$maxKey&quot; : 1 } }, &quot;shard&quot; : &quot;shard1&quot; }<br \/>mongos&gt; db.collections.find()<br \/>{ &quot;_id&quot; : &quot;test.customer&quot;, &quot;lastmod&quot; : ISODate(&quot;2015-07-30T03:51:28.671Z&quot;), &quot;dropped&quot; : false, &quot;key&quot; : { &quot;_id&quot; : 1 }, &quot;unique&quot; : false, &quot;lastmodEpoch&quot; : ObjectId(&quot;55b99f3ff5ddb9333eda7464&quot;) }<br \/>mongos&gt; <\/p>\n<p>\u56db\u3001\u6d4b\u8bd5\u6302\u6389\u4e00\u4e2aconfig:<\/p>\n<p>4.1 <\/p>\n<p>[mongo@localhost bin]$ ll \/opt\/mongodb3.0.3\/config<br \/>\u603b\u7528\u91cf 0<br \/>[mongo@localhost bin]$ .\/configd_start.sh <br \/>about to fork child process, waiting until server is ready for connections.<br \/>forked process: 2638<br \/>child process started successfully, parent exiting<br \/>[mongo@localhost bin]$ ps -ef|grep mongod<br \/>mongo 2455 1 28 10:51 ? 00:04:14 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard1.conf<br \/>mongo 2518 1 7 10:51 ? 00:01:11 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard2.conf<br \/>mongo 2638 1 7 10:53 ? 00:00:59 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f configsvr.conf<br \/>mongo 2931 2083 8 11:06 pts\/0 00:00:00 grep mongod<br \/>[mongo@localhost bin]$ kill -9 2638<br \/>[mongo@localhost bin]$ ps -ef|grep mongod<br \/>mongo 2455 1 27 10:51 ? 00:04:16 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard1.conf<br \/>mongo 2518 1 7 10:51 ? 00:01:13 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard2.conf<br \/>mongo 2941 2083 6 11:06 pts\/0 00:00:00 grep mongod<br \/>[mongo@localhost bin]$ <\/p>\n<p>#t1\u767b\u5f55\u6ca1\u95ee\u9898<br \/>[mongo@t1 bin]$ .\/mongo -port 28000<br \/>MongoDB shell version: 3.0.3<br \/>connecting to: 127.0.0.1:28000\/test<br \/>mongos&gt; show dbs;<br \/>admin (empty)<br \/>config (empty)<br \/>test 0.002GB<br \/>mongos&gt; <\/p>\n<p>#t2\u767b\u5f55 \u4e5f\u6ca1\u95ee\u9898<br \/>[mongo@t2 bin]$ .\/mongo -port 28000<br \/>MongoDB shell version: 3.0.3<br \/>connecting to: 127.0.0.1:28000\/test<br \/>mongos&gt; <\/p>\n<p>#\u540c\u6837\uff0c\u4f7f\u7528mongochef \u5ba2\u6237\u7aef\u767b\u5f55\uff0c\u4e5f\u540c\u6837\u9a8c\u8bc1\u4e86\u4e0a\u9762\u7684\u95ee\u9898\uff0c<\/p>\n<p>4.2.<br \/>\u628a\u5206\u7247\u4ecehostname\u4fee\u6539\u6210ip:<\/p>\n<p>&gt; config = {_id: \\\\\\&#8217;shard1\\\\\\&#8217;, members: [<br \/>{_id: 0, host:\\\\\\&#8217;192.168.2.188:28011\\\\\\&#8217;}]<br \/>}<\/p>\n<p>&gt; rs.initiate(config);<\/p>\n<p>rs.add({_id: 1, host:\\\\\\&#8217;192.168.2.132:28011\\\\\\&#8217;})<br \/>rs.add({_id: 2, host:\\\\\\&#8217;192.168.2.134:28011\\\\\\&#8217;})<\/p>\n<p>&gt; config = {_id: \\\\\\&#8217;shard2\\\\\\&#8217;, members: [<br \/>{_id: 0, host:\\\\\\&#8217;192.168.2.188:28012\\\\\\&#8217;}]<br \/>}<\/p>\n<p>&gt; rs.initiate(config);<\/p>\n<p>rs.add({_id: 1, host:\\\\\\&#8217;192.168.2.132:28012\\\\\\&#8217;})<br \/>rs.add({_id: 2, host:\\\\\\&#8217;192.168.2.134:28012\\\\\\&#8217;})<\/p>\n<p>#\u628amongos \u7684\u53c2\u6570\u4e2d\u7684hostname\u4e5f\u4fee\u6539\u6210IP<\/p>\n<p>[mongo@t1 bin]$ cat mongos_router.sh <br \/>\/opt\/mongodb3.0.3\/bin\/mongos &#8211;configdb 192.168.2.188:28010,192.168.2.132:28010,192.168.2.134:28010 &#8211;port 28000 &#8211;logpath \/opt\/mongodb3.0.3\/logs\/mongos.log &#8211;logappend &#8211;fork<br \/>[mongo@t1 bin]$<\/p>\n<p>#\u6dfb\u52a0\u5206\u7247\uff0c\u628achunksize \u6539\u6210 1M\uff0c\u4ee5\u65b9\u4fbf\u6d4b\u8bd5<\/p>\n<p>&gt;use admin;<br \/>&gt;db.runCommand({addshard:&quot;shard1\/192.168.2.188:28011,192.168.2.132:28011,192.168.2.134:28011&quot;});<br \/>&gt;db.runCommand({addshard:&quot;shard2\/192.168.2.188:28012,192.168.2.132:28012,192.168.2.134:28012&quot;});<\/p>\n<p>db.settings.update({_id:\\\\\\&#8217;chunksize\\\\\\&#8217;},{$set:{value:1}})<\/p>\n<p>#\u5f53\u6240\u6709\u914d\u7f6e\u8bbe\u7f6e\u6210\u4f7f\u7528IP\u540e\uff0c\u5b95\u6389config server.<br \/>#\u518d\u4ece\u672c\u673a\u5c1d\u8bd5\u8fde\u63a5\uff0c\u53d1\u73b0\u4e0d\u6210\u529f\u3002<\/p>\n<p>[mongo@localhost bin]$ ps -ef|grep mongod<br \/>mongo 4062 1 10 11:48 ? 00:09:56 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard1.conf<br \/>mongo 4082 1 8 11:48 ? 00:08:09 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard2.conf<br \/>mongo 4102 1 11 11:48 ? 00:10:45 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f configsvr.conf<br \/>mongo 4121 1 5 11:49 ? 00:04:55 \/opt\/mongodb3.0.3\/bin\/mongos &#8211;configdb 192.168.2.188:28010,192.168.2.132:28010,192.168.2.134:28010 &#8211;logpath \/opt\/mongodb3.0.3\/logs\/mongos.log &#8211;logappend &#8211;fork<br \/>root 9459 9420 0 13:23 pts\/1 00:00:00 tail -330f \/opt\/mongodb3.0.3\/logs\/shard1.log<br \/>mongo 9471 2083 5 13:23 pts\/0 00:00:00 grep mongod<br \/>[mongo@localhost bin]$ kill -9 4102<br \/>[mongo@localhost bin]$ ps -ef|grep mongod<br \/>mongo 4062 1 10 11:48 ? 00:10:20 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard1.conf<br \/>mongo 4082 1 8 11:48 ? 00:08:18 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard2.conf<br \/>mongo 4121 1 5 11:49 ? 00:04:59 \/opt\/mongodb3.0.3\/bin\/mongos &#8211;configdb 192.168.2.188:28010,192.168.2.132:28010,192.168.2.134:28010 &#8211;logpath \/opt\/mongodb3.0.3\/logs\/mongos.log &#8211;logappend &#8211;fork<br \/>root 9459 9420 0 13:23 pts\/1 00:00:00 tail -330f \/opt\/mongodb3.0.3\/logs\/shard1.log<br \/>mongo 9488 2083 5 13:24 pts\/0 00:00:00 grep mongod<\/p>\n<p>[mongo@localhost bin]$ .\/mongo -port 28000<br \/>MongoDB shell version: 3.0.3<br \/>connecting to: 127.0.0.1:28000\/test<br \/>2015-07-31T13:25:52.166 0800 W NETWORK Failed to connect to 127.0.0.1:28000, reason: errno:111 Connection refused<br \/>2015-07-31T13:25:53.514 0800 E QUERY Error: couldn\\\\\\&#8217;t connect to server 127.0.0.1:28000 (127.0.0.1), connection attempt failed<br \/>at connect (src\/mongo\/shell\/mongo.js:181:14)<br \/>at (connect):1:6 at src\/mongo\/shell\/mongo.js:181<br \/>exception: connect failed<br \/>[mongo@localhost bin]$ .\/mongo -port 28000<br \/>MongoDB shell version: 3.0.3<br \/>connecting to: 127.0.0.1:28000\/test<br \/>2015-07-31T13:26:30.823 0800 W NETWORK Failed to connect to 127.0.0.1:28000, reason: errno:111 Connection refused<br \/>2015-07-31T13:26:32.929 0800 E QUERY Error: couldn\\\\\\&#8217;t connect to server 127.0.0.1:28000 (127.0.0.1), connection attempt failed<br \/>at connect (src\/mongo\/shell\/mongo.js:181:14)<br \/>at (connect):1:6 at src\/mongo\/shell\/mongo.js:181<br \/>exception: connect failed<\/p>\n<p>[mongo@localhost bin]$ ps -ef|grep mongod<br \/>mongo 4062 1 12 11:48 ? 00:11:48 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard1.conf<br \/>mongo 4082 1 8 11:48 ? 00:08:29 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard2.conf<br \/>mongo 4121 1 5 11:49 ? 00:05:09 \/opt\/mongodb3.0.3\/bin\/mongos &#8211;configdb 192.168.2.188:28010,192.168.2.132:28010,192.168.2.134:28010 &#8211;logpath \/opt\/mongodb3.0.3\/logs\/mongos.log &#8211;logappend &#8211;fork<br \/>root 9459 9420 0 13:23 pts\/1 00:00:00 tail -330f \/opt\/mongodb3.0.3\/logs\/shard1.log<br \/>mongo 9754 2083 7 13:26 pts\/0 00:00:00 grep mongod<br \/>[mongo@localhost bin]$ .\/mongo -port 28000<br \/>MongoDB shell version: 3.0.3<br \/>connecting to: 127.0.0.1:28000\/test<br \/>2015-07-31T13:28:17.397 0800 W NETWORK Failed to connect to 127.0.0.1:28000, reason: errno:111 Connection refused<br \/>2015-07-31T13:28:19.161 0800 E QUERY Error: couldn\\\\\\&#8217;t connect to server 127.0.0.1:28000 (127.0.0.1), connection attempt failed<br \/>at connect (src\/mongo\/shell\/mongo.js:181:14)<br \/>at (connect):1:6 at src\/mongo\/shell\/mongo.js:181<br \/>exception: connect failed<br \/>[mongo@localhost bin]$ <\/p>\n<p>#\u800c\u5176\u5b83\u8282\u70b9\uff08t2,t1\uff09\u670d\u52a1\u5668\u8fde\u63a5\u6ca1\u6709\u95ee\u9898\u3002\u4f7f\u7528mongochef \u6d4b\u8bd5\uff0c\u4e5f\u5370\u8bc1\u4e86\u8fd9\u70b9\u3002<br \/>\u662f\u5426\u8bf4\u4f7f\u7528Ip\u5730\u5740\uff0c\u771f\u7684\u662f\u5728\u670d\u52a1\u5668\u96c6\u7fa4\u4e2d\uff0c\u7a33\u5b9a\u6027\u4f1a\u5dee\u4e00\u4e9b\u5462\u3002<br \/>\u5e76\u4e14\u6211\u540c\u5728\u5b95\u6389config server. \u65f6\uff0c\u6d4b\u8bd5\u5faa\u73af\u63d2\u5165\u6570\u636e\u7684\u4ee3\u7801\u6ca1\u6709\u4e2d\u6b62\u3002\u540e\u9762\u4e5f\u4e00\u76f4\u5728\u63d2\u5165\u6570\u636e\u3002<\/p>\n<p>[mongo@t2 bin]$ .\/mongo -port 28000<br \/>MongoDB shell version: 3.0.3<br \/>connecting to: 127.0.0.1:28000\/test<br \/>mongos&gt; <br \/>connecting to: 127.0.0.1:28000\/test<br \/>mongos&gt; db.customer.count()<br \/>10024<br \/>mongos&gt; db.customer.count()<br \/>10091<br \/>mongos&gt; db.customer.count()<br \/>10103<br \/>mongos&gt; <\/p>\n<p>\u53ef\u4ee5\u4ece\u4e0b\u9762\u7684\u65e5\u5fd7\u4e2d\u770b\u5230\u8fd9\u70b9\uff1a<\/p>\n<p>2015-07-31T13:34:55.114 0800 I NETWORK [LockPinger] trying reconnect to 192.168.2.134:28010 (192.168.2.134) failed<br \/>2015-07-31T13:34:55.328 0800 W NETWORK [LockPinger] Failed to connect to 192.168.2.134:28010, reason: errno:111 Connection refused<br \/>2015-07-31T13:34:55.383 0800 I WRITE [conn258] insert test.customer query: { _id: 11119.0, name: &quot; test name test name test name test name test name test name test name test name test name end&quot;, address: &quot;address test customer al;dkjfa;lsdfjsal;#^end&quot;,  province: &quot;test customer province&quot;, city: &quot;test customer city&quot; } ninserted:1 keyUpdates:0 writeConflicts:0 numYields:0 locks:{ Global: { acquireCount: { w: 2 } }, Database: { acquireCount: { w: 2 } }, Collection: { acquireCount: { w: 1 } }, oplog: { acquireCount:  { w: 1 } } } 115ms<br \/>2015-07-31T13:34:55.419 0800 I NETWORK [LockPinger] reconnect 192.168.2.134:28010 (192.168.2.134) failed failed couldn\\\\\\&#8217;t connect to server 192.168.2.134:28010 (192.168.2.134), connection attempt failed<br \/>2015-07-31T13:34:55.556 0800 I COMMAND [conn258] command test.$cmd command: insert { insert: &quot;customer&quot;, documents: [ { _id: 11119.0, name: &quot; test name test name test name test name test name test name test name test name test name end&quot;, address: &quot;address  test customer al;dkjfa;lsdfjsal;#^end&quot;, province: &quot;test customer province&quot;, city: &quot;test customer city&quot; } ], ordered: true, metadata: { shardName: &quot;shard1&quot;, shardVersion: [ Timestamp 4000|1, ObjectId(\\\\\\&#8217;55bb0603bb39501b3b7c2934\\\\\\&#8217;) ], session: 0 } } ntoreturn:1  keyUpdates:0 writeConflicts:0 numYields:0 reslen:140 locks:{ Global: { acquireCount: { w: 2 } }, Database: { acquireCount: { w: 2 } }, Collection: { acquireCount: { w: 1 } }, oplog: { acquireCount: { w: 1 } } } 312ms<br \/>2015-07-31T13:34:55.618 0800 I NETWORK [LockPinger] scoped connection to 192.168.2.188:28010,192.168.2.132:28010,192.168.2.134:28010 not being returned to the pool<br \/>2015-07-31T13:34:55.714 0800 W SHARDING [LockPinger] distributed lock pinger \\\\\\&#8217;192.168.2.188:28010,192.168.2.132:28010,192.168.2.134:28010\/t3:28011:1438320143:660128477\\\\\\&#8217; detected an exception while pinging. :: caused by :: SyncClusterConnection::update  prepare failed: 192.168.2.134:28010 (192.168.2.134) failed:9001 socket exception [CONNECT_ERROR] server [192.168.2.134:28010 (192.168.2.134) failed]<br \/>2015-07-31T13:34:55.773 0800 I COMMAND [conn258] command test.$cmd command: insert { insert: &quot;customer&quot;, documents: [ { _id: 11120.0, name: &quot; test name test name test name test name test name test name test name test name test name end&quot;, address: &quot;address  test customer al;dkjfa;lsdfjsal;#^end&quot;, province: &quot;test customer province&quot;, city: &quot;test customer city&quot; } ], ordered: true, metadata: { shardName: &quot;shard1&quot;, shardVersion: [ Timestamp 4000|1, ObjectId(\\\\\\&#8217;55bb0603bb39501b3b7c2934\\\\\\&#8217;) ], session: 0 } } ntoreturn:1  keyUpdates:0 writeConflicts:0 numYields:0 reslen:140 locks:{ Global: { acquireCount: { w: 2 } }, Database: { acquireCount: { w: 2 } }, Collection: { acquireCount: { w: 1 } }, oplog: { acquireCount: { w: 1 } } } 105ms<br \/>2015-07-31T13:34:56.034 0800 I WRITE [conn258] insert test.customer query: { _id: 11121.0, name: &quot; test name test name test name test name test name test name test name test name test name end&quot;, address: &quot;address test customer al;dkjfa;lsdfjsal;#^end&quot;,  province: &quot;test customer province&quot;, city: &quot;test customer city&quot; } ninserted:1 keyUpdates:0 writeConflicts:0 numYields:0 locks:{ Global: { acquireCount: { w: 2 } }, Database: { acquireCount: { w: 2 } }, Collection: { acquireCount: { w: 1 } }, oplog: { acquireCount:  { w: 1 } } } 114ms<br \/>2015-07-31T13:34:56.161 0800 I COMMAND [conn258] command test.$cmd command: insert { insert: &quot;customer&quot;, documents: [ { _id: 11121.0, name: &quot; test name test name test name test name test name test name test name test name test name end&quot;, address: &quot;address  test customer al;dkjfa;lsdfjsal;#^end&quot;, province: &quot;test customer province&quot;, city: &quot;test customer city&quot; } ], ordered: true, metadata: { shardName: &quot;shard1&quot;, shardVersion: [ Timestamp 4000|1, ObjectId(\\\\\\&#8217;55bb0603bb39501b3b7c2934\\\\\\&#8217;) ], session: 0 } } ntoreturn:1  keyUpdates:0 writeConflicts:0 numYields:0 reslen:140 locks:{ Global: { acquireCount: { w: 2 } }, Database: { acquireCount: { w: 2 } }, Collection: { acquireCount: { w: 1 } }, oplog: { acquireCount: { w: 1 } } } 256ms<br \/>2015-07-31T13:34:56.367 0800 I COMMAND [conn258] command test.$cmd command: insert { insert: &quot;customer&quot;, documents: [ { _id: 11122.0, name: &quot; test name test name test name test name test name test name test name test name test name end&quot;, address: &quot;address  test customer al;dkjfa;lsdfjsal;#^end&quot;, province: &quot;test customer province&quot;, city: &quot;test customer city&quot; } ], ordered: true, metadata: { shardName: &quot;shard1&quot;, shardVersion: [ Timestamp 4000|1, ObjectId(\\\\\\&#8217;55bb0603bb39501b3b7c2934\\\\\\&#8217;) ], session: 0 } } ntoreturn:1  keyUpdates:0 writeConflicts:0 numYields:0 reslen:140 locks:{ Global: { acquireCount: { w: 2 } }, Database: { acquireCount: { w: 2 } }, Collection: { acquireCount: { w: 1 } }, oplog: { acquireCount: { w: 1 } } } 110ms<\/p>\n<p>#\u91cd\u542fconfig \u540e\uff0c\u518d\u767b\u5f55\u4e5f\u51fa\u9519\u3002<br \/>\u53ef\u80fd\u662f\u672c\u673amongos \u5df2\u8bb0\u5f55\u6ca1\u627e\u5230config \uff0c\u540e\u518d\u91cd\u542fmongos \uff0c\u5168\u90e8\u6b63\u5e38\u3002<br \/>\u8fd9\u6709\u70b9\u8bf4\u4e0d\u8fc7\u53bb\u3002<\/p>\n<p>[mongo@localhost bin]$ .\/configd_start.sh <br \/>about to fork child process, waiting until server is ready for connections.<br \/>forked process: 12102<br \/>child process started successfully, parent exiting<br \/>[mongo@localhost bin]$ .\/mongo -port 28000<br \/>MongoDB shell version: 3.0.3<br \/>connecting to: 127.0.0.1:28000\/test<br \/>2015-07-31T13:46:49.324 0800 W NETWORK Failed to connect to 127.0.0.1:28000, reason: errno:111 Connection refused<br \/>2015-07-31T13:46:50.747 0800 E QUERY Error: couldn\\\\\\&#8217;t connect to server 127.0.0.1:28000 (127.0.0.1), connection attempt failed<br \/>at connect (src\/mongo\/shell\/mongo.js:181:14)<br \/>at (connect):1:6 at src\/mongo\/shell\/mongo.js:181<br \/>exception: connect failed<br \/>[mongo@localhost bin]$ ps -ef|grep mongod<br \/>mongo 4062 1 23 11:48 ? 00:27:18 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard1.conf<br \/>mongo 4082 1 8 11:48 ? 00:10:29 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard2.conf<br \/>mongo 4121 1 5 11:49 ? 00:06:56 \/opt\/mongodb3.0.3\/bin\/mongos &#8211;configdb 192.168.2.188:28010,192.168.2.132:28010,192.168.2.134:28010 &#8211;logpath \/opt\/mongodb3.0.3\/logs\/mongos.log &#8211;logappend &#8211;fork<br \/>root 11468 9420 0 13:40 pts\/1 00:00:01 tail -330f \/opt\/mongodb3.0.3\/logs\/shard1.log<br \/>mongo 12102 1 12 13:46 ? 00:00:05 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f configsvr.conf<br \/>mongo 12190 2083 3 13:46 pts\/0 00:00:00 grep mongod<br \/>[mongo@localhost bin]$ kill -9 4121<br \/>[mongo@localhost bin]$ .\/mongos_router.sh <br \/>about to fork child process, waiting until server is ready for connections.<br \/>forked process: 12220<br \/>child process started successfully, parent exiting<br \/>[mongo@localhost bin]$ ps -ef|grep mongod<br \/>mongo 4062 1 23 11:48 ? 00:27:57 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard1.conf<br \/>mongo 4082 1 9 11:48 ? 00:11:09 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f shard2.conf<br \/>root 11468 9420 0 13:40 pts\/1 00:00:01 tail -330f \/opt\/mongodb3.0.3\/logs\/shard1.log<br \/>mongo 12102 1 19 13:46 ? 00:00:31 \/opt\/mongodb3.0.3\/bin\/mongod &#8211;storageEngine wiredTiger -f configsvr.conf<br \/>mongo 12220 1 5 13:47 ? 00:00:04 \/opt\/mongodb3.0.3\/bin\/mongos &#8211;configdb 192.168.2.188:28010,192.168.2.132:28010,192.168.2.134:28010 &#8211;logpath \/opt\/mongodb3.0.3\/logs\/mongos.log &#8211;logappend &#8211;fork<br \/>mongo 12299 2083 3 13:48 pts\/0 00:00:00 grep mongod<br \/>[mongo@localhost bin]$ .\/mongo -port 28000<br \/>MongoDB shell version: 3.0.3<\/p>\n<p>cfg = rs.conf()<br \/>cfg.members[0].priority = 2;<br \/>cfg.members[1].priority = 3;<br \/>cfg.members[2].priority = 1;<br \/>rs.reconfig(cfg);<br \/>\u66f4\u591a\u5173\u4e8e\u4e91\u670d\u52a1\u5668\uff0c<span class='wp_keywordlink'><a href=\"https:\/\/www.kenpai.com\/domain.html\" title=\"\u57df\u540d\u6ce8\u518c\" target=\"_blank\">\u57df\u540d<\/a><\/span>\u6ce8\u518c\uff0c\u865a\u62df\u4e3b\u673a\u7684\u95ee\u9898\uff0c\u8bf7\u8bbf\u95ee<span class='wp_keywordlink'><a href=\"https:\/\/www.kenpai.com\/\" title=\"\u57a6\u6d3e\u79d1\u6280\u5b98\u7f51\" target=\"_blank\">\u57a6\u6d3e\u79d1\u6280<\/a><\/span>\u5b98\u7f51\uff1a<span class='wp_keywordlink'><a href=\"https:\/\/www.kenpai.com\/\" title=\"\u57a6\u6d3e\u79d1\u6280\u5b98\u7f51\" target=\"_blank\">www.kenpai.com<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6d4b\u8bd5\u67b6\u6784\uff1a\u6d4b\u8bd5\u76ee\u7684\uff1a\u6d4b\u8bd5\u4e00\u4e2aconfig server \u670d\u52a1\u5668\u6302\u673a\u540e\uff0c\u96c6\u7fa4\u662f\u5426\u80fd\u8bfb\u5199\u6570\u636e\u3002\u6d4b\u8bd5\u539f\u56e0\uff1a\u4e0a\u5468\u56e0\u4e3a\u5185\u5b58\u5403\u7d27\uff0c\u51c6\u5907\u6dfb\u52a0\u5185\u5b58\u3002\u5728\u67e5\u770b\u670d\u52a1\u5668\u65f6\uff0c\u628a\u4e00<\/p>\n","protected":false},"author":2,"featured_media":446,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3322],"tags":[3903],"class_list":["post-5035","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ktougao","tag-config-server-"],"_links":{"self":[{"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/posts\/5035","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/comments?post=5035"}],"version-history":[{"count":0,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/posts\/5035\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/media\/446"}],"wp:attachment":[{"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/media?parent=5035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/categories?post=5035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kenpai.com\/cms\/wp-json\/wp\/v2\/tags?post=5035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}