Elasticsearch-5.6.16.tar.gz版本安裝配置(四)

在此選用elasticsearch-5.6.16.tar.gz方式安裝,Elasticsearch安裝在5.0版本以後必須依賴jdk1.8之上的java版本

安裝JDK1.8

下載鏈接:https://pan.baidu.com/s/1uvktlm-6AqhQKJQZR1nQuw
上傳到機器

[root@CentOS7_node1 src]# tar xf jdk-8u161-linux-x64.tar.gz  -C /usr/local/
[root@CentOS7_node1 src]# mv /usr/local/jdk1.8.0_161 /usr/local/java
[root@CentOS7_node1 src]# tail -5 /etc/profile
#################JAVA#################
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[root@CentOS7_node1 src]# source /etc/profile
[root@CentOS7_node1 src]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

安裝Elasticsearch

下載鏈接:https://pan.baidu.com/s/1hDPam2SWACkbvaz8W_r2SQ
上傳到機器

[root@CentOS7_node1 src]# tar xf elasticsearch-5.6.16.tar.gz -C /usr/local/
[root@CentOS7_node1 src]# ls /usr/local/elasticsearch-5.6.16/
bin  config  data  lib  LICENSE.txt  logs  modules  NOTICE.txt  plugins  README.textile
  1. bin目錄:二進制腳本啓動es程序文件以及啓動es插件目錄
  2. config目錄:elasticsearch配置文件
  3. data目錄:默認Elasticsearch生成的索引/切片數據文件存放目錄,可以指定多個位置來存儲數據
  4. lib目錄:一些開發的jar包
  5. logs目錄:elasticsearch日誌目錄
  6. modules目錄:模塊目錄,詳情看官網鏈接:https://www.elastic.co/guide/en/elasticsearch/reference/5.6/modules.html
  7. plugins目錄:elasticsearch插件目錄,此版本tar包裝後默認無插件

bin目錄文件介紹

[root@CentOS7_node1 elasticsearch-5.6.16]# tree bin/
bin/
├── elasticsearch                                       #Elasticsearch啓動腳本
├── elasticsearch.bat                                   #Win啓動腳本,tar包也是可以在Win運行的
├── elasticsearch.in.bat
├── elasticsearch.in.sh
├── elasticsearch-keystore
├── elasticsearch-keystore.bat
├── elasticsearch-plugin                                #集成插件啓動腳本         
├── elasticsearch-plugin.bat
├── elasticsearch-service.bat
├── elasticsearch-service-mgr.exe
├── elasticsearch-service-x64.exe
├── elasticsearch-service-x86.exe
├── elasticsearch-systemd-pre-exec
├── elasticsearch-translog
└── elasticsearch-translog.bat

0 directories, 15 files

config目錄文件介紹

[root@CentOS7_node1 elasticsearch-5.6.16]# tree config/
config/
├── elasticsearch.yml                              #ES節點集羣等相關配置
├── jvm.options                                    #JVM堆內存及GC相關配置
├── log4j2.properties                              #log4j2框架日誌輸出相關配置
└── scripts                                        #腳本存放目錄,默認無腳本

1 directory, 3 files

logs目錄文件介紹

log目錄默認是沒有的,需要你正常啓動elasticsearch後,會在你的es目錄下自動生成一個log目錄
[root@CentOS7_node1 elasticsearch-5.6.16]# tree logs/
logs/
├── elasticsearch_deprecation.log                   #ES描述日誌
├── elasticsearch_index_indexing_slowlog.log        #索引日誌
├── elasticsearch_index_search_slowlog.log          #搜索日誌
└── elasticsearch.log                               #集羣名稱會生成一個以集羣名稱命名的日誌                                          

0 directories, 4 files

創建elasticsearch所用到的用戶及組

elasticsearch默認是不能以root身份去運行的,否則啓動會報錯誤信息爲“can not run elasticsearch as root Elasticsearch”,所以我們要創建一個普通用戶來管理elasticsearch
創建elasticsearch用戶及組

[root@CentOS7_node1 /]# groupadd elasticsearch 
[root@CentOS7_node1 /]# useradd elasticsearch -g elasticsearch
[root@CentOS7_node1 /]# echo '3edc#EDC' | passwd --stdin elasticsearch
Changing password for user elasticsearch.
passwd: all authentication tokens updated successfully.

更改Elasticsearch目錄屬性信息

