CentOS7.6安装ElasticsSerach7.2.1教程
先上配置文件信息:
# ======================== 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
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# 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 to log files:
#
#path.logs: /path/to/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
#这里设置es可以被外部访问
network.host: 0.0.0.0
#
# 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 this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#集群初始化主节点的个数,这里设置一个主节点node-1
cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation 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
下面介绍错误解决信息
首先es7.2.1是不能使用root角色启动的,你需要创建一个角色然后给那个角色授予es7.2.1目录的权限
//创建一个用户esTest
adduser esTest
//授予用户esTest文件夹 elasticsearch-7.2.1/下所有文件的权限
chown -R esTest elasticsearch-7.2.1/
可能出现的错误_1:
[learner@centos7 bin]$ ./elasticsearch
future versions of Elasticsearch will require Java 11; your Java version from [/export/server/jdk1.8.0_11/jre] does not meet this requirement
[2020-04-22T16:29:14,034][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [centos7.jackhui] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: failed to obtain node locks, tried [[/export/server/elasticsearch-7.2.1/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-7.2.1.jar:7.2.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-7.2.1.jar:7.2.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-7.2.1.jar:7.2.1]
Caused by: java.lang.IllegalStateException: failed to obtain node locks, tried [[/export/server/elasticsearch-7.2.1/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])?
at org.elasticsearch.env.NodeEnvironment.<init>(NodeEnvironment.java:298) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.node.Node.<init>(Node.java:271) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.node.Node.<init>(Node.java:251) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.bootstrap.Bootstrap$5.<init>(Bootstrap.java:221) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:221) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:349) ~[elasticsearch-7.2.1.jar:7.2.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-7.2.1.jar:7.2.1]
解决方案
这个错误是应为你上次启动的es没有关闭
使用命令 ps aux|grep elastics 查看es的进程:
[root@centos7 server]# ps aux|grep elastics
learner 60948 1.5 33.4 3728260 1291788 pts/0 Sl+ 16:39 0:32 /export/server/jdk1.8.0_11/bin/java -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-8351244307289280952 -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 -Dio.netty.allocator.type=unpooled -XX:MaxDirectMemorySize=536870912 -Des.path.home=/export/server/elasticsearch-7.2.1 -Des.path.conf=/export/server/elasticsearch-7.2.1/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /export/server/elasticsearch-7.2.1/lib/* org.elasticsearch.bootstrap.Elasticsearch
learner 61024 0.0 0.1 68772 5524 pts/0 Sl+ 16:39 0:00 /export/server/elasticsearch-7.2.1/modules/x-pack-ml/platform/linux-x86_64/bin/controller
root 61673 0.0 0.0 112712 960 pts/1 S+ 17:13 0:00 grep --color=auto elastics
[root@centos7 server]#
这里看到es的进程号为60948
使用 kill -9 60948来杀死这个进程
可能出现的错误_2:
[2020-04-22T16:32:40,795][INFO ][o.e.x.m.p.l.CppLogMessageHandler] [centos7.jackhui] [controller/60606] [Main.cc@110] controller (64 bit): Version 7.2.1 (Build 4ad685337be7fd) Copyright (c) 2019 Elasticsearch BV
[2020-04-22T16:32:41,323][DEBUG][o.e.a.ActionModule ] [centos7.jackhui] Using REST wrapper from plugin org.elasticsearch.xpack.security.Security
[2020-04-22T16:32:41,693][INFO ][o.e.d.DiscoveryModule ] [centos7.jackhui] using discovery type [zen] and seed hosts providers [settings]
[2020-04-22T16:32:42,762][INFO ][o.e.n.Node ] [centos7.jackhui] initialized
[2020-04-22T16:32:42,763][INFO ][o.e.n.Node ] [centos7.jackhui] starting ...
[2020-04-22T16:32:42,977][INFO ][o.e.t.TransportService ] [centos7.jackhui] publish_address {192.168.187.128:9300}, bound_addresses {[::]:9300}
[2020-04-22T16:32:42,994][INFO ][o.e.b.BootstrapChecks ] [centos7.jackhui] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-04-22T16:32:43,038][INFO ][o.e.n.Node ] [centos7.jackhui] stopping ...
[2020-04-22T16:32:43,072][INFO ][o.e.n.Node ] [centos7.jackhui] stopped
[2020-04-22T16:32:43,072][INFO ][o.e.n.Node ] [centos7.jackhui] closing ...
[2020-04-22T16:32:43,093][INFO ][o.e.n.Node ] [centos7.jackhui] closed
[2020-04-22T16:32:43,098][INFO ][o.e.x.m.p.NativeController] [centos7.jackhui] Native controller process has stopped - no new native processes can be started
解决方案
以上错误解决方法:
vim /etc/security/limits.conf 打开此配置文件
在# End of file之前添加以下数据
* soft nofile 655360
* hard nofile 655360
* soft nproc 4096
* hard nproc 4096
vi /etc/sysctl.conf 打开此配置文件
在末尾添加此配置
vm.max_map_count=655360
执行命令sysctl -p使配置生效(此命令需要root角色执行)
最后切换成刚刚创建的用户esTest启动es就可以了