美文网首页
一、ElasticSearch安装

一、ElasticSearch安装

作者: 缘木与鱼 | 来源:发表于2020-09-27 14:24 被阅读0次

ElasticSearch (1) 安装

1、安装

前提:ElasticSearch 是java实现的,需要提前在环境中安装jre。

1.1 下载 ElasticSearch

ElasticSearch 官网

下载地址

因为安装在centos的环境中,所以下载tar.gz的安装包, 本次使用使用5.5.2版本:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.2.tar.gz
tar -zxvf elasticsearch-5.5.2.tar.gz

解压后得到 elasticsearch-5.5.2 目录。

1.2 启动elasticsearch

启动的是bin目录下的elasticsearch, 使用 sh elasticsearch 即可。

启动日志如下:

[root@localhost elasticsearch]# cd elasticsearch-5.5.2
[root@localhost elasticsearch-5.5.2]# ll
total 224
drwxr-xr-x  2 root root   4096 Sep 25 17:47 bin
drwxr-xr-x  2 root root     75 Aug 14  2017 config
drwxr-xr-x  2 root root   4096 Aug 14  2017 lib
-rw-r--r--  1 root root  11358 Aug 14  2017 LICENSE.txt
drwxr-xr-x 13 root root    236 Aug 14  2017 modules
-rw-r--r--  1 root root 194187 Aug 14  2017 NOTICE.txt
drwxr-xr-x  2 root root      6 Aug 14  2017 plugins
-rw-r--r--  1 root root   9549 Aug 14  2017 README.textile
[root@localhost elasticsearch-5.5.2]# sh bin/elasticsearch
[2020-09-25T17:52:12,667][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:127) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.5.2.jar:5.5.2]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
        at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:351) ~[elasticsearch-5.5.2.jar:5.5.2]
        at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.5.2.jar:5.5.2]
        ... 6 more
[root@localhost elasticsearch-5.5.2]#

出现的错误:can not run elasticsearch as root ,即不能以root用户启动。

新建一个用户来启动:

[root@localhost ~]# useradd elastic
[root@localhost ~]# chown -R elastic:elastic  /home/elasticsearch/elasticsearch-5.5.2/
[root@localhost ~]# su elastic
[elastic@localhost ~]$ sh /home/elasticsearch/elasticsearch-5.5.2/bin/elasticsearch

出现下面的启动日志时,说明启动成功:

[2020-09-25T18:01:20,309][INFO ][o.e.n.Node               ] [OqaZfCM] starting ...
[2020-09-25T18:01:20,421][INFO ][o.e.t.TransportService   ] [OqaZfCM] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2020-09-25T18:01:20,431][WARN ][o.e.b.BootstrapChecks    ] [OqaZfCM] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2020-09-25T18:01:23,536][INFO ][o.e.c.s.ClusterService   ] [OqaZfCM] new_master {OqaZfCM}{OqaZfCMQQlao8JW_DlkQMg}{py31VvHCQCezLRRyyeVVrg}{127.0.0.1}{127.0.0.1:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2020-09-25T18:01:23,554][INFO ][o.e.h.n.Netty4HttpServerTransport] [OqaZfCM] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2020-09-25T18:01:23,554][INFO ][o.e.n.Node               ] [OqaZfCM] started
[2020-09-25T18:01:23,562][INFO ][o.e.g.GatewayService     ] [OqaZfCM] recovered [0] indices into cluster_state

加 -d 可以后台启动:

[elastic@localhost ~]$ sh /home/elasticsearch/elasticsearch-5.5.2/bin/elasticsearch -d
# 确定是否启动
[elastic@localhost ~]$ ps -ef| grep elasticsearch

若出现以下错误:

ERROR: [2] bootstrap checks failed

[1]: max file descriptors [4096] 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]

解决办法见:

CentOS7上elasticsearch5.5启动报错

错误1解决方案:

# 修改/etc/security/limits.conf文件,添加或修改如下行: (请切换到root用户 然后强制修改文件)
*        hard    nofile           65536
*        soft    nofile           65536

错误2解决方案:

# 方式一:
$ sudo sysctl -w vm.max_map_count=2621441    临时解决方式,重启系统失效

# 方式二:修改文件永久生效
[root@localhost ~]# vim /etc/sysctl.conf
添加以下内容:
vm.max_map_count=2621441

# 使配置立即生效:
[root@localhost ~]# sudo sysctl -p /etc/sysctl.conf
vm.max_map_count = 2621441
[root@localhost ~]# 

1.3 验证服务正常运行

curl http://localhost:9200

[elastic@localhost ~]$ curl http://localhost:9200
{
  "name" : "OqaZfCM",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "XD9eY4gBT1iPF04YisdGig",
  "version" : {
    "number" : "5.5.2",
    "build_hash" : "b2f0c09",
    "build_date" : "2017-08-14T12:33:14.154Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}
[elastic@localhost ~]$ 

此时正常运行。

1.4 允许外网连接配置

前面的配置仅是本机使用,但在集群环境时需要与其他机器连接使用,故进行外网连接是进行以下配置:

修改的是 config目录中的 elasticsearch.yml 文件。

[elastic@localhost root]$ vim /home/elasticsearch/elasticsearch-5.5.2/config/elasticsearch.yml
# 修改内容: 取消 network.host 和 http.port 前的注释, 并将 host 改成自己的ip。 如下:
network.host: 10.21.13.48
http.port: 9200

同时需要关闭防火墙:

systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl status firewalld.service

然后重启 elasticsearch:

ps -ef | grep elasticsearch 
查询到对应的进程号后,
kill -9 pid
sh /home/elasticsearch/elasticsearch-5.5.2/bin/elasticsearch -d

使用 curl http://10.21.13.48:9200/ 测试,或者使用浏览器访问: http://10.21.13.48:9200/ ,若能够正常返回,就说明配置成功了。

{
  "name" : "OqaZfCM",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "XD9eY4gBT1iPF04YisdGig",
  "version" : {
    "number" : "5.5.2",
    "build_hash" : "b2f0c09",
    "build_date" : "2017-08-14T12:33:14.154Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.0"
  },
  "tagline" : "You Know, for Search"
}

若启动出现以下错误:

Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)

原因:由于elasticsearch5.5默认分配jvm空间大小为2g,修改jvm空间分配

解决方案:

vim /home/es/elasticsearch-5.5.2/config/jvm.options 
默认配置 
-Xms2g  
-Xmx2g  

改成
-Xms512m  
-Xmx512m

相关文章

网友评论

      本文标题:一、ElasticSearch安装

      本文链接:https://www.haomeiwen.com/subject/upxluktx.html