在linux 系統安裝ElasticSearch-6.3.2最新版本,也適合6.x 系列版本做參考
前提先在linux 安裝好jdk1.8
創建用戶
從5.0開始,ElasticSearch 安全級別提高了,不允許采用root帳號啟動,所以我們要添加一個用戶
1 創建 elasticsearch 用戶組
[root@localhost ~]# groupadd elasticsearch
2 創建用戶 es 並設置密碼為es
[root@localhost ~]# useradd es [root@localhost ~]# passwd es
3 用戶es 添加到 elasticsearch 用戶組
[root@localhost ~]# usermod -G elasticsearch es
4 設置sudo權限
[root@localhost ~]# visudo
在root ALL=(ALL) ALL 一行下面 添加es用戶 如下: es ALL=(ALL) ALL 添加成功保存后切換到es用戶操作
[root@localhost ~]# su es [es@localhost root]$
下載安裝包
在/usr/local/src 目錄下 下載elasticsearch ,並解壓 tar.gz
[es@localhost src]$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.tar.gz
[es@localhost src]$ tar -xvf elasticsearch-6.3.2.tar.gz
把解壓的文件移動到 /usr/local
[es@localhost src]$ sudo mv elasticsearch-6.3.2 /usr/local
更改elasticsearch-6.3.2 文件夾以及內部文件的所屬用戶為es, 用戶組組為elasticsearch,-R表示逐級
[es@localhost local]$ sudo chown -R es:elasticsearch elasticsearch-6.3.2
ElasticSearch 配置
elasticsearch.yml 修改
[es@localhost elasticsearch-6.3.2]$ vim config/elasticsearch.yml
修改內容(沒有就添加):
cluster.name: my-application
node.name: node-1
network.host: 0.0.0.0
http.port: 9200
#因為Centos6不支持SecComp,而ES默認bootstrap.system_call_filter為true進行檢測
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
修改/etc/sysctl.conf
切換回root 用戶 執行
vim /etc/sysctl.conf
在文件最后面添加內容:
vm.max_map_count=262144
保存退出后,使用sysctl -p 刷新生效
[root@localhost ~]# sysctl -p net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 vm.max_map_count = 262144 [root@localhost ~]#
修改文件/etc/security/limits.conf
vim /etc/security/limits.conf
添加如下內容:
* hard nofile 65536 * soft nofile 65536 * soft nproc 2048 * hard nproc 4096
啟動elasticesearch 可能還會報如下錯誤
max number of threads [1024] for user [lish] likely too low, increase to at least [4096]
解決:切換到root用戶,進入limits.d目錄下修改配置文件。
vi /etc/security/limits.d/90-nproc.conf
修改如下內容:
* soft nproc 1024
#修改為
* soft nproc 4096
啟動 elasticsearch
完成上面配置修改后,切換到es 用戶,目錄切換到 elasticsearch 安裝目錄下執行
[es@localhost elasticsearch-6.3.2]$ bin/elasticsearch
在瀏覽器輸入localhost:9200 驗證是否啟動成功,如果瀏覽器輸出如下信息,代表安裝啟動成功
{
"name" : "node-1",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "8okSnhNzRr6Xo233szO0Vg",
"version" : {
"number" : "6.3.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "053779d",
"build_date" : "2018-07-20T05:20:23.451332Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
如果啟動過程中出現異常信息,請根據信息百度相關問題,下面是我啟動過程遇到的錯誤信息並附上解決方案
異常信息1:expecting token of type [START_OBJECT] but found [VALUE_STRING]]; 錯誤原因:elasticsearch.yml 文件內部錯誤 解決辦法:仔細檢查yml文件中的配置項書寫格式: (空格)name:(空格)value --------------------------------------------------------------------------------- 異常信息2:java.lang.UnsupportedOperationException: seccomp unavailable: CONFIG_SECCOMP not compiled into kernel, CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER are needed 錯誤原因:Centos6不支持SecComp,而ES默認bootstrap.system_call_filter為true進行檢測,所以導致檢測失敗,失敗后直接導致ES不能啟動 解決辦法:修改elasticsearch.yml 添加一下內容 : bootstrap.memory_lock: false bootstrap.system_call_filter: false --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- 異常信息3:BindTransportException[Failed to bind to [9300-9400] 解決辦法 打開配置文件elasticsearch.yml 將 network.host: 192.168.0.1 修改為本機IP 0.0.0.0 -------------------------------------------------------------------------------------------- 異常信息4:max number of threads [1024] for user [lish] likely too low, increase to at least [2048] 解決辦法:切換到root用戶,進入limits.d目錄下修改配置文件。 vi /etc/security/limits.d/90-nproc.conf 修改如下內容: * soft nproc 1024 #修改為 * soft nproc 2048
