es 搭建

elastic官方網站

Elastic有一條完整的產品線:Elasticsearch、Kibana、Logstash等,前面說的三個就是大家常說的ELK技術棧。

1.安裝java環境
java環境的安裝

ElasticSearch 7.3安裝
cd /tools
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.1.3.zip
unzip elasticsearch-6.1.3.zip
mv ./elasticsearch-6.1.3 /usr/local/elasticsearch
2.1安裝ElasticSearch 7.3.1安裝
es下載頁

cd /tools
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.3.2-linux-x86_64.tar.gz
tar -zxvf elasticsearch-7.3.2-linux-x86_64.tar.gz
mv ./elasticsearch-7.3.2 /usr/local/elasticsearch
目錄結構介紹:

bin:可執行文件,運行es的命令
config:配置文件目錄
 config/elasticsearch.yml:ES啓動基礎配置
 config/jvm.options:ES啓動時JVM配置
 config/log4j2.properties:ES日誌輸出配置文件
lib:依賴的jar
logs:日誌文件夾
modules:es模塊
plugins:可以自己開發的插件
data:我們自己創建的,存放es存儲文件

設置es權限(elk是elatic的簡稱) cd /usr/local
# 添加elk分組 groupadd elk
# 在elk分組下添加elk用戶 useradd -g elk elk
# 賦權給/usr/local/elasticsearch chown elk:elk -R /usr/local/elasticsearch 安裝成功

啓動
#切換爲elk用戶
su elk
#啓動 後面加 -d 爲後臺啓動
/usr/local/elasticsearch/bin/elasticsearch
一定要注意,elasticSearch不能用root賬戶啓動,elasticSearch不能用root賬戶啓動,elasticSearch不能用root賬戶啓動,重要的說三遍,我這裏用的是我新建的elasticsearch賬戶開機啓動

報錯1:

bash-4.2$ ./elasticsearch -d
future versions of Elasticsearch will require Java 11; your Java version from [/usr/local/jdk/jdk1.8.0_201/jre] does not meet this requirement
Exception in thread “main” java.lang.RuntimeException: starting java failed with [1]
output:

There is insufficient memory for the Java Runtime Environment to continue.

Native memory allocation (mmap) failed to map 986513408 bytes for committing reserved memory.

An error report file with more information is saved as:

logs/hs_err_pid1395.log

error:
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000000c5330000, 986513408, 0) failed; error='Cannot allocate memory' (errno=12)
    at org.elasticsearch.tools.launchers.JvmErgonomics.flagsFinal(JvmErgonomics.java:111)
    at org.elasticsearch.tools.launchers.JvmErgonomics.finalJvmOptions(JvmErgonomics.java:79)
    at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:57)
    at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:89)

解決方案:調小啓動內存

vi /usr/local/elasticsearch/config/jvm.options
修改22行

#-Xms2g
#-Xmx2g
-Xms256m
-Xmx256m
1、切換到root用戶修改配置sysctl.conf

vi /etc/sysctl.conf
添加下面配置:

vm.max_map_count=655360
並執行命令:

sysctl -p

然後,重新啓動elasticsearch,即可啓動成功。
上面設置的分配的內存的最大值爲256MB和最小值64mb,您可以根據自己的機器情況設置內存大小。

重新啓動即可/usr/local/elasticsearch/bin/elasticsearch

