ElasticSearch(一)CentOs6.4下安装Elas

2019-05-07  本文已影响0人  minner_01

一、准备工作

Elastic 需要 Java 8 环境。如果你的机器还没安装 Java,先需要安装java环境,同时还注意要保证环境变量JAVA_HOME正确设置。

下载地址:
https://pan.baidu.com/s/1kGHTtXbM1URHVz5dQQiwbg 
提取码:ktxi 

习惯性下载到/usr/local/src目录下,解压并创建软连接,方便配置环境变量

#tar zxf jdk-8u91-linux-x64.tar.gz -C /usr/local/  //解压
#ln –s /usr/local/jdk1.8.0_91 /usr/local/jdk       //创建软连接
# vim /etc/profile                    //把下面三行代码放在底部
export JAVA_HOME=/usr/local/jdk
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
# source /etc/profile                    //编辑完成之后执行命令生效

二、配置安装ElasticSearch(这里是源码包方式安装版本elasticsearch-2.4.1,rpm包形式安装)

下载

wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.4.1/elasticsearch-2.4.1.rpm 

安装

# yum -y install elasticsearch-2.4.1.rpm  

修改配置文件

# vim /etc/elasticsearch/elasticsearch.yml

#集群名称
cluster.name: my-application
#节点名称
node.name: node-1
#数据存储路径
path.data: /var/lib/elasticsearch
#日志存储路径
path.logs: /var/log/elasticsearch
#将来访问elastic的话,都是通过API访问,在这我们要提供一个http主机地址,这里就是本机IP
network.host: 192.168.9.155  
#默认端口
http.port: 9200

启动ElasticSearch

#servicc elasticsearch start //启动测试

这里遇到了几个错误~

[2018-01-11T09:48:34,177][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 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-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.cli.SettingCommand.execute(SettingCommand.java:54) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:89) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:82) ~[elasticsearch-5.1.2.jar:5.1.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
    at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:100) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:176) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:306) ~[elasticsearch-5.1.2.jar:5.1.2]
    at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-5.1.2.jar:5.1.2]
    ... 6 more

解决(创建新用户)

#groupadd elasticsearch
#useradd elasticsearch -g elasticsearch -p elasticsearch
#cd /opt
#chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
[2018-01-11T09:55:14,892][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty4]
[2018-01-11T09:55:14,894][INFO ][o.e.p.PluginsService     ] [node-1] no plugins loaded
[2018-01-11T09:55:35,673][INFO ][o.e.n.Node               ] [node-1] initialized
[2018-01-11T09:55:35,674][INFO ][o.e.n.Node               ] [node-1] starting ...
[2018-01-11T09:55:35,278][INFO ][o.e.t.TransportService   ] [node-1] publish_address {192.168.9.149:9300}, bound_addresses {192.168.9.149:9300}
[2018-01-11T09:55:35,288][INFO ][o.e.b.BootstrapCheck     ] [node-1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: bootstrap checks failed
max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-01-11T09:55:35,336][INFO ][o.e.n.Node               ] [node-1] stopping ...
[2018-01-11T09:55:35,399][INFO ][o.e.n.Node               ] [node-1] stopped
[2018-01-11T09:55:35,399][INFO ][o.e.n.Node               ] [node-1] closing ...
[2018-01-11T09:55:35,461][INFO ][o.e.n.Node               ] [node-1] closed

①解决max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]。记住root用户修改完文件,切换到elasticsearch用户启动服务时,还会报错,记得一定再切换root,再切回elasticsearch用户启动方可成功

#vim  /etc/security/limits.conf //在底部添加两行代码,让人需要切换到root用户哦
* soft nofile 65536
* hard nofile 65536

②解决max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

# vim  /etc/security/limits.conf       //添加下面一行
vm.max_map_count=655360             //添加此行
#sysctl -p                                //添加完成执行此命令

切换到elasticsearch用户重新启动服务,返回下面提示即表示成功~

[2018-01-11T09:59:30,435][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty3]
[2018-01-11T09:59:30,435][INFO ][o.e.p.PluginsService     ] [node-1] loaded module [transport-netty4]
[2018-01-11T09:59:30,437][INFO ][o.e.p.PluginsService     ] [node-1] no plugins loaded
[2018-01-11T09:59:38,364][INFO ][o.e.n.Node               ] [node-1] initialized
[2018-01-11T09:59:38,364][INFO ][o.e.n.Node               ] [node-1] starting ...
[2018-01-11T09:13:38,903][INFO ][o.e.t.TransportService   ] [node-1] publish_address {192.168.9.149:9300}, bound_addresses {192.168.9.149:9300}
[2018-01-11T09:59:38,912][INFO ][o.e.b.BootstrapCheck     ] [node-1] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2018-01-11T09:59:45,164][INFO ][o.e.c.s.ClusterService   ] [node-1] new_master {node-1}{Tjz6HoyoR1KhuIuhE7A8FA}{CTQ4R5bjQ02yNoPlUwasQw}{192.168.9.149}{192.168.9.149:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-01-11T09:59:45,268][INFO ][o.e.h.HttpServer         ] [node-1] publish_address {192.168.9.149:9200}, bound_addresses {192.168.9.149:9200}
[2018-01-11T09:59:45,268][INFO ][o.e.n.Node               ] [node-1] started
[2018-01-11T09:59:45,301][INFO ][o.e.g.GatewayService     ] [node-1] recovered [0] indices into cluster_state
which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)
Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME

解决办法:

# vim /etc/sysconfig/elasticsearch  //添加下面一行到末尾
JAVA_HOME=/usr/local/jdk

OK~~启动成功

# service elasticsearch start
Starting elasticsearch:                                    [  OK  ]

试着curl访问


11.png

关掉防火墙浏览器访问


12.png
上一篇下一篇

猜你喜欢

热点阅读