[root@CentOS7_node1 /]# chown -Rf elasticsearch:elasticsearch /usr/local/elasticsearch-5.6.16
[root@CentOS7_node1 /]# ll /usr/local/elasticsearch-5.6.16
total 240
drwxr-xr-x.  2 elasticsearch elasticsearch   4096 May  5 14:57 bin
drwxr-xr-x.  2 elasticsearch elasticsearch   4096 May  5 15:11 config
drwxr-xr-x.  2 elasticsearch elasticsearch   4096 Mar 13 23:34 lib
-rw-r--r--.  1 elasticsearch elasticsearch  11358 Mar 13 23:31 LICENSE.txt
drwxr-xr-x.  2 elasticsearch elasticsearch   4096 May  5 14:02 logs
drwxr-xr-x. 13 elasticsearch elasticsearch   4096 Mar 13 23:35 modules
-rw-r--r--.  1 elasticsearch elasticsearch 194187 Mar 13 23:34 NOTICE.txt
drwxr-xr-x.  2 elasticsearch elasticsearch   4096 Mar 13 23:34 plugins
-rw-r--r--.  1 elasticsearch elasticsearch   9491 Mar 13 23:31 README.textile

啓動elasticsearch

切換到elasticsearch用戶來啓動ES
[root@CentOS7_node1 ~]# su elasticsearch
[elasticsearch@CentOS7_node1 root]$ /usr/local/elasticsearch-5.6.16/bin/elasticsearch -h
默認情況下,Elasticsearch在前臺運行,將其日誌打印到標準輸出(stdout),然後按下Ctrl-C即可停止
starts elasticsearch

Option                Description                                              
------                -----------                                              
-E <KeyValuePair>     Configure a setting         
#ES啓動時可以指定配置信息,是以Key Value的形式來配置                           
#-E選項實例:./bin/elasticsearch -d -Ecluster.name=my_cluster -Enode.name=node_1
#-d 表示後臺啓動ES,-Ecluster.name指定ES的集羣名稱,node.name指定節點名稱,這兩參數在ES的config/elasticsearch.yml中都有設置
-V, --version         Prints elasticsearch version information and exits       
#顯示ES的版本信息
-d, --daemonize       Starts Elasticsearch in the background                    
#-d選項改爲以後臺守護進程方式啓動
-h, --help            show help                                                         
-p, --pidfile <Path>  Creates a pid file in the specified path on start         
#指定ES的PID文件路徑 
-q, --quiet           Turns off standard ouput/error streams logging in console     
#關閉控制檯中的標準輸出/錯誤流日誌記錄
-s, --silent          show minimal output                                           
#精簡顯示啓動信息                       
-v, --verbose         show verbose output                                       
#詳細顯示啓動信息
[elasticsearch@CentOS7_node1 /]$ /usr/local/elasticsearch-5.6.16/bin/elasticsearch 
[2019-05-07T23:39:22,140][INFO ][o.e.n.Node               ] [] initializing ...
[2019-05-07T23:39:22,229][INFO ][o.e.e.NodeEnvironment    ] [lPEqF6-] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [18gb], net total_space [24.5gb], spins? [unknown], types [rootfs]
[2019-05-07T23:39:22,229][INFO ][o.e.e.NodeEnvironment    ] [lPEqF6-] heap size [1.9gb], compressed ordinary object pointers [true]
[2019-05-07T23:39:22,230][INFO ][o.e.n.Node               ] node name [lPEqF6-] derived from node ID [lPEqF6-7TaClsuN_NVm9NA]; set [node.name] to override
[2019-05-07T23:39:22,230][INFO ][o.e.n.Node               ] version[5.6.16], pid[17264], build[3a740d1/2019-03-13T15:33:36.565Z], OS[Linux/3.10.0-957.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_161/25.161-b12]
[2019-05-07T23:39:22,231][INFO ][o.e.n.Node               ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/usr/local/elasticsearch-5.6.16]
[2019-05-07T23:39:22,900][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [aggs-matrix-stats]
[2019-05-07T23:39:22,900][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [ingest-common]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [lang-expression]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [lang-groovy]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [lang-mustache]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [lang-painless]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [parent-join]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [percolator]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [reindex]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [transport-netty3]
[2019-05-07T23:39:22,901][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [transport-netty4]
[2019-05-07T23:39:22,902][INFO ][o.e.p.PluginsService     ] [lPEqF6-] no plugins loaded
[2019-05-07T23:39:24,457][INFO ][o.e.d.DiscoveryModule    ] [lPEqF6-] using discovery type [zen]
[2019-05-07T23:39:24,935][INFO ][o.e.n.Node               ] initialized
[2019-05-07T23:39:24,936][INFO ][o.e.n.Node               ] [lPEqF6-] starting ...
[2019-05-07T23:39:27,518][INFO ][o.e.t.TransportService   ] [lPEqF6-] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2019-05-07T23:39:27,529][WARN ][o.e.b.BootstrapChecks    ] [lPEqF6-] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2019-05-07T23:39:27,529][WARN ][o.e.b.BootstrapChecks    ] [lPEqF6-] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2019-05-07T23:39:30,589][INFO ][o.e.c.s.ClusterService   ] [lPEqF6-] new_master {lPEqF6-}{lPEqF6-7TaClsuN_NVm9NA}{O8BQXY-3Q1O9nrC34rDU5w}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2019-05-07T23:39:30,622][INFO ][o.e.h.n.Netty4HttpServerTransport] [lPEqF6-] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-05-07T23:39:30,622][INFO ][o.e.n.Node               ] [lPEqF6-] started
[2019-05-07T23:39:30,635][INFO ][o.e.g.GatewayService     ] [lPEqF6-] recovered [0] indices into cluster_state

