elasticsearch-6.2.4安裝
1. jdk環境變量配置
自行百度,這裡不再介紹安裝
2. elasticsearch下載下傳
官網下載下傳elasticsearch
3. 解壓elasticsearch
4. 建立使用者
從5.0開始,ElasticSearch 安全級别提高了,不允許采用root帳号啟動,是以我們要添加一個使用者。
#建立bigdata 使用者組
[[email protected] elasticsearch]# groupadd bigdata
#建立使用者es
[[email protected] elasticsearch]# useradd es
#為es使用者設定密碼es(密碼過段會提示)
[[email protected] elasticsearch]# passwd es
更改使用者 es 的密碼 。
新的 密碼:
無效的密碼: 密碼少于 8 個字元
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。
#将es使用者添加到bigdata組
[[email protected] elasticsearch]# usermod -G bigdata es
#設定sudo權限
[[email protected] elasticsearch]# visudo
#找到root ALL=(ALL) ALL一行,添加es使用者,如下
root ALL=(ALL) ALL
es ALL=(ALL) ALL
#切換使用者
[[email protected] elasticsearch]# su es
[[email protected] elasticsearch]$
5. 修改目錄權限
更改elasticsearch-6.2.4檔案夾以及内部檔案的所屬使用者為es, 使用者組組為bigdata,-R表示逐級(N層目錄)
#注意:如果想建立軟連接配接建議先為源檔案夾設定所屬使用者,并使用root使用者授權後再切換到es使用者下建立軟連接配接操作
[[email protected] elasticsearch]# ll
總用量 255516
drwxr-xr-x. 8 root root 4096 4月 13 2018 elasticsearch-6.2.4
-rw-r--r--. 1 root root 29056810 5月 18 2019 elasticsearch-6.2.4.tar.gz
drwxrwxr-x. 12 1000 root 4096 4月 13 2018 kibana-6.2.4-linux-x86_64
-rw-r--r--. 1 root root 85348919 5月 18 2019 kibana-6.2.4-linux-x86_64.tar.gz
drwxr-xr-x. 11 root root 4096 5月 15 22:17 logstash-6.2.4
-rw-r--r--. 1 root root 147224408 5月 18 2019 logstash-6.2.4.tar.gz
[[email protected] elasticsearch]# sudo chown -R es:bigdata elasticsearch-6.2.4
[[email protected] elasticsearch]# sudo chown -R es:bigdata kibana-6.2.4-linux-x86_64
[[email protected] elasticsearch]# sudo chown -R es:bigdata logstash-6.2.4
[[email protected] elasticsearch]# ll -h
總用量 250M
drwxr-xr-x. 8 es bigdata 4.0K 4月 13 2018 elasticsearch-6.2.4
-rw-r--r--. 1 root root 28M 5月 18 2019 elasticsearch-6.2.4.tar.gz
drwxrwxr-x. 12 es bigdata 4.0K 4月 13 2018 kibana-6.2.4-linux-x86_64
-rw-r--r--. 1 root root 82M 5月 18 2019 kibana-6.2.4-linux-x86_64.tar.gz
drwxr-xr-x. 11 es bigdata 4.0K 5月 15 22:17 logstash-6.2.4
-rw-r--r--. 1 root root 141M 5月 18 2019 logstash-6.2.4.tar.gz
#建立軟連接配接
[[email protected] elasticsearch]$ ln -s /home/bag/elasticsearch/elasticsearch-6.2.4 /home/soft/elasticsearch/elasticsearch
[[email protected] elasticsearch]$ ln -s /home/bag/elasticsearch/kibana-6.2.4-linux-x86_64 /home/soft/elasticsearch/kibana
[[email protected] elasticsearch]$ ln -s /home/bag/elasticsearch/logstash-6.2.4 /home/soft/elasticsearch/logstash
[[email protected] elasticsearch]$
6. ElasticSearch 配置
6.1 修改elasticsearch.yml
進入到elasticsearch的config目錄下然後vim elasticsearch.yml
#修改network.host和http.port
#network.host為目前伺服器ip
network.host: 192.168.221.5
http.port: 9200
6.2 修改/etc/sysctl.conf
切換到root使用者
[[email protected] elasticsearch]# vim /etc/sysctl.conf
#添加如下内容
vm.max_map_count=655360
6.3 修改/etc/security/limits.conf
切換到root使用者
#添加如下内容
* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096
# End of file
7. ElasticSearch啟動與停止
7.1 注意切換到es使用者下,進入到elasticsearch根目錄下執行
[es@master bin]$ ./elasticsearch
[2019-05-15T23:04:30,213][INFO ][o.e.n.Node ] [] initializing ...
[2019-05-15T23:04:30,326][INFO ][o.e.e.NodeEnvironment ] [7UhuTlZ] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [36.8gb], net total_space [45.4gb], types [rootfs]
[2019-05-15T23:04:30,326][INFO ][o.e.e.NodeEnvironment ] [7UhuTlZ] heap size [1007.3mb], compressed ordinary object pointers [true]
[2019-05-15T23:04:30,327][INFO ][o.e.n.Node ] node name [7UhuTlZ] derived from node ID [7UhuTlZPRwW_eqHCeSDiyw]; set [node.name] to override
[2019-05-15T23:04:30,328][INFO ][o.e.n.Node ] version[6.2.4], pid[14938], build[ccec39f/2018-04-12T20:37:28.497551Z], OS[Linux/3.10.0-957.10.1.el7.x86_64/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_73/25.73-b02]
[2019-05-15T23:04:30,328][INFO ][o.e.n.Node ] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.1eylfCCc, -XX:+HeapDumpOnOutOfMemoryError, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/home/soft/elasticsearch/elasticsearch, -Des.path.conf=/home/soft/elasticsearch/elasticsearch/config]
[2019-05-15T23:04:31,290][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [aggs-matrix-stats]
[2019-05-15T23:04:31,290][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [analysis-common]
[2019-05-15T23:04:31,290][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [ingest-common]
[2019-05-15T23:04:31,290][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [lang-expression]
[2019-05-15T23:04:31,290][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [lang-mustache]
[2019-05-15T23:04:31,290][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [lang-painless]
[2019-05-15T23:04:31,291][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [mapper-extras]
[2019-05-15T23:04:31,291][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [parent-join]
[2019-05-15T23:04:31,291][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [percolator]
[2019-05-15T23:04:31,291][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [rank-eval]
[2019-05-15T23:04:31,291][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [reindex]
[2019-05-15T23:04:31,291][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [repository-url]
[2019-05-15T23:04:31,291][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [transport-netty4]
[2019-05-15T23:04:31,291][INFO ][o.e.p.PluginsService ] [7UhuTlZ] loaded module [tribe]
[2019-05-15T23:04:31,292][INFO ][o.e.p.PluginsService ] [7UhuTlZ] no plugins loaded
[2019-05-15T23:04:34,359][INFO ][o.e.d.DiscoveryModule ] [7UhuTlZ] using discovery type [zen]
[2019-05-15T23:04:35,411][INFO ][o.e.n.Node ] initialized
[2019-05-15T23:04:35,411][INFO ][o.e.n.Node ] [7UhuTlZ] starting ...
[2019-05-15T23:04:35,905][INFO ][o.e.t.TransportService ] [7UhuTlZ] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2019-05-15T23:04:35,935][WARN ][o.e.b.BootstrapChecks ] [7UhuTlZ] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2019-05-15T23:04:39,137][INFO ][o.e.c.s.MasterService ] [7UhuTlZ] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {7UhuTlZ}{7UhuTlZPRwW_eqHCeSDiyw}{0rZ3zuJGQku_rMaO_oPr4w}{127.0.0.1}{127.0.0.1:9300}
[2019-05-15T23:04:39,162][INFO ][o.e.c.s.ClusterApplierService] [7UhuTlZ] new_master {7UhuTlZ}{7UhuTlZPRwW_eqHCeSDiyw}{0rZ3zuJGQku_rMaO_oPr4w}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {7UhuTlZ}{7UhuTlZPRwW_eqHCeSDiyw}{0rZ3zuJGQku_rMaO_oPr4w}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2019-05-15T23:04:39,224][INFO ][o.e.g.GatewayService ] [7UhuTlZ] recovered [0] indices into cluster_state
[2019-05-15T23:04:39,239][INFO ][o.e.h.n.Netty4HttpServerTransport] [7UhuTlZ] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-05-15T23:04:39,239][INFO ][o.e.n.Node ] [7UhuTlZ] started
#出現started時表示啟動成功
7.2 背景運作
可以通過參數-d背景運作
[[email protected] bin]$ ./elasticsearch -d
[[email protected] bin]$ ps -ef|grep elastic
es 15525 1 99 23:15 pts/0 00:00:15 /home/bag/jdk/jdk1.8.0_73/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch.QTWS3OR9 -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/soft/elasticsearch/elasticsearch -Des.path.conf=/home/soft/elasticsearch/elasticsearch/config -cp /home/soft/elasticsearch/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es 15572 13536 0 23:15 pts/0 00:00:00 grep --color=auto elastic
7.3 檢視背景運作日志
[[email protected] bin]$ ll
總用量 256
-rwxr-xr-x. 1 es bigdata 1557 4月 13 2018 elasticsearch
-rw-r--r--. 1 es bigdata 1431 4月 13 2018 elasticsearch.bat
-rwxr-xr-x. 1 es bigdata 2238 4月 13 2018 elasticsearch-env
-rw-r--r--. 1 es bigdata 1713 4月 13 2018 elasticsearch-env.bat
-rwxr-xr-x. 1 es bigdata 239 4月 13 2018 elasticsearch-keystore
-rw-r--r--. 1 es bigdata 329 4月 13 2018 elasticsearch-keystore.bat
-rwxr-xr-x. 1 es bigdata 229 4月 13 2018 elasticsearch-plugin
-rw-r--r--. 1 es bigdata 319 4月 13 2018 elasticsearch-plugin.bat
-rw-r--r--. 1 es bigdata 8018 4月 13 2018 elasticsearch-service.bat
-rw-r--r--. 1 es bigdata 104448 4月 13 2018 elasticsearch-service-mgr.exe
-rw-r--r--. 1 es bigdata 103936 4月 13 2018 elasticsearch-service-x64.exe
-rwxr-xr-x. 1 es bigdata 242 4月 13 2018 elasticsearch-translog
-rw-r--r--. 1 es bigdata 332 4月 13 2018 elasticsearch-translog.bat
[[email protected] bin]$ pwd
/home/soft/elasticsearch/elasticsearch/bin
[[email protected] bin]$ cd ../logs/
[[email protected] logs]$ ll
總用量 40
-rw-rw-r--. 1 es es 0 5月 15 23:04 elasticsearch_deprecation.log
-rw-rw-r--. 1 es es 0 5月 15 23:04 elasticsearch_index_indexing_slowlog.log
-rw-rw-r--. 1 es es 0 5月 15 23:04 elasticsearch_index_search_slowlog.log
-rw-rw-r--. 1 es es 9724 5月 15 23:15 elasticsearch.log
-rw-rw-r--. 1 es es 28388 5月 15 23:15 gc.log.0.current
[[email protected] logs]$ tail -f elasticsearch.log
[2019-05-15T23:15:24,610][INFO ][o.e.d.DiscoveryModule ] [7UhuTlZ] using discovery type [zen]
[2019-05-15T23:15:25,930][INFO ][o.e.n.Node ] initialized
[2019-05-15T23:15:25,931][INFO ][o.e.n.Node ] [7UhuTlZ] starting ...
[2019-05-15T23:15:26,412][INFO ][o.e.t.TransportService ] [7UhuTlZ] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2019-05-15T23:15:26,443][WARN ][o.e.b.BootstrapChecks ] [7UhuTlZ] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2019-05-15T23:15:29,600][INFO ][o.e.c.s.MasterService ] [7UhuTlZ] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {7UhuTlZ}{7UhuTlZPRwW_eqHCeSDiyw}{UCEvAHvFT8a5N8H-vBoDsQ}{127.0.0.1}{127.0.0.1:9300}
[2019-05-15T23:15:29,605][INFO ][o.e.c.s.ClusterApplierService] [7UhuTlZ] new_master {7UhuTlZ}{7UhuTlZPRwW_eqHCeSDiyw}{UCEvAHvFT8a5N8H-vBoDsQ}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {7UhuTlZ}{7UhuTlZPRwW_eqHCeSDiyw}{UCEvAHvFT8a5N8H-vBoDsQ}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2019-05-15T23:15:29,645][INFO ][o.e.g.GatewayService ] [7UhuTlZ] recovered [0] indices into cluster_state
[2019-05-15T23:15:29,648][INFO ][o.e.h.n.Netty4HttpServerTransport] [7UhuTlZ] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2019-05-15T23:15:29,648][INFO ][o.e.n.Node ] [7UhuTlZ] started
7.4 檢視elasticsearch程序
[[email protected] logs]$ ps -ef|grep elasticsearch
es 15525 1 9 23:15 pts/0 00:00:16 /home/bag/jdk/jdk1.8.0_73/bin/java -Xms1g -Xmx1g -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch.QTWS3OR9 -XX:+HeapDumpOnOutOfMemoryError -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/home/soft/elasticsearch/elasticsearch -Des.path.conf=/home/soft/elasticsearch/elasticsearch/config -cp /home/soft/elasticsearch/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es 15716 13536 0 23:18 pts/0 00:00:00 grep --color=auto elasticsearch
#或者使用jps指令,注意需要安裝oracleJdk,openJdk貌似沒有這個指令
[[email protected] logs]$ jps
15525 Elasticsearch
15717 Jps
[[email protected] logs]$
7.5 驗證是否成功
7.5.1 使用curl驗證
[[email protected] bin]$ curl 192.168.221.5:9200
{
"name" : "7UhuTlZ",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "jLL1IiEWQquz_3RX6Y_Raw",
"version" : {
"number" : "6.2.4",
"build_hash" : "ccec39f",
"build_date" : "2018-04-12T20:37:28.497551Z",
"build_snapshot" : false,
"lucene_version" : "7.2.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
7.5.2 浏覽器驗證
8. 常見錯誤
8.1 org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
這個錯誤,是因為使用root使用者啟動elasticsearch,切換到es使用者下執行即可
[[email protected] bin]# ./elasticsearch
[2019-05-15T22:53:17,198][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:125) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.2.4.jar:6.2.4]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.2.4.jar:6.2.4]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.2.4.jar:6.2.4]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:105) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:172) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:323) ~[elasticsearch-6.2.4.jar:6.2.4]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.2.4.jar:6.2.4]
... 6 more
[[email protected] bin]#
8.2 權限不夠
重新解壓elasticsearch-6.2.4.tar.gz并為解壓後的檔案夾設定所屬組
[[email protected] bin]$ ./elasticsearch
Java HotSpot(TM) 64-Bit Server VM warning: Cannot open file logs/gc.log due to Permission denied
2019-05-15 22:55:48,533 main ERROR RollingFileManager (/home/soft/elasticsearch/elasticsearch/logs/elasticsearch.log) java.io.FileNotFoundException: /home/soft/elasticsearch/elasticsearch/logs/elasticsearch.log (權限不夠) java.io.FileNotFoundException: /home/soft/elasticsearch/elasticsearch/logs/elasticsearch.log (權限不夠)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(FileOutputStream.java:270)
at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
at java.io.FileOutputStream.<init>(FileOutputStream.java:133)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:640)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager$RollingFileManagerFactory.createManager(RollingFileManager.java:608)
at org.apache.logging.log4j.core.appender.AbstractManager.getManager(AbstractManager.java:113)
at org.apache.logging.log4j.core.appender.OutputStreamManager.getManager(OutputStreamManager.java:115)
at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:188)
at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:144)
at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:60)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
8.3 max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
原因:普通使用者執行問題
解決:切換到root使用者,編輯/etc/security/limits.conf,添加
es hard nofile 65536
es soft nofile 65536
(es是使用者名)或者寫成*
8.4 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
原因:作業系統的vm.max_map_count參數設定太小導緻的
解決:切換超級使用者,編輯/etc/sysctl.conf
添加 vm.max_map_count=655360
儲存退出,執行 sysctl -p