[root@master local]# curl http://127.0.0.1:9200
{
  "name" : "master",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "j-_k3fJLTtq49qNso0bAcw",
  "version" : {
    "number" : "7.3.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "1c1faf1",
    "build_date" : "2019-09-06T14:40:30.409026Z",
    "build_snapshot" : false,
    "lucene_version" : "8.1.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

啓動成功!

後臺啓動:

/usr/local/elasticsearch/bin/elasticsearch -d
2.2 設置開機啓動: 我是本地,直接把iptables 關掉了
vim /etc/rc.d/rc.local
service iptables stop
su elk -c “/usr/local/elasticsearch/bin/elasticsearch -d”
2.3 配置
vim /usr/local/elasticsearch/config/elasticsearch.yml
修改如下:

cluster.name: application-1
node.name: node-1
network.host: 192.168.0.210
其中cluster.name 是集羣名稱,這個不要使用默認的,要修改,去掉註釋,如果有多個機器,加入同一個集羣,那麼這個值必須一樣

noide.name 是集羣裏面每個節點的值,也就是當前機器的節點的值,這個值,每個節點要不一樣。

network host 改成當前的內網ip
下面的部分是elasticsearch 2 部分的插件,在es6中已經不可用,

es6的可視化GUI,請查看:http://www.fecshop.com/topic/668

記錄一下問題(設置network host :0.0.0.0,用於外網訪問)一直都報這個錯誤:

[2019-09-19T11:59:58,586][DEBUG][o.e.a.ActionModule       ] [node-1] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-09-19T11:59:59,408][INFO ][o.e.d.DiscoveryModule    ] [node-1] using discovery type [zen] and seed hosts providers [settings]
[2019-09-19T12:00:01,501][INFO ][o.e.n.Node               ] [node-1] initialized
[2019-09-19T12:00:01,501][INFO ][o.e.n.Node               ] [node-1] starting ...
[2019-09-19T12:00:01,852][INFO ][o.e.t.TransportService   ] [node-1] publish_address {172.31.64.25:9300}, bound_addresses {0.0.0.0:9300}
[2019-09-19T12:00:01,864][INFO ][o.e.b.BootstrapChecks    ] [node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
[2019-09-19T12:00:01,984][INFO ][o.e.n.Node               ] [node-1] stopping ...
[2019-09-19T12:00:02,269][INFO ][o.e.n.Node               ] [node-1] stopped
[2019-09-19T12:00:02,269][INFO ][o.e.n.Node               ] [node-1] closing ...
[2019-09-19T12:00:02,287][INFO ][o.e.n.Node               ] [node-1] closed

解決方案: 修改/usr/local/elasticsearch/config/elasticsearch.yml配置文件

修改72行

#cluster.initial_master_nodes: [“node-1”, “node-2”]
cluster.initial_master_nodes: [“node-1”]
2.4 查看:
http://自己ip:9200/

報錯2

ERROR: [3] bootstrap checks failed [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

每個進程最大同時打開文件數太小,可通過下面2個命令查看當前數量

ulimit -Hn
ulimit -Sn

在這裏插入圖片描述

修改/etc/security/limits.conf文件,增加配置,用戶退出後重新登錄生效

*               soft    nofile          65536
*               hard    nofile          65536

max number of threads [3818] for user [es] is too low, increase to at least [4096]

問題同上,最大線程個數太低。修改配置文件/etc/security/limits.conf(和問題1是一個文件),增加配置

*               soft    nproc           4096
*               hard    nproc           4096

在這裏插入圖片描述

  修改過後需要重啓服務器 後執行 ulimit -a 是否修改成功

錯誤3

java.lang.UnsupportedOperationException: seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CON
FIG_SECCOMP_FILTER compiled in

原因: 因爲Centos6不支持SecComp,而ES默認bootstrap.system_call_filter爲true進行檢測,所以導致檢測失敗,失敗後直接導致ES不能啓動解決:修改elasticsearch.yml 添加一下內容 :

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

2.5 集羣設置
如果想要建立一個elasticSearch集羣,可以按照下面的步驟,非常的簡單,首先,想說明的是:對於elasticSearch,他隱藏了分佈式的複雜性,分片和複製集,都是他自動完成,你只需要配置好ip就可以了,下面是配置的步驟:

我有兩臺機器 192.169.0.210 192.168.0.199

我的兩臺機器都按照上面的步驟配置完成,下面配置集羣

首先是192.168.0.210

vim /usr/local/elasticsearch/config/elasticsearch.yml
找到行 , 修改如下:
discovery.zen.ping.unicast.hosts: [“192.168.0.199”]
上面的ip就是其他的節點的ip,如果我有5臺機器,那麼,這裏需要把其他四臺機器的ip寫上。

同理,對於其他的節點,需要把其他的節點協商,用逗號隔開

elasticSearch會找到對應的節點,自動分片和做複製集。

2.6 安裝ik插件(中文分詞使用)
報錯原因
我使用的Elasticsearch是6.2.2版本,按照學校文檔創建字段時,使用了

{“type”:“string”,“index”:“not_analyzed”}。
原因分析
檢查拼寫無誤之後,我決定去查Elasticsearch新版本特性,因爲之前也踩過head插件的安裝方法的坑,就是因爲版本問題。
果不其然,Elasticsearch從5.X就引入了text和keyword,其中keyword適用於不分詞字段,搜索時只能完全匹配,這時string還保留着。
到了6.X就徹底移除string了。
另外,”index”的值只能是boolean變量了。

解決方法

{“type”:“text”,“index”:false}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章