linux 安装、启动 Elasticsearch6.4.2 详细步骤以及问题解决方案

第一步:环境

linux 系统 Java 1.8.0_141 elasticsearch-6.4.2

第二步:下载

2.1 JDK的下载可以去官网上直接下载,再次声明一下不要下载最新版本 JAVA 9 版本本人在次已经踩过坑了

2.2 ES 去官网直接下载,本人使用的是 5.6.3 版本;因为版本的不同安装head插件的时候安装步骤不同;好像是从5.0 以后的版本安装head 插件的步骤就不一样了;下面会详细介绍。

第三步:安装

3.1安装JDK环境

前提:查看该系统是否安装过Java 环境,如果安装过将其卸载安装最新的版本,更换Java 的版本也可以这样去操作。

3.1.1 执行命令 rpm -qa|grep jdk 如果安装过将会列出相应的版本,如果没有什么都不会输出。如果安装过使用rpm -e --nodeps java-1.7.0-openjdk-headless-1.7.0.111-2.6.7.2.el7_2.x86_64 使用这个命令需要注意的就是,列出多少个版本插件就要卸载几个插件;执行完成后;在使用 rpm -qa|grep jdk 去查看一下是否有遗漏的插件没有卸载。

3.1.2 直接将下载好的jdk-8u151-linux-x64.rpm 安装包 ;上传到自己创建好的JAVA文件下;cd 命令进入到JAVA文件下使用rpm 命令进行安装 rpm -ivh jdk-8u131-linux-x64.rpm 安装完成后执行 java -version 命令查看安装是否成功

3.1.3 查看安装目录命令,

  命令一:which java 

  命令二:ls -lrt /usr/bin/java

  命令三:ls -lrt /etc/alternatives/java

  最后将会得出这样的目录 /usr/java/jdk1.8.0_151/jre/bin/java

3.1.4 配置环境变量,执行命令 vi /etc/profile;然后进入编辑模式,在文件的最后添加下面的配置,如图

  JAVA_HOME=/usr/javajdk1.8.0_151
  JRE_HOME=/usr/java/jdk1.8.0_151/jre
  CLASSPATH=$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
  PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

修改完配置后,使用Esc 键退出,输入:wq 保存并退出

3.1.5 执行命令 source /etc/profile 使用环境变量生效

3.1.6 验证环境变量是否生效,分别执行下面的命令echo $JAVA_HOME echo $CLASSPATH echo $PATH

OK,JDK就这样安装好了。

上面的步骤我没有做,因为已经好了,所以当个参考吧;

3.2安装ES

 3.2.1 下载ES安装包:https://www.elastic.co/cn/downloads/elasticsearch

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.2.tar.gz
将安装包上传到里面,解压 并 进入 文件里面

解压:

gunzip elasticsearch-6.4.2.tar.gz

tar -xvf elasticsearch-6.4.2.tar
3.2.2 创建ES用户和组(创建elsearch用户组及elsearch用户),因为使用root用户执行ES程序,将会出现错误;所以这里需要创建单独的用户去执行ES 文件;命令如下:

命令一:groupadd elsearch

命令二:useradd elsearch -g elsearch

命令三:chown -R elsearch:elsearch elasticsearch-6.4.2 该命令是更改该文件夹下所属的用户组的权限

3.2.4 创建ES数据文件和日志文件,直接在root用户根目录一下创建就可以了(这个要和下一步配置的里面的路径相同)

  执行命令:mkdir /path

  命令二:chown -R elsearch:elsearch /path/

  命令三:su - elsearch 切换用户

  命令四:mkdir -p to/data

  命令五:mkdir -p to/logs

3.2.5 修改ES配置文件,使用cd命令进入到config 文件下,执行 vi elasticsearch.yml 命令,如图所示,本人没有配置集群,只是简单的配置了一下;详细说明可以参考官网;

======================== 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):

======================== 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: false

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: (此处是本机IP)

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 new node is started:

The default list of hosts is [“127.0.0.1”, “[::1]”]

#discovery.zen.ping.unicast.hosts: [“host1”, “host2”]

Prevent the “split brain” by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):

#discovery.zen.minimum_master_nodes:

For more information, consult the zen discovery 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

3.2.6 执行ES文件,进入到bin 目录下执行 ./elasticsearch 命令就可以了,执行 ./elasticesrarch -d 是后台运行

  如果没有什么问题话,就可以安全生成了;然后执行curl 'http://自己配置的IP地址:9200/' 命令,就出现下面的结果

遇到的问题:

报错1:

