前言
- Elasticsearch 和 Kibana 均基于 5.5.3 版本亭病;
官方建議:在二者版本選擇時耕捞,Elasticsearch 應(yīng)該大于等于 Kibana 版本,否則在使用和升級過程中會出問題,截至文章出稿,已經(jīng)更新到 6.3.0 版本,本文以 5.5.3 版本為例峻仇,對其他版本安裝有同樣的參考作用。
服務(wù)器配置為:阿里云 ECS邑商,1 核础浮,2G 內(nèi)存
系統(tǒng)版本為:CentOS Linux release 7.4.1708 (Core)
4.本教程重點在于“如何搭建 Elasticsearch - Kibana 環(huán)境”帆调,對于二者是什么,能干什么豆同,使用場景番刊,這里不做過多說明,讀者可自行查詢資料影锈;Elasticsearch 如何使用芹务,作者后期會出 Elasticsearch 從入門到實戰(zhàn)系列教程。
5.搭建此環(huán)境的難點在于:過程中會出現(xiàn)各種配置問題鸭廷,需要修改枣抱,但是網(wǎng)上資料殘次不齊,或者不全辆床,或者只給出了一行解決命令佳晶,但是沒有解釋為什么這么修改,這個命令是干什么的讼载,對于 Linux 基礎(chǔ)不好的讀者而言轿秧,盲目執(zhí)行命令可能會對服務(wù)器有負(fù)面影響;本文不敢說全面咨堤,但是給出解決方案時菇篡,會詳細(xì)告知這個命令的作用和使用方法;
- 由于系統(tǒng)環(huán)境不同一喘,本文肯定沒有周全的給出所有的問題解決方案驱还,如果有新問題,樂于一起探討解決凸克。
本文共分為以下幾個步驟:
1. 檢查 JDK 版本
ES 使用 Java 編寫议蟆,安裝 ES 之前,需要先檢查 JDK 環(huán)境萎战,一般要求在 1.7 以上咐容,如果沒有安裝 JDK,建議直接安裝 1.8 版本撞鹉。安裝過程參考:JDK 安裝
[root@izbp163wlhi02tcaxyuxb7z wang]# java -version
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
2. 下載 Elasticsearch 安裝包,解壓
我這里安裝在 Linux 環(huán)境颖侄,下載 tar 包鸟雏,下載完后解壓:
tar -zxvf elasticsearch-5.5.3.tar.gz
3. 啟動 Elasticsearch
在 bin/ 目錄下,直接執(zhí)行 ./elasticsearch
命令即可览祖。
由于 Elasticsearch 運行的環(huán)境需求孝鹊,默認(rèn)的系統(tǒng)環(huán)境一般都需要再做調(diào)整,啟動可能會報如下的一些錯誤展蒂。
3.1 解決內(nèi)存分配問題
[root@izbp163wlhi02tcaxyuxb7z elasticsearch-5.5.3]# ./bin/elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning:
INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /usr/local/wang/elasticsearch-5.5.3/hs_err_pid15795.log
原因:這是由于 Elasticsearch 這個版本默認(rèn)分配 JVM 空間大小為 2g(不同版本默認(rèn)值不一樣)又活,而示例所用服務(wù)器為 1 核 2G苔咪,所以會報出內(nèi)存分配錯誤,我們?nèi)ヅ渲梦募薷?JVM 空間分配:
// 文件目錄在:/elasticsearch-5.5.3/config
[root@izbp163wlhi02tcaxyuxb7z config]# vim jvm.options
將
-Xms2g
-Xmx2g
改為
-Xms512m
-Xmx512m
如果還是報這個錯誤柳骄,那繼續(xù)減小這個數(shù)值团赏,這個得看機(jī)器配置。
3.2 解決用戶權(quán)限問題
錯誤:
[2018-07-04T10:43:45,590][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] 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:127) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.3.jar:5.5.3]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.3.jar:5.5.3]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.3.jar:5.5.3]
... 6 more
//查看當(dāng)前用戶
[root@izbp163wlhi02tcaxyuxb7z elasticsearch-5.5.3]# whoami
root
原因:由于 Elasticsearch 可以輸入且執(zhí)行腳本耐薯,為了系統(tǒng)安全舔清,不允許使用 root 啟動;我們看看有沒有可用的用戶曲初。
[root@izbp163wlhi02tcaxyuxb7z elasticsearch-5.5.3]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:997:User for polkitd:/:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
ntp:x:38:38::/etc/ntp:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
nscd:x:28:28:NSCD Daemon:/:/sbin/nologin
dockerroot:x:997:994:Docker User:/var/lib/docker:/sbin/nologin
//用戶名:密碼:用戶id:用戶所在組id:備注:用戶家目錄:shell命令所在目錄
如果發(fā)現(xiàn)用戶都是系統(tǒng)自帶的用戶体谒,那我們最好還是自己新建一個用戶,我這里新建一個用戶 wang臼婆,分組為 wang抒痒,密碼為 wang。
//添加分組wang
groupadd wang
//添加用戶wang颁褂,分組在wang,密碼wang
useradd wang -g wang -p wang
//授權(quán) /usr/local/wang/elasticsearch-5.5.3目錄下的文件擁有者為 wang(用戶):wang(分組)
chown -R wang:wang /usr/local/wang/elasticsearch-5.5.3
//切換用戶
//使用su和sudo是有區(qū)別的故响,使用su切換用戶需要輸入所切換到的用戶的密碼,而使用sudo則是當(dāng)前用戶的密碼痢虹。
su wang
再次啟動被去。
記住:后面修改文件時有時需要切到 root 用戶奖唯,但是啟動時記得切回來惨缆,不要在 root 下啟動!
[wang@izbp163wlhi02tcaxyuxb7z elasticsearch-5.5.3]$ ./bin/elasticsearch
[2018-07-04T11:25:22,745][INFO ][o.e.n.Node ] [] initializing ...
[2018-07-04T11:25:22,891][INFO ][o.e.e.NodeEnvironment ] [VKU0UAW] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [32.9gb], net total_space [39.2gb], spins? [unknown], types [rootfs]
[2018-07-04T11:25:22,892][INFO ][o.e.e.NodeEnvironment ] [VKU0UAW] heap size [503.6mb], compressed ordinary object pointers [true]
[2018-07-04T11:25:22,894][INFO ][o.e.n.Node ] node name [VKU0UAW] derived from node ID [VKU0UAWPT06PPv0aYHIuDw]; set [node.name] to override
[2018-07-04T11:25:22,894][INFO ][o.e.n.Node ] version[5.5.3], pid[16641], build[9305a5e/2017-09-07T15:56:59.599Z], OS[Linux/3.10.0-693.2.2.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_172/25.172-b11]
[2018-07-04T11:25:22,894][INFO ][o.e.n.Node ] JVM arguments [-Xms512m, -Xmx512m, -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/wang/elasticsearch-5.5.3]
[2018-07-04T11:25:25,352][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [aggs-matrix-stats]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [ingest-common]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [lang-expression]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [lang-groovy]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [lang-mustache]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [lang-painless]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [parent-join]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [percolator]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [reindex]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [transport-netty3]
[2018-07-04T11:25:25,353][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [transport-netty4]
[2018-07-04T11:25:25,354][INFO ][o.e.p.PluginsService ] [VKU0UAW] no plugins loaded
[2018-07-04T11:25:28,878][INFO ][o.e.d.DiscoveryModule ] [VKU0UAW] using discovery type [zen]
[2018-07-04T11:25:29,988][INFO ][o.e.n.Node ] initialized
[2018-07-04T11:25:29,988][INFO ][o.e.n.Node ] [VKU0UAW] starting ...
[2018-07-04T11:25:30,358][INFO ][o.e.t.TransportService ] [VKU0UAW] publish_address {127.0.0.1:9300}, bound_addresses {127.0.0.1:9300}
[2018-07-04T11:25:30,377][WARN ][o.e.b.BootstrapChecks ] [VKU0UAW] max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2018-07-04T11:25:30,377][WARN ][o.e.b.BootstrapChecks ] [VKU0UAW] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-07-04T11:25:33,470][INFO ][o.e.c.s.ClusterService ] [VKU0UAW] new_master {VKU0UAW}{VKU0UAWPT06PPv0aYHIuDw}{gqVgexbbSx-6IWNhGSzvRw}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-07-04T11:25:33,589][INFO ][o.e.h.n.Netty4HttpServerTransport] [VKU0UAW] publish_address {127.0.0.1:9200}, bound_addresses {127.0.0.1:9200}
[2018-07-04T11:25:33,590][INFO ][o.e.n.Node ] [VKU0UAW] started
[2018-07-04T11:25:33,618][INFO ][o.e.g.GatewayService ] [VKU0UAW] recovered [0] indices into cluster_state
啟動成功后丰捷,通過啟動信息坯墨,我們可以知道默認(rèn)的端口在 9200,但是信息中有兩個 warn 級別的日志病往,我們先去瀏覽器訪問的試試捣染。
http://xx.xx.xx.xx:9200
發(fā)現(xiàn)還是無法訪問。
3.3 無法訪問
原因:默認(rèn)訪問地址是 localhost停巷,我們要外網(wǎng)訪問耍攘,需要去修改下配置文件,elasticsearch-5.5.3/config
下的 elasticsearch.yml畔勤。
vim elasticsearch.yml
將network.host放開蕾各,修改為0.0.0.0下,將http.port放開庆揪,如下:
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
再次嘗試啟動式曲。
3.4 解決 ERROR: [2] bootstrap checks failed
[2018-07-04T16:00:28,070][INFO ][o.e.n.Node ] initialized
[2018-07-04T16:00:28,070][INFO ][o.e.n.Node ] [VKU0UAW] starting ...
[2018-07-04T16:00:28,377][INFO ][o.e.t.TransportService ] [VKU0UAW] publish_address {172.16.229.31:9300}, bound_addresses {0.0.0.0:9300}
[2018-07-04T16:00:28,401][INFO ][o.e.b.BootstrapChecks ] [VKU0UAW] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-07-04T16:00:28,485][INFO ][o.e.n.Node ] [VKU0UAW] stopping ...
[2018-07-04T16:00:28,535][INFO ][o.e.n.Node ] [VKU0UAW] stopped
[2018-07-04T16:00:28,536][INFO ][o.e.n.Node ] [VKU0UAW] closing ...
[2018-07-04T16:00:28,550][INFO ][o.e.n.Node ] [VKU0UAW] closed
這里其實是兩個錯誤,就是前面的兩個 warn 信息。
3.4.1 解決 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
原因:max_map_count
這個參數(shù)就是允許一個進(jìn)程在 VMAs(虛擬內(nèi)存區(qū)域)擁有最大數(shù)量吝羞,VMA 是一個連續(xù)的虛擬地址空間兰伤,當(dāng)進(jìn)程創(chuàng)建一個內(nèi)存映像文件時 VMA 的地址空間就會增加,當(dāng)達(dá) 到max_map_count
了就是返回 out of memory errors
钧排。
出現(xiàn)這個問題敦腔,我們需要切換到 root 用戶下。
// 修改下面的文件 里面是一些內(nèi)核參數(shù)
vi /etc/sysctl.conf
//添加以下配置
vm.max_map_count=655360
添加完后保存卖氨,然后執(zhí)行:
sysctl -p
//-p 從指定的文件加載系統(tǒng)參數(shù)会烙,如不指定即從/etc/sysctl.conf中加載
3.4.2 解決 max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
原因:最大文件打開數(shù)量太小,出現(xiàn)此錯誤筒捺,切換到 root 用戶下柏腻,修改 limits.conf。
// 編輯此文件
[root@izbp163wlhi02tcaxyuxb7z /]# vim etc/security/limits.conf
在文件后加上
* soft nofile 65536
* hard nofile 65536
5.5.3 版本系吭,此文件有這幾個值五嫂,我們只需要把這幾個值從 65535 改為 65536 即可。
# End of file
root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536
切回原來用戶肯尺,再次重啟 ES沃缘,檢查 ES 是否啟動成功。
啟動成功后提示如下:
[wang@izbp163wlhi02tcaxyuxb7z elasticsearch-5.5.3]$ ./bin/elasticsearch
[2018-07-04T16:28:45,250][INFO ][o.e.n.Node ] [] initializing ...
[2018-07-04T16:28:45,359][INFO ][o.e.e.NodeEnvironment ] [VKU0UAW] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [32.9gb], net total_space [39.2gb], spins? [unknown], types [rootfs]
[2018-07-04T16:28:45,361][INFO ][o.e.e.NodeEnvironment ] [VKU0UAW] heap size [503.6mb], compressed ordinary object pointers [true]
[2018-07-04T16:28:45,362][INFO ][o.e.n.Node ] node name [VKU0UAW] derived from node ID [VKU0UAWPT06PPv0aYHIuDw]; set [node.name] to override
[2018-07-04T16:28:45,362][INFO ][o.e.n.Node ] version[5.5.3], pid[21467], build[9305a5e/2017-09-07T15:56:59.599Z], OS[Linux/3.10.0-693.2.2.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_172/25.172-b11]
[2018-07-04T16:28:45,363][INFO ][o.e.n.Node ] JVM arguments [-Xms512m, -Xmx512m, -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/wang/elasticsearch-5.5.3]
[2018-07-04T16:28:46,941][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [aggs-matrix-stats]
[2018-07-04T16:28:46,941][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [ingest-common]
[2018-07-04T16:28:46,941][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [lang-expression]
[2018-07-04T16:28:46,941][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [lang-groovy]
[2018-07-04T16:28:46,941][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [lang-mustache]
[2018-07-04T16:28:46,941][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [lang-painless]
[2018-07-04T16:28:46,941][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [parent-join]
[2018-07-04T16:28:46,950][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [percolator]
[2018-07-04T16:28:46,950][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [reindex]
[2018-07-04T16:28:46,950][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [transport-netty3]
[2018-07-04T16:28:46,950][INFO ][o.e.p.PluginsService ] [VKU0UAW] loaded module [transport-netty4]
[2018-07-04T16:28:46,950][INFO ][o.e.p.PluginsService ] [VKU0UAW] no plugins loaded
[2018-07-04T16:28:50,067][INFO ][o.e.d.DiscoveryModule ] [VKU0UAW] using discovery type [zen]
[2018-07-04T16:28:51,171][INFO ][o.e.n.Node ] initialized
[2018-07-04T16:28:51,172][INFO ][o.e.n.Node ] [VKU0UAW] starting ...
[2018-07-04T16:28:51,484][INFO ][o.e.t.TransportService ] [VKU0UAW] publish_address {172.16.229.31:9300}, bound_addresses {0.0.0.0:9300}
[2018-07-04T16:28:51,513][INFO ][o.e.b.BootstrapChecks ] [VKU0UAW] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2018-07-04T16:28:54,650][INFO ][o.e.c.s.ClusterService ] [VKU0UAW] new_master {VKU0UAW}{VKU0UAWPT06PPv0aYHIuDw}{1HxIYnvrQ9KkyLOzhVwe3Q}{172.16.229.31}{172.16.229.31:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-07-04T16:28:54,708][INFO ][o.e.h.n.Netty4HttpServerTransport] [VKU0UAW] publish_address {172.16.229.31:9200}, bound_addresses {0.0.0.0:9200}
[2018-07-04T16:28:54,708][INFO ][o.e.n.Node ] [VKU0UAW] started
[2018-07-04T16:28:54,738][INFO ][o.e.g.GatewayService ] [VKU0UAW] recovered [0] indices into cluster_state
[2018-07-04T16:38:43,328][INFO ][o.e.c.m.MetaDataCreateIndexService] [VKU0UAW] [.kibana] creating index, cause [api], templates [], shards [1]/[1], mappings [_default_, index-pattern, server, visualization, search, timelion-sheet, config, dashboard, url]
仔細(xì)檢查则吟,日志都是 info 級別槐臀,沒有問題,去頁面訪問 xx.xx.xx.xx:9200
氓仲。
頁面會出現(xiàn)如下信息:
{
"name": "VKU0UAW",
"cluster_name": "elasticsearch",
"cluster_uuid": "TTJuSo16Tny1lUoFmnF-dA",
"version": {
"number": "5.5.3",
"build_hash": "9305a5e",
"build_date": "2017-09-07T15:56:59.599Z",
"build_snapshot": false,
"lucene_version": "6.6.0"
},
"tagline": "You Know, for Search"
}
至此水慨,Elasticsearch 安裝完畢。
3.5 后臺啟動 Elasticsearch
下面這種方式是在前臺啟動敬扛,我們關(guān)閉命令行或者退出晰洒,應(yīng)用就會關(guān)閉。
[wang@izbp163wlhi02tcaxyuxb7z elasticsearch-5.5.3]$ ./bin/elasticsearch
所以啥箭,我們需要在后臺啟動谍珊,這樣當(dāng)我們退出時,應(yīng)用仍在后臺運行急侥。
[wang@izbp163wlhi02tcaxyuxb7z elasticsearch-5.5.3]$ ./bin/elasticsearch -d
3.6 停止后臺服務(wù)
前臺啟動砌滞,直接 ctrl+c
退出即可,后臺啟動坏怪,停止時可以直接殺掉進(jìn)程贝润。
[wang@izbp163wlhi02tcaxyuxb7z bin]$ ./elasticsearch -d
[wang@izbp163wlhi02tcaxyuxb7z bin]$ jps
3697 Elasticsearch
3771 Jps
[wang@izbp163wlhi02tcaxyuxb7z bin]$ kill -9 3697
4. 下載 Kibana 安裝包,解壓
每一個版本的 ES 都有一個對應(yīng)的 Kibana 版本陕悬,我們可以去下面的地址查找最新的版本题暖,建議和 ES 相同版本按傅。
//解壓:
tar -zxvf kibana-5.5.3-linux-x86_64.tar.gz
5. 啟動 Kibana
[wang@izbp163wlhi02tcaxyuxb7z kibana-5.5.3-linux-x86_64]$ ./bin/kibana
Kibana 默認(rèn)是在前臺啟動捉超,可以通過 ctrl+c
命令停止胧卤。
解壓時的文件夾下裝著所有 Kibana 相關(guān)的文件,我們不用新建其他文件拼岳,當(dāng)我們需要刪除時枝誊,直接刪除此文件夾即可。
啟動后消息如下:
[wang@izbp163wlhi02tcaxyuxb7z kibana-5.5.3-linux-x86_64]$ ./bin/kibana
log [03:49:45.116] [info][status][plugin:kibana@5.5.3] Status changed from uninitialized to green - Ready
log [03:49:45.188] [info][status][plugin:elasticsearch@5.5.3] Status changed from uninitialized to yellow - Waiting for Elasticsearch
log [03:49:45.215] [error][admin][elasticsearch] Request error, retrying
HEAD http://localhost:9200/ => connect ECONNREFUSED 127.0.0.1:9200
log [03:49:45.219] [info][status][plugin:console@5.5.3] Status changed from uninitialized to green - Ready
log [03:49:45.224] [warning][admin][elasticsearch] Unable to revive connection: http://localhost:9200/
log [03:49:45.225] [warning][admin][elasticsearch] No living connections
log [03:49:45.228] [error][status][plugin:elasticsearch@5.5.3] Status changed from yellow to red - Unable to connect to Elasticsearch at http://localhost:9200.
log [03:49:45.251] [info][status][plugin:metrics@5.5.3] Status changed from uninitialized to green - Ready
log [03:49:45.454] [info][status][plugin:timelion@5.5.3] Status changed from uninitialized to green - Ready
log [03:49:45.459] [info][listening] Server running at http://localhost:5601
log [03:49:45.461] [error][status][ui settings] Status changed from uninitialized to red - Elasticsearch plugin is red
log [03:49:47.735] [warning][admin][elasticsearch] Unable to revive connection: http://localhost:9200/
log [03:49:47.735] [warning][admin][elasticsearch] No living connections
log [03:49:50.244] [warning][admin][elasticsearch] Unable to revive connection: http://localhost:9200/
log [03:49:50.245] [warning][admin][elasticsearch] No living connections
log [03:49:52.751] [warning][admin][elasticsearch] Unable to revive connection: http://localhost:9200/
log [03:49:52.751] [warning][admin][elasticsearch] No living connections
......
我們可以看到惜纸,他會默認(rèn)去鏈接同一臺服務(wù)器上的 9200 端口提供的服務(wù)叶撒,如果沒有啟動 Elasticsearch 服務(wù),他會一直嘗試去連接耐版,我們啟動下 Elasticsearch祠够。
訪問 http://xx.xx.xx.xx:5601,然后發(fā)現(xiàn)訪問不了粪牲,我們注意上面的日志古瓤,有這么一句:
log [03:49:45.459] [info][listening] Server running at http://localhost:5601
5.1 Kibana 外網(wǎng)無法訪問
在 config/kibana.yml 中,有如下配置腺阳,意思是默認(rèn)是 localhost落君,外網(wǎng)是無法訪問的,如果外網(wǎng)想訪問亭引,那需要修改一下 server.host绎速。
# Kibana is served by a back end server. This setting specifies the port to use.
#server.port: 5601
# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
#server.host: "localhost"
我們放開端口,放開 server.host焙蚓,并修改如下:
server.port: 5601
server.host: 0.0.0.0
意思是任何人都可以訪問纹冤,然后再次啟動,訪問http://xx.xx.xx.xx:5601主届,出現(xiàn)如下頁面赵哲,說明大功告成。
5.2 Kibana 后臺啟動
當(dāng)使用前臺啟動時君丁,如果我們退出終端枫夺,服務(wù)就會停止,我們可以使用 nohup
命令來啟動绘闷。
[root@izbp163wlhi02tcaxyuxb7z kibana-5.5.3-linux-x86_64]# nohup ./bin/kibana &
nohup
命令:如果你在運行一個進(jìn)程橡庞,你希望在退出賬戶或者關(guān)閉終端時繼續(xù)運行相應(yīng)的進(jìn)程,就可以使用 nohup(no hang up);
該命令格式為:nohup command &
印蔗。
6. Kibana 目錄結(jié)構(gòu)分析
我們查看下 Kibana 的目錄:
[wang@izbp163wlhi02tcaxyuxb7z kibana-5.5.3-linux-x86_64]$ ls
bin config data LICENSE.txt node node_modules NOTICE.txt optimize package.json plugins README.txt src ui_framework webpackShims
- bin:二進(jìn)制腳本扒最,包括 Kibana 啟動 Kibana 服務(wù)和 Kibana-plugin 安裝插件
- config:配置文件,包括 kibana.yml
- data:Kibana 和其插件寫入磁盤的數(shù)據(jù)文件位置
- optimize:編譯過的源碼华嘹。某些管理操作(如插件安裝)導(dǎo)致運行時重新編譯源碼
- plugins:插件文件位置吧趣。每一個插件都有一個單獨的二級目錄