以上告警有WARN警告信息,我們一定要注意下,並解決此問題,這涉及到了ES的兩種模式,分別爲:開發者模式和生產模式

開發者模式可生產模式

默認情況下,Elasticsearch假定您正在開發模式下工作。如果未正確配置上述任何設置,則會向日志文件寫入警告,但您將能夠啓動並運行Elasticsearch節點。
一旦配置了網絡設置network.host(此參數在elasticsearch.yml文件中配置),Elasticsearch就會假定您正在轉向生產並將上述警告升級爲異常。這些異常將阻止您的Elasticsearch節點啓動。這是一項重要的安全措施,可確保您不會因服務器配置錯誤而丟失數據。
爲了更讓我們的測試環境貼合生產模式,我們堅決不允許它出半點問題

啓動失敗問題

1.文件描述符過低
[2019-05-07T23:39:27,529][WARN ][o.e.b.BootstrapChecks ] [lPEqF6-] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

解決:
修改文件描述符數量

echo '* soft nofile 65536' >> /etc/security/limits.conf
echo '* hard nofile 65536' >> /etc/security/limits.conf
然後重新登錄終端
[root@CentOS7_node1 ~]# ulimit -n
65536

2.max_map_count值爲65530]太低,至少增加到262144
[2019-05-07T23:39:27,529][WARN ][o.e.b.BootstrapChecks ] [lPEqF6-] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
在linux系統上,elasticsearch默認使用hybrid mmapfs / niofs來存儲索引文件,因此操作系統主要會通過mmap來限制存儲的空間,因此如果存儲空間滿了,那麼會拋出異常,我們可以使用如下命令來更改設置。

解決:
修改max_map_count值

臨時設置:
[root@CentOS7_node1 ~]# sysctl -w vm.max_map_count=655360
vm.max_map_count = 655360

永久設置:
[root@CentOS7_node1 ~]# echo 'vm.max_map_count=655360' >> /etc/sysctl.conf 
[root@CentOS7_node1 ~]# sysctl -p   
vm.max_map_count = 655360

3.這個問題我們現在雖然是沒遇見,但是建議先把坑填上,不然還是會出現的
在ES啓動的時候警告信息爲:“Unable to lock JVM Memory: error=12, reason=Cannot allocate memory”,無法分配內存的意思

解決:

[root@CentOS7_node1 ~]# echo '* soft memlock unlimited' >> /etc/security/limits.conf
[root@CentOS7_node1 ~]# echo '* hard memlock unlimited' >> /etc/security/limits.conf
[root@CentOS7_node1 ~]# tail -2 /etc/security/limits.conf
* soft memlock unlimited
* hard memlock unlimited

再次啓動
首先要退出終端,然後重新登錄,讓elasticsearch用戶能夠重新加載我們剛修改的配置

