Äúµ±Ç°ËùÔÚλÖãºÊ×Ò³ > ÎÊ´ð > ²â»æÎÊ´ð >

ÍØÆÕ¿µESÔõôµ÷ƽ

±à¼­£ºrichie

2023-12-10 04:41:10

ÍØÆÕ¿µESÔõôµ÷ƽ - רҵָµ¼

ÍØÆÕ¿µESÔõôµ÷ƽ

ÍØÆÕ¿µESÊÇÒ»¿î¹¦ÄÜÇ¿´ó¡¢Áé»î¶àÑùµÄÆóÒµ¼¶¹ÜÀíϵͳ¡£È»¶ø£¬ÓÉÓÚÆäÇ¿´óµÄ¹¦Äܺ͸´ÔÓµÄÅäÖÃÑ¡ÏÓÐʱ»á³öÏÖÓû§ÔÚʹÓùý³ÌÖÐÓöµ½ÏµÍ³²»Æ½ºâµÄÇé¿ö¡£±¾ÎĽ«Ïêϸ½éÉÜһЩµ÷ƽµÄ¼¼ÇÉ£¬°ïÖúÄúÓÅ»¯ÍØÆÕ¿µESϵͳµÄÐÔÄÜ¡£

1. ²é¿´ÏµÍ³¸ºÔØ

Òªµ÷ƽÍØÆÕ¿µESϵͳ£¬Ê×ÏÈÒªÁ˽âϵͳµÄµ±Ç°¸ºÔØÇé¿ö¡£¿ÉÒÔͨ¹ýÒÔÏ·½Ê½²é¿´£º

1.1 ÃüÁîÐз½Ê½

ÔÚÍØÆÕ¿µES·þÎñÆ÷ÉÏ´ò¿ªÃüÁîÐÐÖնˣ¬²¢ÊäÈëÒÔÏÂÃüÁ

$ top

¸ÃÃüÁÏÔʾϵͳµÄʵʱ¸ºÔØÇé¿ö£¬°üÀ¨CPUʹÓÃÂÊ¡¢ÄÚ´æʹÓÃÂʵȡ£

1.2 Kibana¼à¿Ø

ÍØÆÕ¿µESϵͳ×Ô´øÁËKibana¼à¿Ø¹¤¾ß£¬¿ÉÒÔͨ¹ýKibana²é¿´ÏµÍ³µÄ¸ºÔØÇé¿ö¡£´ò¿ªä¯ÀÀÆ÷£¬ÊäÈëÍØÆÕ¿µES·þÎñÆ÷µÄIPµØÖ·£¬È»ºóÔÚµØÖ·À¸ºóÃæ¼ÓÉÏ/app/kibana£¬Èçapp/kibana£¬È»ºó°´»Ø³µ¼ü¡£ÔÚKibanaµÄ½çÃæÉÏ£¬Ñ¡Ôñ¡°¼à¿Ø¡±Ñ¡Ï¿ÉÒԲ鿴ϵͳµÄ¸ºÔØÇé¿öÒÔ¼°ÆäËûÐÔÄÜÖ¸±ê¡£

2. µ÷ÕûÄÚ´æÅäÖÃ

ÍØÆÕ¿µESϵͳÔÚÔËÐйý³ÌÖлáÏûºÄ´óÁ¿µÄÄÚ´æ¡£Èç¹ûϵͳÄÚ´æ²»×㣬»áµ¼ÖÂϵͳÐÔÄÜϽµ»ò±ÀÀ£¡£Òò´Ë£¬ºÏÀíÅäÖÃϵͳµÄÄÚ´æÊǵ÷ƽÍØÆÕ¿µESϵͳµÄ¹Ø¼ü¡£

2.1 ·ÖÅä¶ÑÄÚ´æ