org.elasticsearch.bootstrap.StartupException: BindTransportException[Failed to bind to [9300-9400]]; nested: BindException[Cannot assign requested address];
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:140) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:127) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.4.2.jar:6.4.2]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.4.2.jar:6.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:93) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:86) ~[elasticsearch-6.4.2.jar:6.4.2]
Caused by: org.elasticsearch.transport.BindTransportException: Failed to bind to [9300-9400]
at org.elasticsearch.transport.TcpTransport.bindToPort(TcpTransport.java:821) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.transport.TcpTransport.bindServer(TcpTransport.java:786) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.transport.netty4.Netty4Transport.doStart(Netty4Transport.java:134) ~[?:?]
at org.elasticsearch.xpack.core.security.transport.netty4.SecurityNetty4Transport.doStart(SecurityNetty4Transport.java:87) ~[?:?]
at org.elasticsearch.xpack.security.transport.netty4.SecurityNetty4ServerTransport.doStart(SecurityNetty4ServerTransport.java:41) ~[?:?]
at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:66) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.transport.TransportService.doStart(TransportService.java:217) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.common.component.AbstractLifecycleComponent.start(AbstractLifecycleComponent.java:66) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.node.Node.start(Node.java:667) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.bootstrap.Bootstrap.start(Bootstrap.java:265) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:335) ~[elasticsearch-6.4.2.jar:6.4.2]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:136) ~[elasticsearch-6.4.2.jar:6.4.2]
… 6 more
Caused by: java.net.BindException: Cannot assign requested address
at sun.nio.ch.Net.bind0(Native Method) ~[?:?]
at sun.nio.ch.Net.bind(Net.java:433) ~[?:?]
at sun.nio.ch.Net.bind(Net.java:425) ~[?:?]
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[?:?]
at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:128) ~[?:?]
at io.netty.channel.AbstractChannel A b s t r a c t U n s a f e . b i n d ( A b s t r a c t C h a n n e l . j a v a : 558 )   [ ? : ? ] a t i o . n e t t y . c h a n n e l . D e f a u l t C h a n n e l P i p e l i n e AbstractUnsafe.bind(AbstractChannel.java:558) ~[?:?] at io.netty.channel.DefaultChannelPipeline AbstractUnsafe.bind(AbstractChannel.java:558) [?:?]atio.netty.channel.DefaultChannelPipelineHeadContext.bind(DefaultChannelPipeline.java:1283) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501) ~[?:?]
at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486) ~[?:?]
at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:989) ~[?:?]
at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254) ~[?:?]
at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:365) ~[?:?]
at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[?:?]
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403) ~[?:?]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463) ~[?:?]
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[?:?]
at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]
[2018-11-01T08:05:01,755][INFO ][o.e.n.Node ] [node-1] stopping …
[2018-11-01T08:05:01,758][INFO ][o.e.n.Node ] [node-1] stopped
[2018-11-01T08:05:01,758][INFO ][o.e.n.Node ] [node-1] closing …
[2018-11-01T08:05:01,767][INFO ][o.e.n.Node ] [node-1] closed

解决方案:network.host: (本机IP)
此处的IP是本机IP,这个错的原因是本机IP写错了;

参考:https://www.jianshu.com/p/8ab9fe3d3481

报错二:

ERROR: [3] bootstrap checks failed
[1]: max file descriptors [10240] for elasticsearch process is too low, increase to at least [65536]
解决方案:bootstrap.memory_lock: false

这个地方默认是true,改一下就好了;

如果还是有这样的问题

编辑 /etc/security/limits.conf
在文件最后添加

  • soft nofile 65536
  • hard nofile 65536
    保存

此文件修改后需要重新登录用户,才会生效

报错三:

[2]: memory locking requested for elasticsearch process but memory is not locked
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
问题翻译过来就是:elasticsearch用户拥有的内存权限太小,至少需要262144;

解决:

切换到root用户

执行命令:

sysctl -w vm.max_map_count=262144

查看结果:

sysctl -a|grep vm.max_map_count

显示:

vm.max_map_count = 262144

上述方法修改之后,如果重启虚拟机将失效,所以:

解决办法:

在 /etc/sysctl.conf文件最后添加一行

vm.max_map_count=262144

即可永久修改

小材料:

1、lsof -i:端口号

2、netstat -tunlp|grep 端口号

杀ES进程:

使用命令kill杀掉服务器的ES进程即可
1.查找ES进程

ps -ef | grep elastic

2.杀掉ES进程

kill -9 2382(进程号)

3.重启ES

sh elasticsearch -d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值