ES - Linux - 注意事项

文章详细介绍了如何在Linux环境下以非root用户启动ElasticSearch和Kibana,包括处理权限问题、配置文件设置、启动参数、日志排查以及分词器的安装。同时,讨论了ElasticSearch的高性能配置建议和示例,如索引映射与搜索查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

## 1. ElasticSearch 和 Kibana 在 Linux服务器启动
需要切换到非root用户启动
[root@localhsot bin] useradd es
[root@localhsot bin] su es
[es@localhsot bin] # ./elasticsearch
[es@localhsot bin] # ./kibana

## 2.若启动时报Permission Denied,需要赋文件夹权限给es用户
[root@localhsot bin] chown -R es /apps/elasticsearch /apps/kibana

不建议 --allow-root
建议 使用root创建一个普通用户,再使用普通用户启动

## 3. 启动成功后可以在浏览器进行验证浏览

## 4. 挂载启动
[es@localhsot bin] # nohup ./elasticsearch & 
[es@localhsot bin] # nohup ./kibana &


## 5. 关闭进程
# 1) ElasticSearch - grep 应用名
[es@localhsot bin] #ps aux|grep elastic

# 2) Kibana - grep 端口号
[es@localhsot bin] #ps aux|grep 5601 

[es@localhsot bin] # kill -9 xxx



## 6. ES启动参数配置文件 --- [../config/elasticsearch.yml 配置文件]
# 忽略掉geoip下载
ingest.geoip.downloader.enabled: false

# 单机本地磁盘空间较小。(磁盘空间不足,配置了集群的话,索引会不健康)
cluster.routing.allocation.disk.threshold_enabled: false

# 外网部署,有防火墙
 systemctl status firewalld
 firewall-cmd --query-port=9200/tcp

ElasticSearch: 

# 启动后访问9200网址无返回信息
# 查着日志显示
# [2024-03-26T14:20:05,905][WARN ][o.e.x.s.t.n.SecurityNetty4HttpServerTransport] [yanfayibu1] received plaintext http traffic on an https channel, closing connection Netty4HttpChannel{localAddress=/172.16.81.43:9200, remoteAddress=/172.16.81.43:52442}

# application.yml
xpack相关的配置true都改成false

# 安装分词器
#1) 在es/plugin文件夹下,解压完成后需要将zip文件删除,否则无法启动es
#2) 分词器安装完成后,需要将kibana先停止,然后再启动es,否则es也无法启动

kibana:

# 会影响后期集群,可一并改了
# xpack.reporting.roles.enabled

# kibana.yml 配置修改,否则无法完全启动成功
server.host: 172.16.81.43

# 改称中文
i18n.locale: "zh-CN"

  

Kibana进程截图

一、ES高性能配置讲解

[译]9条关于高性能ElasticSearch的配置建议

二、ES 简单示例

# Click the Variables button, above, to create your own variables.