ÍØÆÕ¿µESϵͳĬÈÏ»áΪJavaÐéÄâ»ú·ÖÅä1GBµÄ¶ÑÄÚ´æ¡£ÔÚ´ó¶àÊýÇé¿öÏ£¬ÕâÊDz»¹»µÄ¡£ÎÒÃǽ¨Ò齫¶ÑÄÚ´æµÄ´óСÉèÖÃΪÎïÀíÄÚ´æµÄÒ»°ë£¬µ«²»³¬¹ý32GB¡£Äú¿ÉÒÔͨ¹ý±à¼­jvm.optionsÎļþÀ´ÉèÖöÑÄÚ´æ´óС¡£ÕÒµ½ÒÔÏÂÐУº

-Xms1g
-Xmx1g

½«ÆäÐÞ¸ÄΪ£º

-Xms8g
-Xmx8g

Õ⽫ΪJavaÐéÄâ»ú·ÖÅä8GBµÄ¶ÑÄÚ´æ¡£

2.2 ¹Ø±Õ²»ÐèÒªµÄ²å¼þ

ÍØÆÕ¿µESϵͳÓкܶà²å¼þ£¬Èç¹û²»ÐèҪijЩ²å¼þ£¬¿ÉÒÔͨ¹ý±à¼­elasticsearch.ymlÎļþÀ´¹Ø±ÕËüÃÇ¡£ÕÒµ½ÒÔÏÂÐУº

# ÆôÓÃX-Pack²å¼þ
#xpack.security.enabled: true

½«Æä×¢Ê͵ô£¬¼´ÐÞ¸ÄΪ£º

# ÆôÓÃX-Pack²å¼þ
#xpack.security.enabled: false

Õ⽫¹Ø±ÕX-Pack²å¼þ£¬½ÚʡϵͳÄÚ´æ¡£

3. Ôö¼Ó½Úµã

Èç¹ûÍØÆÕ¿µESϵͳ¸ºÔعýÖØ£¬¿ÉÒÔͨ¹ýÔö¼Ó½ÚµãÀ´·ÖÉ¢¸ºÔØ£¬ÌáÉýϵͳÐÔÄÜ¡£

3.1 Ìí¼ÓÊý¾Ý½Úµã

ÍØÆÕ¿µESϵͳĬÈÏÇé¿öÏÂÖ»ÓÐÒ»¸öÊý¾Ý½Úµã£¬Èç¹ûÊý¾ÝÁ¿ºÜ´ó£¬¿ÉÒÔͨ¹ýÌí¼Ó¸ü¶àµÄÊý¾Ý½ÚµãÀ´ÌáÉýÊý¾Ý´¦ÀíÄÜÁ¦¡£±à¼­elasticsearch.ymlÎļþ£¬ÕÒµ½ÒÔÏÂÐУº

# ½ÚµãÃû³Æ
#node.name: node-1

¸´ÖÆÕâÐв¢ÐÞ¸ÄÃû³ÆΪnode-2£¬È»ºóÈ¡Ïû×¢ÊÍ£º

# ½ÚµãÃû³Æ
node.name: node-2

Öظ´ÒÔÉϲ½Ö裬¿ÉÒÔÌí¼Ó¸ü¶àµÄÊý¾Ý½Úµã¡£

3.2 Ìí¼Ó¿Í»§¶Ë½Úµã

Èç¹ûÓдóÁ¿µÄ¿Í»§¶ËÇëÇó£¬ÎªÁ˼õÇáÊý¾Ý½ÚµãµÄ¸ºÔØ£¬¿ÉÒÔÌí¼Ó¿Í»§¶Ë½Úµã¡£±à¼­elasticsearch.ymlÎļþ£¬ÕÒµ½ÒÔÏÂÐУº

# ½ÚµãÃû³Æ
#node.name: node-1

¸´ÖÆÕâÐв¢ÐÞ¸ÄÃû³ÆΪnode-3£¬È»ºóÈ¡Ïû×¢ÊÍ£º

# ½ÚµãÃû³Æ
node.name: node-3