[root@CentOS7_node1 ~]# su elasticsearch
[elasticsearch@CentOS7_node1 root]$ ulimit -n
65536
[elasticsearch@CentOS7_node1 root]$ /usr/local/elasticsearch-5.6.16/bin/elasticsearch 
[2019-05-08T00:00:43,188][INFO ][o.e.n.Node               ] [] initializing ...
[2019-05-08T00:00:43,265][INFO ][o.e.e.NodeEnvironment    ] [lPEqF6-] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [18.1gb], net total_space [24.5gb], spins? [unknown], types [rootfs]
[2019-05-08T00:00:43,265][INFO ][o.e.e.NodeEnvironment    ] [lPEqF6-] heap size [1.9gb], compressed ordinary object pointers [true]
[2019-05-08T00:00:43,266][INFO ][o.e.n.Node               ] node name [lPEqF6-] derived from node ID [lPEqF6-7TaClsuN_NVm9NA]; set [node.name] to override
[2019-05-08T00:00:43,266][INFO ][o.e.n.Node               ] version[5.6.16], pid[21842], build[3a740d1/2019-03-13T15:33:36.565Z], OS[Linux/3.10.0-957.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_161/25.161-b12]
[2019-05-08T00:00:43,266][INFO ][o.e.n.Node               ] JVM arguments [-Xms2g, -Xmx2g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -Djdk.io.permissionsUseCanonicalPath=true, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Dlog4j.skipJansi=true, -XX:+HeapDumpOnOutOfMemoryError, -Des.path.home=/usr/local/elasticsearch-5.6.16]
[2019-05-08T00:00:44,000][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [aggs-matrix-stats]
[2019-05-08T00:00:44,000][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [ingest-common]
[2019-05-08T00:00:44,000][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [lang-expression]
[2019-05-08T00:00:44,000][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [lang-groovy]
[2019-05-08T00:00:44,000][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [lang-mustache]
[2019-05-08T00:00:44,001][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [lang-painless]
[2019-05-08T00:00:44,001][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [parent-join]
[2019-05-08T00:00:44,001][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [percolator]
[2019-05-08T00:00:44,001][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [reindex]
[2019-05-08T00:00:44,001][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [transport-netty3]
[2019-05-08T00:00:44,001][INFO ][o.e.p.PluginsService     ] [lPEqF6-] loaded module [transport-netty4]
[2019-05-08T00:00:44,001][INFO ][o.e.p.PluginsService     ] [lPEqF6-] no plugins loaded
[2019-05-08T00:00:45,824][INFO ][o.e.d.DiscoveryModule    ] [lPEqF6-] using discovery type [zen]
[2019-05-08T00:00:46,288][INFO ][o.e.n.Node               ] initialized
[2019-05-08T00:00:46,288][INFO ][o.e.n.Node               ] [lPEqF6-] starting ...
[2019-05-08T00:00:48,555][INFO ][o.e.t.TransportService   ] [lPEqF6-] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2019-05-08T00:00:51,637][INFO ][o.e.c.s.ClusterService   ] [lPEqF6-] new_master {lPEqF6-}{lPEqF6-7TaClsuN_NVm9NA}{QRumAuUXQpW14l6cEgBUGA}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2019-05-08T00:00:51,672][INFO ][o.e.h.n.Netty4HttpServerTransport] [lPEqF6-] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-05-08T00:00:51,672][INFO ][o.e.n.Node               ] [lPEqF6-] started
[2019-05-08T00:00:51,692][INFO ][o.e.g.GatewayService     ] [lPEqF6-] recovered [0] indices into cluster_state

ES端口詳解

再次打開一個終端

[root@CentOS7_node1 ~]# ps -ef|grep java
elastic+ 21842 21777 14 00:00 pts/1    00:00:09 /usr/local/java/bin/java -Xms2g -Xmx2g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -server -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -Djdk.io.permissionsUseCanonicalPath=true -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Dlog4j.skipJansi=true -XX:+HeapDumpOnOutOfMemoryError -Des.path.home=/usr/local/elasticsearch-5.6.16 -cp /usr/local/elasticsearch-5.6.16/lib/* org.elasticsearch.bootstrap.Elasticsearch
root     22132 20125  0 00:01 pts/2    00:00:00 grep --color=auto java
[root@CentOS7_node1 ~]# ss -anplt | grep java
LISTEN     0      128       ::ffff:127.0.0.1:9200                    :::*                   users:(("java",pid=21842,fd=135))
LISTEN     0      128        ::1:9200                    :::*                   users:(("java",pid=21842,fd=134))
LISTEN     0      128       ::ffff:127.0.0.1:9300                    :::*                   users:(("java",pid=21842,fd=121))
LISTEN     0      128        ::1:9300                    :::*                   users:(("java",pid=21842,fd=119))

查看java進程可以看到我們的elasticsearch是以elasticsearch用戶所啓動
查看端口看到ES默認啓用兩個端口,分別是TCP端口9200及TCP端口9300,但是隻監聽在了127.0.0.1的地址上,如需修改監聽地址,我們可以通過config/elasticsearch.yml文件來修改。
9200端口是爲搜索服務所提供的端口。
9300是ES集羣中通信端口,根據9300端口來判定集羣各節點的存活性,此端口採用單播的形式進行集羣通信。

測試ES是否啓動成功

打開一個終端,訪問本地9200端口,查看返回信息

[elasticsearch@CentOS7_node1 root]$ curl http://127.0.0.1:9200 
{
  "name" : "mDAWBTb",                       #本節點名稱
  "cluster_name" : "elasticsearch",         #集羣名稱
  "cluster_uuid" : "DEXGYpVzRhOnXcmykCtJTQ",#集羣UID
  "version" : {                             #以下爲版本信息
    "number" : "5.6.16",                    #ES版本
    "build_hash" : "3a740d1",               #ES默認會爲各個節點分片一個UID標識符,具有唯一性
    "build_date" : "2019-03-13T15:33:36.565Z",#es數據構建時間
    "build_snapshot" : false,                 #是否構建快照
    "lucene_version" : "6.6.1"                #Apache Lucene檢索工具庫版本
  },
  "tagline" : "You Know, for Search"
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章