蛤蟆功Elasticsearch——Elasticsearch安装及简单使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dongdong9223/article/details/88692793

转载请注明出处:http://blog.csdn.net/dongdong9223/article/details/88692793
本文出自【我是干勾鱼的博客

Ingredients:

1 下载

创建文件夹:

mkdir -p /opt/elasticsearch/

进入文件夹:

cd /opt/elasticsearch/

下载elasticsearch-6.6.2.tar.gz版本:

wget -c https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.6.2.tar.gz

2 解压缩

tar -zxvf elasticsearch-6.6.2.tar.gz

进入解压后的文件夹:

cd /opt/elasticsearch/elasticsearch-6.6.2/

3 配置

编辑配置文件:

vi config/elasticsearch.yml

加入内容:

network.host: 0.0.0.0

使得可以远程访问。

4 创建es用户并授权

启动Elasticsearch不能使用root用户,而需要使用单独创建的es用户,如下所示:

useradd es
chown -R es:es /opt/elasticsearch/elasticsearch-6.6.2
su es

5 启动

  • 前台启动:
./bin/elasticsearch
  • 后台启动:
./bin/elasticsearch -d

5.1 错误1:不能使用root用户

报错:

[root@shizhi002 bin]# ./elasticsearch
[2019-03-20T17:27:04,155][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [unknown] 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:163) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.6.2.jar:6.6.2]
	at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.6.2.jar:6.6.2]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.6.2.jar:6.6.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
	at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.6.2.jar:6.6.2]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.6.2.jar:6.6.2]
	... 6 more

解决办法:

[root@shizhi002 bin]# useradd es
[root@shizhi002 bin]# chown -R es:es /opt/elasticsearch/elasticsearch-6.6.2
[root@shizhi002 bin]# su es
[es@shizhi002 bin]$ ./elasticsearch

5.2 错误2:文具描述符不够,虚拟内存不够

[2019-03-21T11:23:56,092][INFO ][o.e.b.BootstrapChecks    ] [T92Oci_] bound or publishing to a non-loopback 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]
[2019-03-21T11:23:56,150][INFO ][o.e.n.Node               ] [T92Oci_] stopping ...
[2019-03-21T11:23:56,170][INFO ][o.e.n.Node               ] [T92Oci_] stopped
[2019-03-21T11:23:56,170][INFO ][o.e.n.Node               ] [T92Oci_] closing ...
[2019-03-21T11:23:56,182][INFO ][o.e.n.Node               ] [T92Oci_] closed

这里面有2个错误:

  • 1:文件描述符太少:
[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

解决办法是编辑文件:

vi /etc/security/limits.conf

将原有的:

* hard nofile 65535

修改为:

* hard nofile 65536

配置完需重新启动服务器。

  • 2:虚拟内存太少
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决办法是编辑文件:

vi /etc/sysctl.conf

加入内容:

vm.max_map_count=262144

配置完需重新启动服务器。

5.3 错误3:日志操作权限不够

[es@shizhi002 elasticsearch-6.6.2]$ ./bin/elasticsearch
2019-03-21 13:27:38,165 main ERROR RollingFileManager (/opt/elasticsearch/elasticsearch-6.6.2/logs/elasticsearch.log) java.io.FileNotFoundException: /opt/elasticsearch/elasticsearch-6.6.2/logs/elasticsearch.log (权限不够) java.io.FileNotFoundException: /opt/elasticsearch/elasticsearch-6.6.2/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:114)
	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:145)
	at org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:61)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:123)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:959)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:899)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:891)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:514)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:238)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:250)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:547)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:263)
	at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:234)
	at org.elasticsearch.common.logging.LogConfigurator.configure(LogConfigurator.java:127)
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:302)
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159)
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124)
	at org.elasticsearch.cli.Command.main(Command.java:90)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:116)
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93)

错误原因:有可能你先使用了root用户启动,发现不可以又换成了es用户,这时候其实log日志已经被root用户生成了,权限也为root,这时候就需要再次参考错误1设置权限:

chown -R es:es /opt/elasticsearch/elasticsearch-6.6.2

6 再次启动

再启动就成功了:

