linux安裝Elasticsearch5.6.X詳細(xì)步驟
第一步:環(huán)境
linux 系統(tǒng) Java 1.8.0_151 elasticsearch-5.6.8
第二步:下載安裝
-
1损拢,下載JDK怠堪,安裝JDK環(huán)境
JDK的下載可以去官網(wǎng)上直接下載:http://www.oracle.com/technetwork/java/javase/downloads/index.html
-
直接將下載好的jdk-8u151-linux-x64.rpm 安裝包 ;上傳到自己創(chuàng)建好的JAVA文件下;cd 命令進(jìn)入到JAVA文件下使用rpm 命令進(jìn)行安裝 rpm -ivh jdk-8u131-linux-x64.rpm 安裝完成后執(zhí)行 java -version 命令查看安裝是否成功。
配置環(huán)境變量,執(zhí)行命令 vi /etc/profile愕宋;然后進(jìn)入編輯模式出牧,在文件的最后添加下面的配置悴了,如圖
JAVA_HOME=/usr/javajdk1.8.0_151
JRE_HOME=/usr/java/jdk1.8.0_151/jre
CLASSPATH=JRE_HOME/lib:
JAVA_HOME/bin:
PATH
image.png
執(zhí)行命令 source /etc/profile 使用環(huán)境變量生效
驗(yàn)證環(huán)境變量是否生效:echo $JAVA_HOME
- 2寇钉,下載安裝ES
去官網(wǎng)直接下載矫渔,本人使用的是 5.6.8版本;因?yàn)榘姹镜牟煌惭bhead插件的時(shí)候安裝步驟不同摧莽;好像是從5.0 以后的版本安裝head 插件的步驟就不一樣了庙洼;下面會(huì)詳細(xì)介紹。
ES官網(wǎng):https://www.elastic.co/下載ES安裝包elasticsearch-5.6.8.zip 在usr 目錄下創(chuàng)建了es文件夾镊辕,將安裝包上傳到里面油够,解壓 unzip elasticsearch-5.6.8.zip cd 進(jìn)入 elasticsearch-5.6.8 文件里面。
創(chuàng)建ES用戶和組(創(chuàng)建elsearch用戶組及elsearch用戶)征懈,因?yàn)槭褂胷oot用戶執(zhí)行ES程序石咬,將會(huì)出現(xiàn)錯(cuò)誤;所以這里需要?jiǎng)?chuàng)建單獨(dú)的用戶去執(zhí)行ES 文件卖哎;命令如下:
命令一:groupadd elsearch
命令二:useradd elsearch -g elsearch
命令三:chown -R elsearch:elsearch-
創(chuàng)建ES數(shù)據(jù)文件和日志文件鬼悠,直接在root用戶根目錄一下創(chuàng)建就可以了
執(zhí)行命令:mkdir /data
命令二:chown -R elsearch:elsearch /data/
命令三:su - elsearch 切換用戶
命令四:mkdir -p es/data
命令五:mkdir -p es/logsimage.png 修改ES配置文件,使用cd命令進(jìn)入到config 文件下亏娜,執(zhí)行 vi elasticsearch.yml 命令焕窝,如圖所示,本人沒有配置集群维贺,只是簡單的配置了一下它掂;詳細(xì)說明可以參考官網(wǎng);
執(zhí)行ES文件溯泣,進(jìn)入到bin 目錄下執(zhí)行 ./elasticsearch 命令就可以了虐秋,執(zhí)行 ./elasticesrarch -d 是后臺(tái)運(yùn)行。
如果沒有什么問題話垃沦,就可以安全生成了客给;然后執(zhí)行curl 'http://自己配置的IP地址:9200/' 命令,就出現(xiàn)下面的結(jié)果
后臺(tái)啟動(dòng)es命令:./bin/elasticsearch -d
可以看到es在后臺(tái)啟動(dòng)了
第四步:問題
- 1肢簿,[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536] 意思是說你的進(jìn)程不夠用了
解決方案: 切到root 用戶:進(jìn)入到security目錄下的limits.conf靶剑;執(zhí)行命令 vim /etc/security/limits.conf 在文件的末尾添加下面的參數(shù)值:
- soft nofile 65536
- hard nofile 131072
- soft nproc 2048
hard nproc 4096
前面的*符號必須帶上,然后重新啟動(dòng)就可以了译仗。執(zhí)行完成后可以使用命令 ulimit -n 查看進(jìn)程數(shù) 抬虽。
root@data-hadoop-112-15:~ $ ssh 192.168.129.94
Last login: Mon Dec 9 20:23:29 2019 from data-hadoop-112-15.bjrs.zybang.com
[root@owl-nginx-129-94 ~]# ulimit -n
655350
用戶退出后重新登錄生效
- 2官觅,[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144] 需要修改系統(tǒng)變量的最大值
解決方案:切換到root用戶修改配置sysctl.conf 增加配置值: vm.max_map_count=655360
執(zhí)行命令 sysctl -p 這樣就可以了纵菌,然后重新啟動(dòng)ES服務(wù) 就可以了。
第五步:安裝head插件
-
1休涤,下載head安裝包咱圆,下載地址:https://github.com/mobz/elasticsearch-head/archive/master.zip 這是接從git 上下載下來 笛辟,然后上傳到虛擬機(jī)上的;由于head 插件不能放在elasticsearch-5.6.8 文件夾里序苏,head 插件需要單獨(dú)放手幢,單獨(dú)去執(zhí)行; 所 以在elasticsearch-5.6.8 同級目錄下解壓了 head 插件忱详;解壓出來的文件名字围来,如圖:
image.png -
2,安裝head 插件匈睁,需要node.js 的支持监透,所以,下面先安裝一node.js
- 執(zhí)行命令一:curl -sL https://rpm.nodesource.com/setup_8.x | bash -
- 命令二:yum install -y nodejs-----用brew來安裝
? softeare brew install -y node.js
Updating Homebrew...
==> Installing dependencies for node: icu4c
==> Installing node dependency: icu4c
==> Downloading https://homebrew.bintray.com/bottles/icu4c-61.1.high_sierra.bottle.tar.gz
######################################################################## 100.0%
執(zhí)行完成后航唆,可以使用命令 node -v 驗(yàn)證是否安裝成功胀蛮,同時(shí)npm 也安裝成功了;執(zhí)行命令 npm -v 也是可以驗(yàn)證的糯钙。
- 3粪狼,安裝grunt ,由于head 插件的執(zhí)行文件是有g(shù)runt 命令來執(zhí)行的,所以這個(gè)命令必須安裝
- npm install grunt --save-dev
---》brew ? softeare brew install grunt --save-dev
Updating Homebrew...
Warning: grunt-cli: this formula has no --save-dev option so it will be ignored!
==> Downloading https://homebrew.bintray.com/bottles/grunt-cli-1.2.0.high_sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring grunt-cli-1.2.0.high_sierra.bottle.tar.gz
?? /usr/local/Cellar/grunt-cli/1.2.0: 154 files, 251.3KB
如果出現(xiàn)以下錯(cuò)誤:
image.png
- npm install grunt --save-dev
-
則安裝缺少的包:
參考:http://www.reibang.com/p/a73d95030edb
npm install grunt-contrib-clean
npm install grunt-contrib-concat
npm install grunt-contrib-watch
npm install grunt-contrib-connect (安裝了太久)
npm install grunt-contrib-copy
npm install grunt-contrib-jasmine-
最后一個(gè)比較難安裝任岸,要聯(lián)網(wǎng)到一個(gè)國外網(wǎng)站下載一個(gè)東西再榄,而且貌似 有個(gè)引擎要求的node比我這里的node版本高,會(huì)有一個(gè)warning享潜,安裝到Receiving...就殺了進(jìn)程不跟,殺掉之后再運(yùn)行g(shù)runt可以看到一切都正常了,有條件的可以等待Receiving...后面的內(nèi)容米碰。
image.png -
命令二:npm install
image.png 修改配置文件窝革,cd 進(jìn)入elasticsearch-head-master 文件夾下,執(zhí)行命令vim Gruntfile.js文件:增加hostname屬性吕座,設(shè)置為*虐译;如圖:
路徑:elasticsearch-head-master/_site/app.js
修改 localhost:9200 為實(shí)際 Elasticsearch 的地址
修改前:this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://localhost:9200";
修改后:
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://172.16.X.X:9200";
-
- 修改 vim _site/app.js 文件,修改head的連接地址吴趴,如圖所示:
- 最后一個(gè)命令: grunt server & 執(zhí)行完成后就OK了漆诽。
- 涉及到的問題,在網(wǎng)頁上無法正常訪問锣枝;查看防火墻是否關(guān)閉
執(zhí)行命令service iptables status 查看狀態(tài) 厢拭;直接將防火墻關(guān)閉就好了 執(zhí)行命令service iptables stop。
- 最后執(zhí)行的結(jié)果是這樣的撇叁,我沒有配置集群: 注意下面使用的端口號供鸠,不在是9200 了 而是head 插件中的 9100 了。
- 看到上面的出現(xiàn)的健康值了嗎陨闹,說明的連接還是有問題的楞捂,解決方案是修改 cd 命令進(jìn)入到elasticsearch-5.6.3 /config 文件中 vi elasticsearch.yml
文件下添加 :
http.cors.enabled: true
http.cors.allow-origin: "*"
然后重新執(zhí)行ES ./elasticsearch 成功起來就可以了薄坏,執(zhí)行結(jié)果就是這樣的
- 未寫入數(shù)據(jù)前:
ES集群安裝遇到的問題
報(bào)錯(cuò):
root@hue:~/elasticsearch-5.6.8/bin# [2018-04-03T16:28:51,641][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [master1] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:123) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:70) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:134) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.6.8.jar:5.6.8]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:195) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:342) ~[elasticsearch-5.6.8.jar:5.6.8]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:132) ~[elasticsearch-5.6.8.jar:5.6.8]
... 6 more
切換到es用戶
注意將data目錄的用戶和用戶組設(shè)置為es
Master啟動(dòng)日志如下:
es@hue:/usr/local/es/elasticsearch-5.6.8/bin$ ./elasticsearch &
[1] 25086
es@hue:/usr/local/es/elasticsearch-5.6.8/bin$ [2018-04-03T17:44:54,347][INFO ][o.e.n.Node ] [master1] initializing ...
[2018-04-03T17:44:54,552][INFO ][o.e.e.NodeEnvironment ] [master1] using [1] data paths, mounts [[/ (/dev/vda1)]], net usable_space [28.2gb], net total_space [39.2gb], spins? [possibly], types [ext4]
[2018-04-03T17:44:54,553][INFO ][o.e.e.NodeEnvironment ] [master1] heap size [1.9gb], compressed ordinary object pointers [true]
[2018-04-03T17:44:54,554][INFO ][o.e.n.Node ] [master1] node name [master1], node ID [T73gSpfdTS-34qIYEwFPYA]
[2018-04-03T17:44:54,554][INFO ][o.e.n.Node ] [master1] version[5.6.8], pid[25086], build[688ecce/2018-02-16T16:46:30.010Z], OS[Linux/4.4.0-62-generic/amd64], JVM[Oracle Corporation/OpenJDK 64-Bit Server VM/1.8.0_151/25.151-b12]
[2018-04-03T17:44:54,555][INFO ][o.e.n.Node ] [master1] 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/es/elasticsearch-5.6.8]
[2018-04-03T17:44:55,482][INFO ][o.e.p.PluginsService ] [master1] loaded module [aggs-matrix-stats]
[2018-04-03T17:44:55,482][INFO ][o.e.p.PluginsService ] [master1] loaded module [ingest-common]
[2018-04-03T17:44:55,483][INFO ][o.e.p.PluginsService ] [master1] loaded module [lang-expression]
[2018-04-03T17:44:55,483][INFO ][o.e.p.PluginsService ] [master1] loaded module [lang-groovy]
[2018-04-03T17:44:55,483][INFO ][o.e.p.PluginsService ] [master1] loaded module [lang-mustache]
[2018-04-03T17:44:55,483][INFO ][o.e.p.PluginsService ] [master1] loaded module [lang-painless]
[2018-04-03T17:44:55,483][INFO ][o.e.p.PluginsService ] [master1] loaded module [parent-join]
[2018-04-03T17:44:55,483][INFO ][o.e.p.PluginsService ] [master1] loaded module [percolator]
[2018-04-03T17:44:55,483][INFO ][o.e.p.PluginsService ] [master1] loaded module [reindex]
[2018-04-03T17:44:55,484][INFO ][o.e.p.PluginsService ] [master1] loaded module [transport-netty3]
[2018-04-03T17:44:55,484][INFO ][o.e.p.PluginsService ] [master1] loaded module [transport-netty4]
[2018-04-03T17:44:55,484][INFO ][o.e.p.PluginsService ] [master1] no plugins loaded
[2018-04-03T17:44:56,800][INFO ][o.e.d.DiscoveryModule ] [master1] using discovery type [zen]
[2018-04-03T17:44:57,287][INFO ][o.e.n.Node ] [master1] initialized
[2018-04-03T17:44:57,288][INFO ][o.e.n.Node ] [master1] starting ...
[2018-04-03T17:44:57,592][INFO ][o.e.t.TransportService ] [master1] publish_address {10.1.72.136:9300}, bound_addresses {10.1.72.136:9300}
[2018-04-03T17:44:57,605][INFO ][o.e.b.BootstrapChecks ] [master1] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2018-04-03T17:45:00,686][INFO ][o.e.c.s.ClusterService ] [master1] new_master {master1}{T73gSpfdTS-34qIYEwFPYA}{ofDnSPHlSfe8kLZZx4NCaQ}{10.1.72.136}{10.1.72.136:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-04-03T17:45:00,745][INFO ][o.e.h.n.Netty4HttpServerTransport] [master1] publish_address {10.1.72.136:9200}, bound_addresses {10.1.72.136:9200}
[2018-04-03T17:45:00,746][INFO ][o.e.n.Node ] [master1] started
[2018-04-03T17:45:00,765][INFO ][o.e.g.GatewayService ] [master1] recovered [0] indices into cluster_state
訪問master:
注意要啟動(dòng)slave!U帧胶坠!
可以看到slave節(jié)點(diǎn)也啟動(dòng)了
附es配置文件:
- master
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
cluster.name: bingo-es
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
node.name: master1
node.master: true
node.data: true
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
path.data: /usr/local/data/es/data
# Path to log files:
#
#path.logs: /path/to/logs
path.logs: /usr/local/data/es/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: host1
#
# Set a custom port for HTTP:
http.port: 9200
discovery.zen.ping.unicast.hosts: ["host1","host2"]
discovery.zen.minimum_master_nodes: 2
#head
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
#xpack.security.enabled: false
#xpack.reporting.enabled: false
#xpack.monitoring.enabled: false
#xpack.monitoring.exporters.auth.username: "elastic"
#xpack.monitoring.exporters.auth.password: "changeme"
#xpack.security.audit.enabled: true
#action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*
#elasticsearch.username: "elastic"
#elasticsearch.password: "changeme"
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
- data節(jié)點(diǎn)
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
cluster.name: bingo-es
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
node.name: data1
#node.master: false
node.master: true
node.data: true
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
path.data: /usr/local/data/es/data
# Path to log files:
#
#path.logs: /path/to/logs
path.logs: /usr/local/data/es/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: host2
# Set a custom port for HTTP:
#
#http.port: 9200
http.port: 9200
discovery.zen.ping.unicast.hosts: ["host1","host2"]
discovery.zen.minimum_master_nodes: 2
#discovery.zen.ping.multicast.enabled: false
#
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-headers: Authorization,X-Requested-With,Content-Length,Content-Type
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#
#xpack.security.enabled: false
#xpack.reporting.enabled: false
#xpack.monitoring.enabled: false
#action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history*
#xpack.monitoring.elasticsearch.username: "elastic"
#xpack.monitoring.elasticsearch.password: "changeme"
#elsticsearch.username: "elastic"
#elasticsearch.password: "changeme"
#For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true