PUT es_business_file_txt
{
  "mappings": {
    "properties": {
      "fileId":{
        "type": "keyword"
      },
      "sysCode":{
        "type": "keyword"
      },
      "branchId":{
        "type": "keyword"
      },
      "batchNo":{
        "type": "keyword"
      },
      "fileName":{
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "fileType":{
        "type": "keyword"
      },
      "billCode":{
        "type": "keyword"
      },
      "createdBy":{
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "createTime":{
        "type": "date"
      },
      "REMARK":{
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "annotation":{
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "label":{
        "type": "text",
        "analyzer": "ik_max_word"
      }
    }
  }
  , "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}


PUT es_business_file_txt
{
  "mappings": {
    "properties": {
      "fileId":{
        "type": "text",
		    "fields": {
		        "keyword": {
		        "type": "keyword",
		        "ignore_above": 256
		      }
		    }
      },
      "sysCode":{
        "type": "text"
      },
      "branchId":{
        "type": "text"
      },
      "batchNo":{
        "type": "text"
      },
      "fileName":{
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "fileType":{
        "type": "text"
      },
      "billCode":{
        "type": "text"
      },
      "createdBy":{
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "createTime":{
        "type": "date"
      },
      "REMARK":{
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "annotation":{
        "type": "text",
        "analyzer": "ik_max_word"
      },
      "label":{
        "type": "text",
        "analyzer": "ik_max_word"
      }
    }
  }
  , "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

# json形式index
PUT es_business_file_json
{
  "mappings": {
    "properties": {
      "objectFiled":{
        "type": "object"
      },
      "jsonField":{
        "type": "text",
		    "fields": {
		        "keyword": {
		        "type": "keyword",
		        "ignore_above": 256
		      }
		    }
      },
      "nestedFiled":{
        "type": "nested"
      }
    }
  }, 
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

PUT es_business_file_json/_create/1
{
    "objectFiled": {"objFiled1": "objValue1"},
    "jsonField": "{\"jsonFiled1\": \"jsonValue1\"}",
    "nestedFiled": {"objFiled2": "objValue2"}
}

PUT es_business_file_json/_create/2
{
    "objectFiled": {"Filed1": "object Value1", "Filed1_2": "object1_2 Value1_2 你很好"},
    "jsonField": "{\"Filed2\": \"json Value2\", \"Filed2_2\": \"object2_2 Value2_2 你很好 很好\"}",
    "nestedFiled": {"Filed3": "nested Value3", "Filed3_2": "object3_2 Value3_2 你很好很好很好"}
}

PUT es_business_file_json/_create/3
{
    "objectFiled": {"Filed3_1": "object Value1", "Filed3_2": "object1_2 Value1_2 你很好3", "field3_3": {"Filed3_1": "早上好 早上很好3 object hello 1"}},
    "nestedFiled": {"Filed3_3": "nested Value3", "Filed3_2": "object3_2 Value3_2 你很好很好很好 3", "field3_3": {"Filed3_1": "早上好 早上很好3  object hello 3"}}
}

# json格式存储
PUT es_business_file_txt/_create/1{
    "fileId": "你很好很好很好",
    "fileName": "你很好",
    "billCode": "你真很好很好",
    "REMARK": "{"bookName"}"
}


GET _analyze
{
  "analyzer": "ik_max_word",
  "text": ["大大"]
}

GET es_business_file/_search
{
  "query":{
    "multi_match":{
      "query":"你好",
      "fields":["billCode"]
    }
  }
}

PUT es_business_file_txt/_create/1
{
  "fileId": "你很好很好很好",
    "fileName": "你很好",
    "billCode": "你真很好很好"
}

# json格式存储
PUT es_business_file_txt/_create/1{
    "fileId": "你很好很好很好",
    "fileName": "你很好",
    "billCode": "你真很好很好",
    "REMARK": "{"bookName"}"
}





POST es_business_file/_doc
{
  "fileId": "CCC"
}

POST es_business_file/_update/2
{
  "doc": {
    "fileId": "BBB",
    "fileName": "你很好",
    "billCode": "你很好很好"
  }
}



DELETE es_business_file/_doc/NpZzS4cBX2TbHzC0yFEL




GET es_business_file/_search
{
  "query":{
    "match_all":{}
  },
  "from":0,
  "size":100,
  "sort":{
    "createTime":"desc"
  }
}





GET es_business_file/_search
{
  "query":{
  "bool" : {
    "must" : [
      {
        "match" : {
          "fileName" : {
            "query" : "大",
            "operator" : "OR",
            "prefix_length" : 0,
            "max_expansions" : 50,
            "fuzzy_transpositions" : true,
            "lenient" : false,
            "zero_terms_query" : "NONE",
            "auto_generate_synonyms_phrase_query" : true,
            "boost" : 1.0
          }
        }
      }
    ],
    "filter" : [
      {
        "terms" : {
          "sysCode" : [
            "epcb"
          ],
          "boost" : 1.0
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
},
  "from":0,
  "size":100,
  "sort":{
    "createTime":"desc"
  }
  
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值