[es@shizhi002 elasticsearch-6.6.2]$ ./bin/elasticsearch
[2019-03-21T13:38:06,983][INFO ][o.e.e.NodeEnvironment    ] [T92Oci_] using [1] data paths, mounts [[/ (rootfs)]], net usable_space [42.9gb], net total_space [58.9gb], types [rootfs]
[2019-03-21T13:38:06,987][INFO ][o.e.e.NodeEnvironment    ] [T92Oci_] heap size [1007.3mb], compressed ordinary object pointers [true]
[2019-03-21T13:38:06,988][INFO ][o.e.n.Node               ] [T92Oci_] node name derived from node ID [T92Oci_OR9u4TGpMM-LEUA]; set [node.name] to override
[2019-03-21T13:38:06,989][INFO ][o.e.n.Node               ] [T92Oci_] version[6.6.2], pid[1484], build[default/tar/3bd3e59/2019-03-06T15:16:26.864148Z], 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_162/25.162-b12]
[2019-03-21T13:38:06,989][INFO ][o.e.n.Node               ] [T92Oci_] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -Des.networkaddress.cache.ttl=60, -Des.networkaddress.cache.negative.ttl=10, -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-516840046857408498, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -XX:+PrintGCDetails, -XX:+PrintGCDateStamps, -XX:+PrintTenuringDistribution, -XX:+PrintGCApplicationStoppedTime, -Xloggc:logs/gc.log, -XX:+UseGCLogFileRotation, -XX:NumberOfGCLogFiles=32, -XX:GCLogFileSize=64m, -Des.path.home=/opt/elasticsearch/elasticsearch-6.6.2, -Des.path.conf=/opt/elasticsearch/elasticsearch-6.6.2/config, -Des.distribution.flavor=default, -Des.distribution.type=tar]
[2019-03-21T13:38:09,460][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [aggs-matrix-stats]
[2019-03-21T13:38:09,460][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [analysis-common]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [ingest-common]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [lang-expression]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [lang-mustache]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [lang-painless]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [mapper-extras]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [parent-join]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [percolator]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [rank-eval]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [reindex]
[2019-03-21T13:38:09,461][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [repository-url]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [transport-netty4]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [tribe]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-ccr]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-core]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-deprecation]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-graph]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-ilm]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-logstash]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-ml]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-monitoring]
[2019-03-21T13:38:09,462][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-rollup]
[2019-03-21T13:38:09,463][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-security]
[2019-03-21T13:38:09,463][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-sql]
[2019-03-21T13:38:09,463][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-upgrade]
[2019-03-21T13:38:09,463][INFO ][o.e.p.PluginsService     ] [T92Oci_] loaded module [x-pack-watcher]
[2019-03-21T13:38:09,463][INFO ][o.e.p.PluginsService     ] [T92Oci_] no plugins loaded
[2019-03-21T13:38:14,790][INFO ][o.e.x.s.a.s.FileRolesStore] [T92Oci_] parsed [0] roles from file [/opt/elasticsearch/elasticsearch-6.6.2/config/roles.yml]
[2019-03-21T13:38:15,757][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [T92Oci_] [controller/1546] [Main.cc@109] controller (64 bit): Version 6.6.2 (Build 62531230b275d3) Copyright (c) 2019 Elasticsearch BV
[2019-03-21T13:38:16,570][DEBUG][o.e.a.ActionModule       ] [T92Oci_] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2019-03-21T13:38:16,928][INFO ][o.e.d.DiscoveryModule    ] [T92Oci_] using discovery type [zen] and host providers [settings]
[2019-03-21T13:38:17,925][INFO ][o.e.n.Node               ] [T92Oci_] initialized
[2019-03-21T13:38:17,926][INFO ][o.e.n.Node               ] [T92Oci_] starting ...
[2019-03-21T13:38:18,102][INFO ][o.e.t.TransportService   ] [T92Oci_] publish_address {192.168.0.102:9300}, bound_addresses {0.0.0.0:9300}
[2019-03-21T13:38:18,130][INFO ][o.e.b.BootstrapChecks    ] [T92Oci_] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2019-03-21T13:38:21,245][INFO ][o.e.c.s.MasterService    ] [T92Oci_] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {T92Oci_}{T92Oci_OR9u4TGpMM-LEUA}{l2wQgrDaRwu2W-X7Y3U84w}{192.168.0.102}{192.168.0.102:9300}{ml.machine_memory=3974848512, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}
[2019-03-21T13:38:21,252][INFO ][o.e.c.s.ClusterApplierService] [T92Oci_] new_master {T92Oci_}{T92Oci_OR9u4TGpMM-LEUA}{l2wQgrDaRwu2W-X7Y3U84w}{192.168.0.102}{192.168.0.102:9300}{ml.machine_memory=3974848512, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true}, reason: apply cluster state (from master [master {T92Oci_}{T92Oci_OR9u4TGpMM-LEUA}{l2wQgrDaRwu2W-X7Y3U84w}{192.168.0.102}{192.168.0.102:9300}{ml.machine_memory=3974848512, xpack.installed=true, ml.max_open_jobs=20, ml.enabled=true} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2019-03-21T13:38:21,353][INFO ][o.e.h.n.Netty4HttpServerTransport] [T92Oci_] publish_address {192.168.0.102:9200}, bound_addresses {0.0.0.0:9200}
[2019-03-21T13:38:21,354][INFO ][o.e.n.Node               ] [T92Oci_] started
[2019-03-21T13:38:21,614][WARN ][o.e.x.s.a.s.m.NativeRoleMappingStore] [T92Oci_] Failed to clear cache for realms [[]]
[2019-03-21T13:38:21,684][INFO ][o.e.l.LicenseService     ] [T92Oci_] license [c9077a87-6ac6-401b-85db-8fd8445367bd] mode [basic] - valid
[2019-03-21T13:38:21,696][INFO ][o.e.g.GatewayService     ] [T92Oci_] recovered [0] indices into cluster_state

7 日志监控

tail -f logs/elasticsearch.log 

8 访问浏览器查看

在浏览器中访问服务器,地址为:

http://IP:9200

其中9200是默认端口,当然也可以在配置文件中修改端口。

界面如图所示:

在这里插入图片描述

9 参考

Install Elasticsearch 6.6 with .zip or .tar.gz

Installation

【ElasticSearch】 安装

Elasticsearch部署异常Permission denied

全文搜索引擎 Elasticsearch 入门教程

展开阅读全文

没有更多推荐了,返回首页