ͨ¹ýÌí¼Ó¸ü¶àµÄ¿Í»§¶Ë½Úµã£¬¿ÉÒÔÌá¸ßϵͳµÄ²¢·¢´¦ÀíÄÜÁ¦¡£

4. ÓÅ»¯ËÑË÷ÐÔÄÜ

ÍØÆÕ¿µESϵͳµÄºËÐŦÄÜÖ®Ò»¾ÍÊÇÇ¿´óµÄËÑË÷ÄÜÁ¦¡£ÒÔÏÂÊÇһЩÓÅ»¯ËÑË÷ÐÔÄܵļ¼ÇÉ£º

4.1 ´´½¨Ë÷Òýʱָ¶¨·ÖƬºÍ¸±±¾ÊýÁ¿

ÔÚ´´½¨Ë÷Òýʱ£¬¿ÉÒÔͨ¹ýÖ¸¶¨·ÖƬºÍ¸±±¾ÊýÁ¿À´Ìá¸ßËÑË÷ÐÔÄÜ¡£ÀýÈ磺

PUT /my_index
{
  "settings": {
    "number_of_shards": 5,
    "number_of_replicas": 1
  }
}

ÉÏÊö´úÂë±íʾ½«my_indexË÷Òý»®·ÖΪ5¸ö·ÖƬ£¬Ã¿¸ö·ÖƬÓÐÒ»¸ö¸±±¾¡£

4.2 ʹÓùýÂËÆ÷

¹ýÂËÆ÷ÊÇÒ»ÖÖÓÃÓÚÔÚËÑË÷¹ý³ÌÖÐÅųý²»Æ¥ÅäµÄÎĵµµÄ¼¼Êõ¡£Í¨¹ýʹÓùýÂËÆ÷£¬¿ÉÒÔÏÔÖøÌá¸ßËÑË÷ÐÔÄÜ¡£ÀýÈ磺

GET /my_index/_search
{
  "query": {
    "bool": {
      "must": {
        "match": {
          "title": "¹Ø¼ü´Ê"
        }
      },
      "filter": {
        "term": {
          "category": "Àà±ð"
        }
      }
    }
  }
}

ÉÏÊö´úÂëÖУ¬¹ýÂËÆ÷termÓÃÓÚ¹ýÂËÖ¸¶¨Àà±ðµÄÎĵµ¡£

4.3 ʹÓþۺÏ

¾ÛºÏÊÇÒ»ÖÖÓÃÓÚͳ¼Æ¡¢·ÖÎöÊý¾ÝµÄ¼¼Êõ¡£Í¨¹ýʹÓþۺϣ¬¿ÉÒÔ»ñÈ¡¸üÏêϸµÄÊý¾ÝÐÅÏ¢£¬²¢Ìá¸ßËÑË÷ÐÔÄÜ¡£ÀýÈ磺

GET /my_index/_search
{
  "aggs": {
    "avg_price": {
      "avg": {
        "field": "price"
      }
    }
  }
}

ÉÏÊö´úÂëÖУ¬¾ÛºÏavgÓÃÓÚ¼ÆËãprice×ֶεÄƽ¾ùÖµ¡£

5. ×ܽá

ͨ¹ýºÏÀíµ÷ÕûÍØÆÕ¿µESϵͳµÄÅäÖ㬿ÉÒÔÌá¸ßϵͳµÄÐÔÄܺÍÎȶ¨ÐÔ¡£±¾ÎĽéÉÜÁ˲鿴ϵͳ¸ºÔØ¡¢µ÷ÕûÄÚ´æÅäÖá¢Ôö¼Ó½ÚµãºÍÓÅ»¯ËÑË÷ÐÔÄܵȼ¼ÇÉ¡£Ï£ÍûÕâЩ¼¼ÇɶÔÄúÓÅ»¯ÍØÆÕ¿µESϵͳÓÐËù°ïÖú¡£

±êÇ©£º

¡ñ Ïà¹ØÍƼö¸ü¶à>>