{"id":1202,"date":"2024-07-30T21:26:00","date_gmt":"2024-07-30T13:26:00","guid":{"rendered":"http:\/\/blue.yn.cn\/?p=1202"},"modified":"2024-08-14T16:13:50","modified_gmt":"2024-08-14T08:13:50","slug":"elasticsearch%e5%85%a5%e9%97%a8%e4%b8%8e%e9%9b%86%e7%be%a4","status":"publish","type":"post","link":"http:\/\/blue.yn.cn\/?p=1202","title":{"rendered":"elasticsearch\u5165\u95e8\u4e0e\u96c6\u7fa4"},"content":{"rendered":"<h3>es\u57fa\u672c\u6982\u5ff5<\/h3>\n<h4>es\u662f\u4ec0\u4e48<\/h4>\n<p><code>elasticsearch<\/code>\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u3001<code>restful<\/code>\u98ce\u683c\u7684\u641c\u7d22\u548c\u6570\u636e\u5b58\u50a8\u5206\u6790\u5f15\u64ce<\/p>\n<h4>es\u4e3b\u8981\u529f\u80fd<\/h4>\n<p>\u6570\u636e\u5b58\u50a8\u3001\u6570\u636e\u641c\u7d22\u3001\u6570\u636e\u5206\u6790<\/p>\n<h4>es\u76f8\u5173\u672f\u8bed<\/h4>\n<h5>\u6587\u6863document<\/h5>\n<p><code>document<\/code>\u6587\u6863\u5c31\u662f\u7528\u6237\u5b58\u5728<code>es<\/code>\u4e2d\u7684\u4e00\u4e9b\u6570\u636e\uff0c\u5b83\u662f<code>es<\/code>\u4e2d\u5b58\u50a8\u7684\u6700\u5c0f\u5355\u5143\uff08\u7c7b\u4f3c\u4e8e\u8868\u4e2d\u7684\u4e00\u884c\u6570\u636e\uff09\u3002<br \/>\n\u6ce8\u610f\uff1a\u6bcf\u4e2a\u6587\u6863\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684<code>id<\/code>\u8868\u793a\uff0c\u53ef\u4ee5\u81ea\u884c\u6307\u5b9a\uff0c\u5982\u679c\u4e0d\u6307\u5b9a<code>es<\/code>\u4f1a\u81ea\u52a8\u751f\u6210<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722346229755.png\" alt=\"file\" \/><\/p>\n<h5>\u7d22\u5f15index<\/h5>\n<p>\u7d22\u5f15\u5176\u5b9e\u662f\u4e00\u5806\u6587\u6863<code>document<\/code>\u7684\u96c6\u5408\uff08\u7c7b\u4f3c\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u4e2a\u8868\uff09<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722346301756.png\" alt=\"file\" \/><\/p>\n<h5>\u5b57\u6bb5filed<\/h5>\n<p>\u5728<code>es<\/code>\u4e2d\uff0c<code>document<\/code>\u5c31\u662f\u4e00\u4e2a<code>json object<\/code>\uff0c\u4e00\u4e2a<code>json object<\/code>\u5176\u5b9e\u662f\u7531\u591a\u4e2a\u5b57\u6bb5\u7ec4\u6210\u7684\uff0c\u6bcf\u4e2a\u5b57\u6bb5\u5b83\u6709\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722346413954.png\" alt=\"file\" \/><\/p>\n<p>\u5b57\u7b26\u4e32\uff1a<code>text\u3001keyword<\/code><br \/>\n\u6570\u503c\u578b\uff1a<code>long\u3001integer\u3001short\u3001byte\u3001double\u3001float<\/code><br \/>\n\u5e03\u5c14\uff1a<code>boolean<\/code><br \/>\n\u65e5\u671f\uff1a<code>date<\/code><br \/>\n\u4e8c\u8fdb\u5236\uff1a<code>binary<\/code><\/p>\n<p>\u8303\u56f4\u7c7b\u578b\uff1a<code>integer_range,float_range,long_range,double_range,date_range<\/code><\/p>\n<h5>es\u672f\u8bed\u603b\u7ed3<\/h5>\n<p><code>es<\/code>\u7d22\u5f15\u3001\u6587\u6863\u3001\u5b57\u6bb5\u5173\u7cfb\u5c0f\u7ed3\uff1a<br \/>\n\u4e00\u4e2a\u7d22\u5f15\u91cc\u9762\u5b58\u50a8\u4e86\u5f88\u591a\u7684<code>document<\/code>\u6587\u6863\uff0c\u4e00\u4e2a\u6587\u6863\u5c31\u662f\u4e00\u4e2a<code>json object<\/code>\uff0c\u4e00\u4e2a<code>json object<\/code>\u662f\u7531\u591a\u4e2a\u4e0d\u540c\u6216\u76f8\u540c\u7684<code>filed<\/code>\u5b57\u6bb5\u7ec4\u6210\uff1b<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722346709559.png\" alt=\"file\" \/><\/p>\n<h4>es\u64cd\u4f5c\u65b9\u5f0f<\/h4>\n<ul>\n<li>\n<p><code>es<\/code>\u7684\u64cd\u4f5c\u548c\u6211\u4eec\u4f20\u7edf\u7684\u6570\u636e\u5e93\u64cd\u4f5c\u4e0d\u592a\u4e00\u6837\uff0c\u5b83\u662f\u901a\u8fc7<code>restfulapi<\/code>\u65b9\u5f0f\u8fdb\u884c\u64cd\u4f5c\u7684\uff0c\u5176\u5b9e\u672c\u8d28\u4e0a\u5c31\u662f\u901a\u8fc7<code>http<\/code>\u7684\u65b9\u5f0f\u53bb\u53d8\u66f4\u6211\u4eec\u7684\u8d44\u6e90\u72b6\u6001<\/p>\n<ul>\n<li>\u901a\u8fc7<code>uri<\/code>\u6307\u5b9a\u8981\u64cd\u4f5c\u7684\u8d44\u6e90\uff0c\u6bd4\u5982<code>index\u3001document<\/code><\/li>\n<li>\u901a\u8fc7<code>http method<\/code>\u6307\u5b9a\u8981\u64cd\u4f5c\u7684\u65b9\u6cd5\uff1a\u5982<code>get\u3001post\u3001put\u3001delete<\/code><\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5e38\u89c1\u64cd\u4f5c<code>es<\/code>\u7684\u4e24\u79cd\u65b9\u5f0f\uff1a<code>curl\u3001kibana devtools<\/code><\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722346911794.png\" alt=\"file\" \/><\/p>\n<h5>curl\u547d\u4ee4\u64cd\u4f5ces<\/h5>\n<h5>kibana\u64cd\u4f5ces<\/h5>\n<pre><code class=\"language-bash\"># \u5b89\u88c5kibana\nrpm -ivh kibana-7.8.1-x86_64.rpm\n\n# \u914d\u7f6ekibana\ngrep &quot;^[a-Z]&quot; \/etc\/kibana\/kibana.yml\nserver.port: 5601\nserver.host: &quot;0.0.0.0&quot;\nserver.name: &quot;kibana.dot.com&quot;\nelasticsearch.hosts: [&quot;http:\/\/x.x.x.x:9200&quot;]\ni18n.locale: &quot;zh-CN&quot;\n\n# \u542f\u52a8kibana\nsystemctl start kibana\nsystemctl enable kibana<\/code><\/pre>\n<h4>es\u7d22\u5f15api<\/h4>\n<p><code>es<\/code>\u6709\u4e13\u95e8\u7684<code>index api<\/code>\uff0c\u7528\u4e8e\u521b\u5efa\u3001\u66f4\u65b0\u3001\u5220\u9664\u7d22\u5f15\u914d\u7f6e\u7b49<\/p>\n<h5>\u521b\u5efa\u7d22\u5f15<\/h5>\n<p>\u521b\u5efa\u7d22\u5f15<code>api<\/code>\u5982\u4e0b\uff1a<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722433237728.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-bash\"># \u521b\u5efa\u7d22\u5f15\nPUT \/test_index\n\n# \u67e5\u770b\u6240\u6709\u5df2\u5b58\u5728\u7684\u7d22\u5f15\nGET _cat\/indices<\/code><\/pre>\n<h5>\u5220\u9664\u7d22\u5f15<\/h5>\n<p>\u5220\u9664\u7d22\u5f15<code>api<\/code>\u5982\u4e0b<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722433375509.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-bash\"># \u5220\u9664\u7d22\u5f15\nDELETE \/test_index<\/code><\/pre>\n<h4>es\u6587\u6863api<\/h4>\n<p><code>es<\/code>\u4e3a\u7d22\u5f15\u6dfb\u52a0\u6587\u6863\uff0c\u6709\u4e13\u95e8\u7684<code>document api<\/code><\/p>\n<ul>\n<li>\u521b\u5efa\u6587\u6863<br \/>\n\u521b\u5efa\u6587\u6863\uff0c\u9700\u8981\u6307\u5b9a<code>id<\/code><\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722694508753.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-bash\"># \u521b\u5efa\u4e00\u4e2a\u6587\u6863\uff08\u6307\u5b9aID\uff09\nPOST \/test_index\/_doc\/1\n{\n  &quot;username&quot;: &quot;hello&quot;,\n  &quot;age&quot;: 18,\n  &quot;salary&quot;: 100\n}<\/code><\/pre>\n<p>\u521b\u5efa\u6587\u6863\uff0c\u4e0d\u6307\u5b9a<code>id<\/code><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722694668669.png\" alt=\"file\" \/><\/p>\n<ul>\n<li>\u67e5\u8be2\u6587\u6863<br \/>\n\u67e5\u8be2\u6587\u6863\uff0c\u6307\u5b9a\u8981\u67e5\u8be2\u7684\u6587\u6863<code>id<\/code><\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722694786981.png\" alt=\"file\" \/><\/p>\n<p>\u67e5\u8be2\u6587\u6863\uff0c\u641c\u7d22\u6240\u6709\u6587\u6863\uff0c\u7528<code>_search<\/code><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722694981145.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-bash\"># \u67e5\u8be2\u6307\u5b9a\u7684\u5185\u5bb9\nGET \/tencentnginx-access-7.8.1-2024.08.03\/_search\n{\n  &quot;query&quot;: {&quot;match&quot;: {\n    &quot;remote_addr&quot;: &quot;222.217.160.209&quot;\n  }}\n}<\/code><\/pre>\n<ul>\n<li>\u6279\u91cf\u521b\u5efa\u6587\u6863<br \/>\n<code>es<\/code>\u5141\u8bb8\u901a\u8fc7<code>_bulk<\/code>\u4e00\u6b21\u521b\u5efa\u591a\u4e2a\u6587\u6863\uff0c\u4ece\u800c\u51cf\u5c11\u7f51\u7edc\u4f20\u8f93\u5f00\u9500\uff0c\u63d0\u5347\u5199\u5165\u901f\u7387<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722695434270.png\" alt=\"file\" \/><\/p>\n<p><code>es<\/code>\u5141\u8bb8\u901a\u8fc7<code>_mget<\/code>\u4e00\u6b21\u67e5\u8be2\u591a\u4e2a\u6587\u6863<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722695713672.png\" alt=\"file\" \/><\/p>\n<h3>es\u96c6\u7fa4\u5b89\u88c5\u90e8\u7f72<\/h3>\n<h4>es\u96c6\u7fa4\u7684\u597d\u5904<\/h4>\n<ul>\n<li><code>es<\/code>\u5929\u7136\u652f\u6301\u96c6\u7fa4\u6a21\u5f0f\u3001\u5176\u597d\u5904\u4e3b\u8981\u6709\u4e24\u4e2a\uff1a\n<ul>\n<li>1.\u80fd\u591f\u589e\u5927\u7cfb\u7edf\u7684\u5bb9\u91cf\uff0c\u5982\u5185\u5b58\u3001\u78c1\u76d8\uff0c\u4f7f\u5f97<code>es<\/code>\u96c6\u7fa4\u53ef\u4ee5\u652f\u6301<code>pb<\/code>\u7ea7\u7684\u6570\u636e<\/li>\n<li>2.\u80fd\u591f\u63d0\u4f9b\u7cfb\u7edf\u53ef\u7528\u6027\uff0c\u5373\u4f7f\u90e8\u5206\u8282\u70b9\u505c\u6b62\u670d\u52a1\uff0c\u6574\u4e2a\u96c6\u7fa4\u4f9d\u7136\u53ef\u4ee5\u6b63\u5e38\u670d\u52a1<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>es\u5982\u4f55\u7ec4\u5efa\u96c6\u7fa4<\/h4>\n<ul>\n<li>\u5355\u8282\u70b9<code>es<\/code>\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722347238825.png\" alt=\"file\" \/><\/p>\n<ul>\n<li>\u5982\u679c\u5355\u8282\u70b9\u51fa\u73b0\u95ee\u9898\uff0c\u670d\u52a1\u5c31\u4e0d\u53ef\u7528\u4e86\uff0c\u5982\u4f55\u65b0\u589e\u4e00\u4e2a<code>es<\/code>\u8282\u70b9\u52a0\u5165\u96c6\u7fa4<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722347294252.png\" alt=\"file\" \/><\/p>\n<ul>\n<li><code>elasticsearch<\/code>\u96c6\u7fa4\u662f\u7531\u591a\u4e2a\u8282\u70b9\u7ec4\u6210\u7684\uff0c\u901a\u8fc7<code>cluster.name<\/code>\u8bbe\u7f6e\u96c6\u7fa4\u540d\u79f0\uff0c\u5e76\u4e14\u7528\u4e8e\u533a\u5206\u5176\u5b83\u7684\u96c6\u7fa4\uff0c\u6bcf\u4e2a\u8282\u70b9\u901a\u8fc7<code>node.name<\/code>\u6307\u5b9a\u8282\u70b9\u7684\u540d\u79f0<\/li>\n<\/ul>\n<h4>es\u96c6\u7fa4\u73af\u5883\u90e8\u7f72<\/h4>\n<h5>\u73af\u5883\u51c6\u5907<\/h5>\n<table>\n<thead>\n<tr>\n<th>\u4e3b\u673a\u540d\u79f0<\/th>\n<th>ip\u5730\u5740<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>es-node1<\/td>\n<td>192.168.1.11<\/td>\n<\/tr>\n<tr>\n<td>es-node2<\/td>\n<td>192.168.1.12<\/td>\n<\/tr>\n<tr>\n<td>es-node3<\/td>\n<td>192.168.1.13<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h5>\u5b89\u88c5es\u8f6f\u4ef6<\/h5>\n<p>\u6240\u6709\u96c6\u7fa4\u8282\u70b9\u90fd\u9700\u8981\u5b89\u88c5<code>es<\/code>\u8f6f\u4ef6<\/p>\n<pre><code class=\"language-bash\">yum install java\nrpm -ivh elasticsearch-7.8.1-x86_64.rpm<\/code><\/pre>\n<h5>node1\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e<\/h5>\n<pre><code class=\"language-bash\">grep &quot;^[a-Z]&quot; \/etc\/elasticsearch\/elasticsearch.yml\ncluster.name: my-application  # \u96c6\u7fa4\u540d\u79f0\nnode.name: node-1  # \u8282\u70b9\u540d\u79f0\npath.data: \/elkstorage  # \u6570\u636e\u5b58\u50a8\u8def\u5f84\npath.logs: \/var\/log\/elasticsearch  # \u65e5\u5fd7\u5b58\u50a8\u8def\u5f84\nbootstrap.memory_lock: true  # \u4e0d\u4f7f\u7528swap\u5206\u533a\uff08\u9700\u4fee\u6539\u542f\u52a8\u53c2\u6570\uff09\nnetwork.host: 192.168.99.11  #  \u76d1\u63a7\u5728\u672c\u5730\u54ea\u4e2a\u5730\u5740\uff08web\u8bbf\u95ee\u9700\u901a\u8fc7cerebro\uff09\nhttp.port: 9200  # \u76d1\u542c\u7aef\u53e3\ndiscovery.seed_hosts: [&quot;192.168.99.11&quot;, &quot;192.168.99.12&quot;,&quot;192.168.99.13&quot;]  # \u96c6\u7fa4\u4e3b\u673a\u5217\u8868\ncluster.initial_master_nodes: [&quot;192.168.99.11&quot;, &quot;192.168.99.12&quot;,&quot;192.168.99.13&quot;]  # \u4ec5\u7b2c\u4e00\u6b21\u542f\u52a8\u96c6\u7fa4\u65f6\u8fdb\u884c\u9009\u4e3e<\/code><\/pre>\n<h5>node2\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e<\/h5>\n<pre><code class=\"language-bash\">grep &quot;^[a-Z]&quot; \/etc\/elasticsearch\/elasticsearch.yml\ncluster.name: my-application\nnode.name: node-2\npath.data: \/elkstorage\npath.logs: \/var\/log\/elasticsearch\nbootstrap.memory_lock: true\nnetwork.host: 192.168.99.12\nhttp.port: 9200\ndiscovery.seed_hosts: [&quot;192.168.99.11&quot;, &quot;192.168.99.12&quot;,&quot;192.168.99.13&quot;]\ncluster.initial_master_nodes: [&quot;192.168.99.11&quot;, &quot;192.168.99.12&quot;,&quot;192.168.99.13&quot;]<\/code><\/pre>\n<h5>node3\u96c6\u7fa4\u8282\u70b9\u914d\u7f6e<\/h5>\n<pre><code class=\"language-bash\">grep &quot;^[a-Z]&quot; \/etc\/elasticsearch\/elasticsearch.yml\ncluster.name: my-application\nnode.name: node-3\npath.data: \/elkstorage\npath.logs: \/var\/log\/elasticsearch\nbootstrap.memory_lock: true\nnetwork.host: 192.168.99.13\nhttp.port: 9200\ndiscovery.seed_hosts: [&quot;192.168.99.11&quot;, &quot;192.168.99.12&quot;,&quot;192.168.99.13&quot;]\ncluster.initial_master_nodes: [&quot;192.168.99.11&quot;, &quot;192.168.99.12&quot;,&quot;192.168.99.13&quot;]<\/code><\/pre>\n<h3>es\u96c6\u7fa4\u5065\u5eb7\u68c0\u6d4b<\/h3>\n<p><code>cluster health<\/code>\u83b7\u53d6\u96c6\u7fa4\u7684\u5065\u5eb7\u72b6\u6001\uff0c\u6574\u4e2a\u96c6\u7fa4\u72b6\u6001\u5305\u62ec\u4ee5\u4e0b\u4e09\u79cd\uff1a<\/p>\n<ul>\n<li>1.<code>green<\/code>\u5065\u5eb7\u72b6\u6001\uff0c\u6307\u6240\u6709\u4e3b\u526f\u5206\u7247\u90fd\u6b63\u5e38\u5206\u914d<\/li>\n<li>2.<code>yellow<\/code>\u6307\u6240\u6709\u4e3b\u5206\u7247\u90fd\u6b63\u5e38\u5206\u914d\uff0c\u4f46\u662f\u6709\u526f\u672c\u5206\u7247\u672a\u6b63\u5e38\u5206\u914d<\/li>\n<li>3.<code>red<\/code>\u6709\u4e3b\u5206\u7247\u672a\u5206\u914d\uff0c\u8868\u793a\u7d22\u5f15\u4e0d\u5b8c\u5907\uff0c\u5199\u53ef\u80fd\u6709\u95ee\u9898\u3002\uff08\u4f46\u4e0d\u4ee3\u8868\u4e0d\u80fd\u5b58\u50a8\u6570\u636e\u548c\u8bfb\u53d6\u6570\u636e\uff09<\/li>\n<\/ul>\n<p>\u68c0\u67e5<code>es<\/code>\u96c6\u7fa4\u662f\u5426\u6b63\u5e38\u8fd0\u884c\uff0c\u53ef\u4ee5\u901a\u8fc7<code>curl\u3001cerebro<\/code>\u4e24\u79cd\u65b9\u5f0f\uff1b<\/p>\n<h4>curl\u547d\u4ee4\u68c0\u67e5\u96c6\u7fa4\u72b6\u6001<\/h4>\n<pre><code class=\"language-bash\"># \u901a\u8fc7curl\u68c0\u67e5es\u96c6\u7fa4\u72b6\u6001\ncurl http:\/\/192.168.99.11:9200\/_cluster\/health?pretty=true\n{\n  &quot;cluster_name&quot; : &quot;my-application&quot;,\n  &quot;status&quot; : &quot;green&quot;,\n  &quot;timed_out&quot; : false,\n  &quot;number_of_nodes&quot; : 3,\n  &quot;number_of_data_nodes&quot; : 3,\n  &quot;active_primary_shards&quot; : 20,\n  &quot;active_shards&quot; : 40,\n  &quot;relocating_shards&quot; : 0,\n  &quot;initializing_shards&quot; : 0,\n  &quot;unassigned_shards&quot; : 0,\n  &quot;delayed_unassigned_shards&quot; : 0,\n  &quot;number_of_pending_tasks&quot; : 0,\n  &quot;number_of_in_flight_fetch&quot; : 0,\n  &quot;task_max_waiting_in_queue_millis&quot; : 0,\n  &quot;active_shards_percent_as_number&quot; : 100.0\n}\n\n# \u76d1\u63a7es\u96c6\u7fa4\u72b6\u6001\u811a\u672c\ncurl -s http:\/\/192.168.99.11:9200\/_cluster\/health?pretty=true | grep &quot;status&quot; | awk -F &#039;&quot;&#039; &#039;{print $4}&#039;\ngreen<\/code><\/pre>\n<h4>cerebro\u68c0\u67e5\u96c6\u7fa4\u72b6\u6001<\/h4>\n<p>\u53ef\u89c6\u5316<code>cerebro<\/code>\u5de5\u5177\u68c0\u67e5<code>es<\/code>\u96c6\u7fa4\u72b6\u6001<\/p>\n<pre><code class=\"language-bash\">rpm -ivh cerebro-0.9.4-1.noarch.rpm\n\nvim \/etc\/cerebro\/application.conf\n# Path of local database file\ndata.path: &quot;\/var\/lib\/cerebro\/cerebro.db&quot;\n#data.path = &quot;.\/cerebro.db&quot;\n\nsystemctl enable cerebro.service\nsystemctl start cerebro.service\n\nnetstat -lntp\ntcp6       0      0 :::9000                 :::*                    LISTEN      3149\/java<\/code><\/pre>\n<p>\u96c6\u7fa4\u68c0\u67e5\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<br \/>\n<img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722727848576.png\" alt=\"file\" \/><\/p>\n<h3>es\u96c6\u7fa4\u8282\u70b9\u7c7b\u578b<\/h3>\n<ul>\n<li><code>es<\/code>\u96c6\u7fa4\u4e2d\u8282\u70b9\u7c7b\u578b\u4ecb\u7ecd\n<ul>\n<li><code>cluster state<\/code><\/li>\n<li><code>master<\/code><\/li>\n<li><code>data<\/code><\/li>\n<li><code>coordinating<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>cluster state<\/h4>\n<ul>\n<li><code>cluster state<\/code>\uff1a\u96c6\u7fa4\u76f8\u5173\u7684\u6570\u636e\u79f0\u4e3a<code>cluster state<\/code>\uff1b\u4f1a\u5b58\u50a8\u5728\u6bcf\u4e2a\u8282\u70b9\u4e2d\uff0c\u4e3b\u8981\u6709\u5982\u4e0b\u4fe1\u606f\uff1a\n<ul>\n<li>1.\u8282\u70b9\u4fe1\u606f\uff0c\u6bd4\u5982\u8282\u70b9\u540d\u79f0\u3001\u8282\u70b9\u8fde\u63a5\u5730\u5740\u7b49<\/li>\n<li>2.\u7d22\u5f15\u4fe1\u606f\uff0c\u6bd4\u5982\u7d22\u5f15\u540d\u79f0\u3001\u7d22\u5f15\u914d\u7f6e\u4fe1\u606f\u7b49<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>master<\/h4>\n<ul>\n<li>1.<code>es<\/code>\u96c6\u7fa4\u4e2d\u53ea\u80fd\u6709\u4e00\u4e2a<code>master<\/code>\u8282\u70b9\uff0c<code>master<\/code>\u8282\u70b9\u7528\u4e8e\u63a7\u5236\u6574\u4e2a\u96c6\u7fa4\u7684\u64cd\u4f5c\uff1b<\/li>\n<li>2.<code>master<\/code>\u4e3b\u8981\u7ef4\u62a4<code>cluster state<\/code>\uff0c\u5f53\u6709\u65b0\u6570\u636e\u4ea7\u751f\u540e\uff0c<code>master<\/code>\u4f1a\u5c06\u6570\u636e\u540c\u6b65\u7ed9\u5176\u4ed6<code>node<\/code>\u8282\u70b9\uff1b<\/li>\n<li>3.<code>master<\/code>\u8282\u70b9\u662f\u901a\u8fc7\u9009\u4e3e\u4ea7\u751f\u7684\uff0c\u53ef\u4ee5\u901a\u8fc7<code>node.master:true<\/code>\u6307\u5b9a\u4e3a<code>master<\/code>\u8282\u70b9\u3002\uff08\u9ed8\u8ba4\u4e3a<code>true<\/code>\uff09<\/li>\n<\/ul>\n<p>\u5f53\u6211\u4eec\u901a\u8fc7<code>api<\/code>\u521b\u5efa\u7d22\u5f15<code>PUT \/test_index<\/code>\uff0c<code>cluster state<\/code>\u5219\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u7531<code>master<\/code>\u540c\u6b65\u81f3\u5176\u4ed6<code>node<\/code>\u8282\u70b9\uff1b<\/p>\n<h4>data<\/h4>\n<ol>\n<li>\u5b58\u50a8\u6570\u636e\u7684\u8282\u70b9\u5373\u4e3a<code>data<\/code>\u8282\u70b9\uff0c\u9ed8\u8ba4\u8282\u70b9\u90fd\u662f<code>data<\/code>\u7d2f\u5fc3\uff0c\u914d\u7f6e<code>node.data:true<\/code>\uff08\u9ed8\u8ba4\u4e3a<code>true<\/code>\uff09<\/li>\n<li>\u5f53\u521b\u5efa\u7d22\u5f15\u540e\uff0c\u7d22\u5f15\u521b\u5efa\u7684\u6570\u636e\u4f1a\u5b58\u50a8\u81f3\u67d0\u4e2a\u8282\u70b9\uff0c\u80fd\u591f\u5b58\u50a8\u6570\u636e\u7684\u8282\u70b9\uff0c\u79f0\u4e3a<code>data<\/code>\u8282\u70b9\u3002<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722735051719.png\" alt=\"file\" \/><\/p>\n<h4>coordinating<\/h4>\n<ol>\n<li>\u5904\u7406\u8bf7\u6c42\u7684\u8282\u70b9\u5373\u4e3a<code>coordinating<\/code>\u8282\u70b9\uff0c\u8be5\u8282\u70b9\u4e3a\u6240\u6709\u8282\u70b9\u7684\u9ed8\u8ba4\u89d2\u8272\uff0c\u4e0d\u80fd\u53d6\u6d88<\/li>\n<li><code>coordinating<\/code>\u8282\u70b9\u4e3b\u8981\u5c06\u8bf7\u6c42\u8def\u7531\u5230\u6b63\u786e\u7684\u8282\u70b9\u5904\u7406\u3002\u6bd4\u5982\u521b\u5efa\u6240\u4ee5\u7684\u8bf7\u6c42\u4f1a\u7531<code>coordinating<\/code>\u8def\u7531\u5230<code>master<\/code>\u8282\u70b9\u5904\u7406\uff1b\u5f53\u914d\u7f6e<code>node.master:false\u3001node.data:false<\/code>\u5219\u53ea\u4f5c\u4e3a<code>coordinating<\/code>\u8282\u70b9<\/li>\n<\/ol>\n<h4>master-eligible node<\/h4>\n<p>\u5728\u521d\u59cb\u5316\u65f6\u6709\u8d44\u683c\u9009\u4e3e\u7684\u8282\u70b9\uff0c\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u5b9a\u4e49<br \/>\n<code>cluster.initial_master_nodes:<\/code><\/p>\n<h3>es\u96c6\u7fa4\u5206\u7247\u526f\u672c<\/h3>\n<h4>\u63d0\u9ad8es\u96c6\u7fa4\u53ef\u7528\u6027<\/h4>\n<ul>\n<li>\u5982\u4f55\u63d0\u9ad8es\u96c6\u7fa4\u7cfb\u7edf\u7684\u53ef\u7528\u6027\uff0c\u7531\u5982\u4e0b\u4e24\u4e2a\u65b9\u9762\uff1a\n<ul>\n<li>1.\u670d\u52a1\u53ef\u7528\u6027\uff1a2\u4e2a\u8282\u70b9\u7684\u60c5\u51b5\u4e0b\uff0c\u5141\u8bb8\u5176\u4e2d1\u4e2a\u8282\u70b9\u505c\u6b62\u670d\u52a1\uff1b\u591a\u4e2a\u8282\u70b9\u7684\u60c5\u51b5\u4e0b\uff0c\u574f\u7684\u8282\u70b9\u4e0d\u80fd\u8d85\u8fc7\u96c6\u7fa4\u4e00\u534a\u4ee5\u4e0a<\/li>\n<li>2.\u6570\u636e\u53ef\u7528\u6027\uff1a\u901a\u8fc7\u526f\u672c<code>replication<\/code>\u89e3\u51b3\uff0c\u8fd9\u6837\u6bcf\u4e2a\u8282\u70b9\u90fd\u6709\u5b8c\u5907\u7684\u6570\u636e\uff1b\u5982\u4e0b\u6240\u793a\uff0c<code>node2<\/code>\u662f<code>oldxu_index<\/code>\u7d22\u5f15\u7684\u4e00\u4e2a\u5b8c\u6574\u526f\u672c\u6570\u636e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722736126228.png\" alt=\"file\" \/><\/p>\n<h4>\u589e\u5927es\u96c6\u7fa4\u7684\u5bb9\u91cf<\/h4>\n<ul>\n<li>\n<p>\u5982\u4f55\u589e\u5927<code>es<\/code>\u96c6\u7fa4\u7cfb\u7edf\u7684\u5bb9\u91cf\uff1b\u6211\u4eec\u9700\u8981\u9879\u529e\u6cd5\u5c06\u6570\u636e\u5747\u5300\u5206\u5e03\u5728\u6240\u6709\u8282\u70b9\u4e0a\uff1b<\/p>\n<ul>\n<li>\u5f15\u5165\u5206\u7247<code>shard<\/code>\u89e3\u51b3<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4ec0\u4e48\u662f\u5206\u7247\uff0c\u5c06\u4e00\u4efd\u5b8c\u6574\u6570\u636e\u5206\u6563\u4e3a\u591a\u4e2a\u5206\u7247\u5b58\u50a8<\/p>\n<ul>\n<li>\u5206\u7247\u662f<code>es<\/code>\u652f\u6301<code>pb<\/code>\u7ea7\u6570\u636e\u7684\u57fa\u77f3<\/li>\n<li>\u5206\u7247\u5b58\u50a8\u4e86\u7d22\u5f15\u7684\u90e8\u5206\u6570\u636e\uff0c\u53ef\u4ee5\u5206\u5e03\u5728\u4efb\u610f\u8282\u70b9\u4e0a<\/li>\n<li>\u5206\u7247\u5b58\u5728\u4e3b\u5206\u7247\u548c\u526f\u672c\u5206\u7247\u4e4b\u5206\uff0c\u526f\u672c\u5206\u7247\u4e3b\u8981\u7528\u6765\u5b9e\u73b0\u6570\u636e\u7684\u9ad8\u53ef\u7528<\/li>\n<li>\u526f\u672c\u5206\u7247\u7684\u6570\u636e\u7531\u4e3b\u5206\u7247\u540c\u6b65\uff0c\u53ef\u4ee5\u6709\u591a\u4e2a\uff0c\u7528\u6765\u63d0\u9ad8\u8bfb\u53d6\u6570\u636e\u6027\u80fd\u7684<\/li>\n<li>\u6ce8\u610f\uff1a\u4e3b\u5206\u7247\u6570\u5728\u7d22\u5f15\u521b\u5efa\u65f6\u6307\u5b9a\u4e14\u540e\u7eed\u4e0d\u5141\u8bb8\u5728\u66f4\u6539\uff1b\u9ed8\u8ba4<code>es<\/code>\u5206\u7247\u6570\u4e3a1\u4e2a<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff1a\u57283\u4e2a\u8282\u70b9\u7684\u96c6\u7fa4\u4e2d\u521b\u5efa<code>oldxu_index<\/code>\u7d22\u5f15\uff0c\u6307\u5b9a3\u4e2a\u5206\u7247\uff0c\u548c1\u4e2a\u526f\u672c\uff1b<\/p>\n<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722737441247.png\" alt=\"file\" \/><\/p>\n<pre><code class=\"language-bash\"># \u521b\u5efa\u7d22\u5f15\uff0c\u8bbe\u5b9a\u4e3b\u5206\u7247\u6570\u91cf\u548c\u526f\u672c\u6570\u91cf\nPUT \/test_index\n{\n  &quot;settings&quot;: {\n    &quot;number_of_shards&quot;: 3,\n    &quot;number_of_replicas&quot;: 1\n    }\n}\n\n# \u52a8\u6001\u4fee\u6539\u526f\u672c\u6570\u91cf\nPUT \/test_index\/_settings\n{\n  &quot;number_of_replicas&quot;: 2\n}<\/code><\/pre>\n<h4>\u589e\u52a0\u8282\u70b9\u80fd\u5426\u63d0\u9ad8\u5bb9\u91cf<\/h4>\n<p>\u95ee\u9898\uff1a\u76ee\u524d\u4e00\u5171\u67093\u4e2a<code>es<\/code>\u8282\u70b9\uff0c\u5982\u679c\u6b64\u65f6\u589e\u52a0\u4e00\u4e2a\u65b0\u8282\u70b9\u80fd\u5426\u63d0\u9ad8<code>oldxu_index<\/code>\u7d22\u5f15\u6570\u636e\u5bb9\u91cf<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722738088367.png\" alt=\"file\" \/><\/p>\n<p>\u7b54\u6848\uff1a\u4e0d\u80fd\uff0c\u56e0\u4e3a<code>oldxu_index<\/code>\u53ea\u67093\u4e2a\u5206\u7247\uff0c\u5df2\u7ecf\u5206\u5e03\u57283\u53f0\u8282\u70b9\u4e0a\uff0c\u90a3\u4e48\u65b0\u589e\u7684\u7b2c\u56db\u4e2a\u8282\u70b9\u5bf9\u4e8e<code>oldxu_index<\/code>\u800c\u8a00\u662f\u65e0\u6cd5\u4f7f\u7528\u5230\u7684\u3002\u6240\u4ee5\u4e5f\u65e0\u6cd5\u5e26\u6765\u6570\u636e\u5bb9\u91cf\u7684\u63d0\u5347<\/p>\n<h4>\u589e\u52a0\u526f\u672c\u80fd\u5426\u63d0\u9ad8\u8bfb\u6027\u80fd<\/h4>\n<p>\u95ee\u9898\uff1a\u76ee\u524d\u4e00\u5171\u67093\u4e2a<code>es<\/code>\u8282\u70b9\uff0c\u5982\u679c\u589e\u52a0\u526f\u672c\u6570\u91cf\u662f\u5426\u80fd\u63d0\u9ad8<code>oldxu_index<\/code>\u7684\u8bfb\u541e\u5410\u91cf<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722738100809.png\" alt=\"file\" \/><\/p>\n<p>\u7b54\u6848\uff1a\u4e0d\u80fd\uff0c\u56e0\u4e3a\u65b0\u589e\u7684\u526f\u672c\u8fd8\u662f\u4f1a\u5206\u5e03\u5728<code>node1\u3001node2\u3001node3<\/code>\u8fd9\u4e09\u4e2a\u8282\u70b9\u4e0a\uff0c\u8fd8\u662f\u4f7f\u7528\u4e86\u76f8\u540c\u7684\u8d44\u6e90\uff0c\u4e5f\u5c31\u610f\u5473\u7740\u6709\u8bfb\u8bf7\u6c42\u6765\u65f6\uff0c\u8fd9\u4e9b\u8bf7\u6c42\u8fd8\u662f\u4f1a\u5206\u914d\u5230<code>node1\u3001node2\u3001node3<\/code>\u4e0a\u8fdb\u884c\u5904\u7406\uff0c\u4e5f\u5c31\u610f\u5473\u7740\uff0c\u8fd8\u662f\u5229\u7528\u4e86\u76f8\u540c\u7684\u786c\u4ef6\u8d44\u6e90\uff0c\u6240\u4ee5\u4e0d\u4f1a\u63d0\u5347\u8bfb\u6027\u80fd\u3002<\/p>\n<h4>\u526f\u672c\u4e0e\u5206\u7247\u603b\u7ed3<\/h4>\n<ul>\n<li>\u5206\u7247\u6570\u91cf\u548c\u526f\u672c\u6570\u91cf\u7684\u8bbe\u5b9a\u5f88\u91cd\u8981\uff0c\u9700\u8981\u63d0\u524d\u89c4\u5212\u597d\n<ul>\n<li>\u8fc7\u5c0f\u4f1a\u5bfc\u81f4\u540e\u7eed\u65e0\u6cd5\u901a\u8fc7\u589e\u52a0\u8282\u70b9\u5b9e\u73b0\u6c34\u5e73\u6269\u5bb9\uff1b<\/li>\n<li>\u8bbe\u7f6e\u5206\u7247\u8fc7\u5927\u4f1a\u5bfc\u81f4\u4e00\u4e2a\u8282\u70b9\u4e0a\u5206\u5e03\u8fc7\u591a\u7684\u5206\u7247\uff0c\u9020\u6210\u8d44\u6e90\u6d6a\u8d39\u3002\u5206\u7247\u8fc7\u591a\u4e5f\u4f1a\u5f71\u54cd\u67e5\u8be2\u6027\u80fd\uff1b<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>es\u96c6\u7fa4\u6545\u969c\u8f6c\u79fb<\/h3>\n<h4>\u4ec0\u4e48\u662f\u6545\u969c\u8f6c\u79fb<\/h4>\n<p>\u6240\u8c13\u6545\u969c\u8f6c\u79fb\u6307\u7684\u662f\uff0c\u5f53\u96c6\u7fa4\u4e2d\u6709\u8282\u70b9\u53d1\u751f\u6545\u969c\u65f6\uff0c\u8fd9\u4e2a\u96c6\u7fa4\u662f\u5982\u4f55\u8fdb\u884c\u81ea\u52a8\u4fee\u590d\u7684\u3002<br \/>\n<code>es<\/code>\u96c6\u7fa4\u76ee\u524d\u662f\u75313\u4e2a\u8282\u70b9\u7ec4\u6210\uff0c\u5982\u4e0b\u6240\u793a\uff0c\u6b64\u65f6\u96c6\u7fa4\u72b6\u6001\u662f<code>green<\/code><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722739664236.png\" alt=\"file\" \/><\/p>\n<h4>\u6a21\u62df\u8282\u70b9\u6545\u969c<\/h4>\n<ul>\n<li>\u5047\u8bbe\uff1a<code>node1<\/code>\u6240\u5728\u673a\u5668\u5b95\u673a\u5bfc\u81f4\u670d\u52a1\u7ec8\u6b62\uff0c\u6b64\u65f6\u96c6\u7fa4\u4f1a\u5982\u4f55\u5904\u7406\uff1b\u5927\u4f53\u5206\u4e3a\u4e09\u4e2a\u6b65\u9aa4\uff1a\n<ul>\n<li>1.\u91cd\u65b0\u9009\u4e3e<\/li>\n<li>2.\u4e3b\u5206\u7247\u8c03\u6574<\/li>\n<li>3.\u526f\u5206\u7247\u8c03\u6574<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h5>\u91cd\u65b0\u9009\u4e3e<\/h5>\n<p><code>node2<\/code>\u548c<code>node3<\/code>\u53d1\u73b0<code>node1<\/code>\u65e0\u6cd5\u54cd\u5e94\uff1b\u4e00\u6bb5\u65f6\u95f4\u540e\u4f1a\u53d1\u8d77<code>master<\/code>\u9009\u4e3e\uff0c\u6bd4\u5982\u8fd9\u91cc\u9009\u62e9<code>node2<\/code>\u4e3a<code>master<\/code>\u8282\u70b9\uff0c\u6b64\u65f6\u96c6\u7fa4\u72b6\u6001\u53d8\u4e3a<code>red<\/code>\u72b6\u6001<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722739651977.png\" alt=\"file\" \/><\/p>\n<h5>\u4e3b\u5206\u7247\u8c03\u6574<\/h5>\n<p><code>node<\/code>\u53d1\u73b0\u4e3b\u5206\u7247<code>p0<\/code>\u672a\u5206\u914d\uff0c\u5c06<code>node3<\/code>\u4e0a\u7684<code>r0<\/code>\u63d0\u5347\u4e3a\u4e3b\u5206\u7247\uff1b\u6b64\u65f6\u6240\u6709\u7684\u4e3b\u5206\u7247\u90fd\u6b63\u5e38\u5206\u914d\uff0c\u96c6\u7fa4\u72b6\u6001\u53d8\u4e3a<code>yellow<\/code>\u72b6\u6001\uff1b<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722739636330.png\" alt=\"file\" \/><\/p>\n<h4>\u526f\u672c\u5206\u7247\u8c03\u6574<\/h4>\n<p><code>node2<\/code>\u5c06<code>p0<\/code>\u548c<code>p1<\/code>\u4e3b\u5206\u7247\u91cd\u65b0\u751f\u6210\u65b0\u7684\u526f\u672c\u5206\u7247<code>r0\u3001r1<\/code>\uff0c\u6b64\u65f6\u96c6\u7fa4\u72b6\u6001\u53d8\u4e3a<code>green<\/code><\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722739625120.png\" alt=\"file\" \/><\/p>\n<h3>es\u6587\u6863\u8def\u7531\u539f\u7406<\/h3>\n<p><code>es<\/code>\u6587\u6863\u5206\u5e03\u5f0f\u5b58\u50a8\uff0c\u5f53\u4e00\u4e2a\u6587\u6863\u5b58\u50a8\u81f3<code>es<\/code>\u96c6\u7fa4\u65f6\uff0c\u5b58\u50a8\u7684\u539f\u7406\u662f\u4ec0\u4e48\u6837\u7684\uff1f<br \/>\n\u5982\u4e0b\u6240\u793a\uff0c\u5f53\u6211\u4eec\u60f3\u4e00\u4e2a\u96c6\u7fa4\u4fdd\u5b58\u6587\u6863\u65f6\uff0c<code>document1<\/code>\u662f\u5982\u4f55\u5b58\u50a8\u5230\u5206\u7247<code>p1<\/code>\u7684\uff1f\u9009\u62e9<code>p1<\/code>\u7684\u4f9d\u636e\u662f\u4ec0\u4e48\uff1f<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722740276206.png\" alt=\"file\" \/><\/p>\n<p>\u5176\u5b9e\u662f\u6709\u4e00\u4e2a\u6587\u6863\u5230\u5206\u7247\u7684\u6620\u5c04\u7b97\u6cd5\uff0c\u5176\u76ee\u7684\u662f\u4f7f\u6240\u6709\u6587\u6863\u5747\u5300\u5206\u5e03\u5728\u6240\u6709\u7684\u5206\u7247\u4e0a\uff0c\u90a3\u4e48\u662f\u4ec0\u4e48\u7b97\u6cd5\u5462\uff1f<br \/>\n\u968f\u673a\u8fd8\u662f\u8f6e\u8be2\uff1f\u8fd9\u79cd\u662f\u4e0d\u53ef\u53d6\u7684\uff0c\u56e0\u4e3a\u6570\u636e\u5b58\u50a8\u540e\uff0c\u8fd8\u9700\u8981\u8bfb\u53d6\uff0c\u90a3\u8fd9\u6837\u7684\u8bdd\u5982\u4f55\u8bfb\u53d6\u5462\uff1f<br \/>\n\u5b9e\u9645\u4e0a\uff0c\u5728<code>es<\/code>\u4e2d\uff0c\u901a\u8fc7\u5982\u4e0b\u7684\u516c\u5f0f\u8ba1\u7b97\u6587\u6863\u5bf9\u5e94\u7684\u5206\u7247\u5b58\u50a8\u5230\u54ea\u4e2a\u8282\u70b9\uff0c\u8ba1\u7b97\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-bash\">shard = hash(routing) % number_of_primary_shards\n# hash \u7b97\u6cd5\u4fdd\u8bc1\u5c06\u6570\u636e\u5747\u5300\u5206\u6563\u5728\u5206\u7247\u4e2d\n# routing \u662f\u4e00\u4e2a\u5173\u952e\u53c2\u6570\uff0c\u9ed8\u8ba4\u662f\u6587\u6863id\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5b9a\u4e49\n# number_of_primary_shards \u4e3b\u5206\u7247\u6570\u91cf\n\n# \u6ce8\u610f\uff1a\u8be5\u7b97\u6cd5\u4e0e\u4e3b\u5206\u7247\u6570\u91cf\u76f8\u5173\uff0c\u4e00\u65e6\u786e\u5b9a\u540e\u4fbf\u4e0d\u80fd\u66f4\u6539\u4e3b\u5206\u7247\u6570\u91cf\n# \u56e0\u4e3a\u4e00\u65e6\u4fee\u6539\u4e3b\u5206\u7247\u6570\u91cf\u540e\uff0cshard\u7684\u8ba1\u7b97\u7ed3\u679c\u5c31\u5b8c\u5168\u548c\u4fee\u6539\u524d\u7684\u5b8c\u5168\u4e0d\u4e00\u6837\u4e86<\/code><\/pre>\n<h4>\u6587\u6863\u7684\u521b\u5efa\u6d41\u7a0b<\/h4>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722740638287.png\" alt=\"file\" \/><\/p>\n<h4>\u6587\u6863\u7684\u8bfb\u53d6\u6d41\u7a0b<\/h4>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722740545153.png\" alt=\"file\" \/><\/p>\n<h4>\u6587\u6863\u6279\u91cf\u521b\u5efa\u7684\u6d41\u7a0b<\/h4>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722740530945.png\" alt=\"file\" \/><\/p>\n<h4>\u6587\u6863\u6279\u91cf\u8bfb\u53d6\u7684\u6d41\u7a0b<\/h4>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/07\/image-1722740513745.png\" alt=\"file\" \/><\/p>\n<h3>es\u6269\u5c55\u96c6\u7fa4\u8282\u70b9<\/h3>\n<h4>\u8282\u70b9\u6269\u5c55\u73af\u5883\u51c6\u5907<\/h4>\n<table>\n<thead>\n<tr>\n<th>\u4e3b\u673a\u540d\u79f0<\/th>\n<th>ip\u5730\u5740<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>es-node4<\/td>\n<td>192.168.99.14<\/td>\n<\/tr>\n<tr>\n<td>es-node5<\/td>\n<td>192.168.99.15<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>\u8282\u70b9\u6269\u5c55\u914d\u7f6e<\/h4>\n<pre><code class=\"language-bash\">grep &quot;^[a-Z]&quot; \/etc\/elasticsearch\/elasticsearch.yml\ncluster.name: my-application\nnode.name: node-4\npath.data: \/elkstorage\npath.logs: \/var\/log\/elasticsearch\nbootstrap.memory_lock: true\nnetwork.host: 192.168.99.14\nhttp.port: 9200\ndiscovery.seed_hosts: [&quot;192.168.99.11&quot;, &quot;192.168.99.12&quot;,&quot;192.168.99.13&quot;]\nnode.data: true  # data\u8282\u70b9\nnode.master: false # \u4e0d\u53c2\u4e0emaster\u9009\u4e3e<\/code><\/pre>\n<pre><code class=\"language-bash\">grep &quot;^[a-Z]&quot; \/etc\/elasticsearch\/elasticsearch.yml\ncluster.name: my-application\nnode.name: node-5\npath.data: \/elkstorage\npath.logs: \/var\/log\/elasticsearch\nbootstrap.memory_lock: true\nnetwork.host: 192.168.99.15\nhttp.port: 9200\ndiscovery.seed_hosts: [&quot;192.168.99.11&quot;, &quot;192.168.99.12&quot;,&quot;192.168.99.13&quot;]\nnode.data: true  # data\u8282\u70b9\nnode.master: false # \u4e0d\u53c2\u4e0emaster\u9009\u4e3e<\/code><\/pre>\n<h4>\u8282\u70b9\u6269\u5c55\u68c0\u67e5<\/h4>\n<p>\u901a\u8fc7<code>cerebro<\/code>\u68c0\u67e5\u96c6\u7fa4\u6269\u5c55\u540e\u7684\u72b6\u6001\uff1b\u5982\u679c\u51fa\u73b0\u96c6\u7fa4\u65e0\u6cd5\u52a0\u5165\u3001\u6216\u8005\u96c6\u7fa4\u88ab\u62d2\u7edd<br \/>\n\u5c1d\u8bd5\u5220\u9664<code>\/var\/lib\/elasticsearch<\/code>\u4e0b\u7684\u6587\u4ef6\uff0c\u7136\u540e\u91cd\u542f<code>es<\/code><\/p>\n<p>\u5982\u679c\u8981\u5c06<code>data<\/code>\u8282\u70b9\u4fee\u6539\u4e3a<code>coordinating<\/code>\u8282\u70b9\uff1b\u9700\u8981\u6e05\u7406\u6570\u636e\uff0c\u5426\u6b63\u65e0\u6cd5\u542f\u52a8<\/p>\n<pre><code class=\"language-bash\"># repurpose \u91cd\u65b0\u8c03\u6574\n\/usr\/share\/elasticsearch\/bin\/elasticsearch-node repurpos<\/code><\/pre>\n<h3>es\u96c6\u7fa4\u8c03\u4f18\u5efa\u8bae<\/h3>\n<h4>\u5185\u6838\u53c2\u6570\u4f18\u5316<\/h4>\n<pre><code class=\"language-bash\"># \u5bf9\u4e8e\u64cd\u4f5c\u7cfb\u7edf\uff0c\u9700\u8981\u8c03\u6574\u51e0\u4e2a\u5185\u6838\u53c2\u6570\nvim \/etc\/sysctl.conf\nfs.file-max = 655360  # \u8bbe\u5b9a\u7cfb\u7edf\u6700\u5927\u6253\u5f00\u6587\u4ef6\u63cf\u8ff0\u7b26\u6570\uff0c\u5efa\u8bae\u4fee\u6539655360\u6216\u8005\u66f4\u9ad8\nvm.max_map_count = 262144  #\u7528\u4e8e\u9650\u5236\u4e00\u4e2a\u8fdb\u7a0b\u53ef\u4ee5\u62e5\u6709\u7684\u865a\u62df\u5185\u5b58\u5927\u5c0f\uff0c\u5efa\u8bae\u4fee\u6539\u6210262144\u6216\u8005\u66f4\u9ad8\nnet.core.somaxconn = 32768\nnet.ipv4.tcp_tw_reuse = 1\nnet.ipv4.ip_local_port_range = 1000 65535\nnet.ipv4.tcp_max_tw_buckets = 400000\nsysctl -p\n\n# \u8c03\u6574\u6700\u5927\u7528\u6237\u8fdb\u7a0b\u6570\uff08nproc\uff09\uff0c\u8c03\u6574\u8fdb\u7a0b\u6700\u5927\u6253\u5f00\u6587\u4ef6\u63cf\u8ff0\u7b26\uff08nofile\uff09\nrm -f \/etc\/security\/limits.d\/20-nproc.conf  # \u5220\u9664\u9ed8\u8ba4nproc\u8bbe\u5b9a\u6587\u4ef6\nvim \/etc\/security\/limits.conf\n*       soft    nproc   20480\n*       hard    nproc   20480\n*       soft    nofile  65536\n*       hard    nofile  65536<\/code><\/pre>\n<h4>\u914d\u7f6e\u53c2\u6570\u4f18\u5316<\/h4>\n<pre><code class=\"language-bash\"># \u9501\u5b9a\u7269\u7406\u5185\u5b58\u5730\u5740\uff0c\u907f\u514des\u4f7f\u7528swap\u4ea4\u6362\u5206\u533a\uff0c\u9891\u7e41\u7684\u4ea4\u6362\uff0c\u4f1a\u5bfc\u81f4iops\u53d8\u9ad8\nvim \/etc\/elasticsearch\/elasticsearch.yml\nbootstrap.memory_lock: true\n\n# \u914d\u7f6eelasticsearch\u542f\u52a8\u53c2\u6570\nvim \/usr\/lib\/systemd\/system\/elasticsearch.service\n\u5728[Service]\u4e0b\u52a0\u591a\u4e00\u884c\nLimitMEMLOCK=infinity\n\nsed -i &#039;\/\\[Service\\]\/a LimitMEMLOCK=infinity&#039; \/usr\/lib\/systemd\/system\/elasticsearch.service\n\nsystemctl daemon-reload\nsystemctl restart elasticsearch.service<\/code><\/pre>\n<h4>jvm\u53c2\u6570\u4f18\u5316<\/h4>\n<p><code>jvm<\/code>\u5185\u5b58\u5177\u4f53\u8981\u6839\u636e<code>node<\/code>\u5b58\u50a8\u7684\u6570\u636e\u91cf\u6765\u4f30\u7b97\uff0c\u4e3a\u4e86\u4fdd\u8bc1\u6027\u80fd\uff0c\u5728\u5185\u5b58\u548c\u6570\u636e\u95f4\u6709\u4e00\u4e2a\u5efa\u8bae\u7684\u6bd4\u4f8b\uff1a<br \/>\n\u50cf\u4e00\u822c\u65e5\u5fd7\u7c7b\u6587\u4ef6\uff0c<code>1G<\/code>\u5185\u5b58\u80fd\u591f\u5b58\u50a8<code>48G~96GB<\/code>\u6570\u636e\uff1b<br \/>\n<code>jvm<\/code>\u5806\u5185\u5b58\u6700\u5927\u4e0d\u8981\u8d85\u8fc7<code>31G<\/code>\uff1b<br \/>\n\u5176\u6b21\u5c31\u662f\u4e3b\u5206\u7247\u7684\u5bb9\u91cf\uff0c\u5355\u4e2a\u63a7\u5236\u5728<code>30~50GB<\/code>\uff1b<\/p>\n<p>\u5047\u8bbe<strong>\u6bcf\u5929<\/strong>\u603b\u6570\u636e\u91cf\u4e3a<code>xGB<\/code>\uff1b3\u4e2a<code>node<\/code>\u8282\u70b9\uff0c1\u4e2a\u526f\u672c\uff1b<br \/>\n\u90a3\u4e48\u5b9e\u9645\u8981\u5b58\u50a8\u7684\u5927\u5c0f\u4e3a<code>2xGB<\/code>\uff0c\u56e0\u4e3a\u7531\u4e00\u4e2a\u526f\u672c\u7684\u5b58\u5728\uff1b<\/p>\n<p><code>2xGB \/ 3 \/ 0.8 = 0.8xGB<\/code>\uff0c\u56e0\u4e3a\u6bcf\u4e2a\u8282\u70b9\u9700\u8981\u9884\u7559\u7ea6<code>20%<\/code>\u7684\u7a7a\u95f4\uff0c\u610f\u5473\u7740\u6bcf\u4e2a<code>node<\/code>\u8981\u5b58\u50a8\u5927\u7ea6<code>0.8xGB<\/code>\u7684\u6570\u636e\uff1b<\/p>\n<p>\u5b89\u88c5\u5185\u5b58\u4e0e\u5b58\u50a8\u6570\u636e\u7684\u6bd4\u7387\u8ba1\u7b97\uff08\u5047\u8bbe\u6bcf\u4e2a<code>node<\/code>\u7684\u5185\u5b58\u4e3a<code>8G<\/code>\uff09\uff1a<br \/>\n<code>0.8xGB \/ 48 = 8GB<\/code>\uff0c\u5f97\u51fa<code>x = 480GB<\/code>\uff0c\uff08<code>8G<\/code>\u5185\u5b58\u53ef\u4ee5\u6ee1\u8db3\u6bcf\u5929<code>480GB<\/code>\u7684\u65e5\u5fd7\u91cf\uff09<br \/>\n\u6240\u4ee5\u76ee\u524d<code>node<\/code>\u8282\u70b9\u7684\u914d\u7f6e\u4e3a\u5185\u5b58<code>8G<\/code>\uff0c\u6302\u5728\u5b58\u50a8\u76ee\u5f55<code>\/elkstorage<\/code>\u4e3a<code>500GB<\/code><br \/>\n\u8fd8\u8981\u5c3d\u91cf\u63a7\u5236\u4e3b\u5206\u7247\u7684\u5927\u5c0f\u4e3a<code>30~50GB<\/code><\/p>\n<pre><code class=\"language-bash\">vim \/etc\/elasticsearch\/jvm.options\n-Xms8g\n-Xmx8g\n\n# \u6839\u636e\u670d\u52a1\u5668\u5185\u5b588G\uff0c\u4fee\u6539\u4e3a4G\u3002\u4e00\u822c\u8bbe\u7f6e\u4e3a\u670d\u52a1\u5668\u7269\u7406\u5185\u5b58\u7684\u4e00\u534a\u4e3a\u6700\u4f73\uff0c\u4f46\u6700\u5927\u4e0d\u80fd\u8d85\u8fc732G<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>es\u57fa\u672c\u6982\u5ff5 es\u662f\u4ec0\u4e48 elasticsearch\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u3001restful\u98ce\u683c\u7684\u641c\u7d22\u548c\u6570\u636e\u5b58\u50a8\u5206\u6790\u5f15\u64ce &#8230; &raquo; <a class=\"read-more-link\" href=\"http:\/\/blue.yn.cn\/?p=1202\">\u9605\u8bfb\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-1202","post","type-post","status-publish","format-standard","hentry","category-elk"],"_links":{"self":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1202"}],"version-history":[{"count":16,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1202\/revisions"}],"predecessor-version":[{"id":1290,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1202\/revisions\/1290"}],"wp:attachment":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1202"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}