自行百度,这里不再介绍安装
[root@master elasticsearch]# tar -zxvf elasticsearch-6.2.4.tar.gz
从5.0开始,ElasticSearch 安全级别提高了,不允许采用root帐号启动,所以我们要添加一个用户。
#创建bigdata 用户组
[root@master elasticsearch]# groupadd bigdata
#创建用户es
[root@master elasticsearch]# useradd es
#为es用户设置密码es(密码过段会提示)
[root@master elasticsearch]# passwd es
更改用户 es 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
#将es用户添加到bigdata组
[root@master elasticsearch]# usermod -G bigdata es
#设置sudo权限
[root@master elasticsearch]# visudo
#找到root ALL=(ALL) ALL一行,添加es用户,如下
root ALL=(ALL) ALL
es ALL=(ALL) ALL
#切换用户
[root@master elasticsearch]# su es
[es@master elasticsearch]$
更改elasticsearch-6.2.4文件夹以及内部文件的所属用户为es, 用户组组为bigdata,-R表示逐级(N层目录)
#注意:如果想创建软连接建议先为源文件夹设置所属用户,并使用root用户授权后再切换到es用户下创建软连接操作
[root@master 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
[root@master elasticsearch]# sudo chown -R es:bigdata elasticsearch-6.2.4
[root@master elasticsearch]# sudo chown -R es:bigdata kibana-6.2.4-linux-x86_64
[root@master elasticsearch]# sudo chown -R es:bigdata logstash-6.2.4
[root@master 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
#创建软连接
[es@master elasticsearch]$ ln -s /home/bag/elasticsearch/elasticsearch-6.2.4 /home/soft/elasticsearch/elasticsearch
[es@master elasticsearch]$ ln -s /home/bag/elasticsearch/kibana-6.2.4-linux-x86_64 /home/soft/elasticsearch/kibana
[es@master elasticsearch]$ ln -s /home/bag/elasticsearch/logstash-6.2.4 /home/soft/elasticsearch/logstash
[es@master elasticsearch]$
进入到elasticsearch的config目录下然后vim elasticsearch.yml
#修改network.host和http.port
#network.host为当前服务器ip
network.host: 192.168.221.5
http.port: 9200
切换到root用户
[root@master elasticsearch]# vim /etc/sysctl.conf
#添加如下内容
vm.max_map_count=655360
切换到root用户
#添加如下内容
* hard nofile 65536
* soft nofile 65536
* soft nproc 2048
* hard nproc 4096
# End of file
[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时表示启动成功
可以通过参数-d后台运行
[es@master bin]$ ./elasticsearch -d
[es@master 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
[es@master 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
[es@master bin]$ pwd
/home/soft/elasticsearch/elasticsearch/bin
[es@master bin]$ cd ../logs/
[es@master 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
[es@master 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
[es@master 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貌似没有这个命令
[es@master logs]$ jps
15525 Elasticsearch
15717 Jps
[es@master logs]$
[es@master 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"
}
这个错误,是因为使用root用户启动elasticsearch,切换到es用户下执行即可
[root@master 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
[root@master bin]#
重新解压elasticsearch-6.2.4.tar.gz并为解压后的文件夹设置所属组
[es@master 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)
原因:普通用户执行问题
解决:切换到root用户,编辑/etc/security/limits.conf,添加
es hard nofile 65536
es soft nofile 65536
(es是用户名)或者写成*
原因:操作系统的vm.max_map_count参数设置太小导致的
解决:切换超级用户,编辑/etc/sysctl.conf
添加 vm.max_map_count=655360
保存退出,执行 sysctl -p