虚拟机 CentOS 6.5 安装搭建 Elasticsearch 6.2.2

1.安装jre

Elasticsearch(下文用ES简称代替) 的安装搭建环境要求JAVA环境,需要jre1.8以上,所以先从JAVA官网下载jre的rpm包

http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html


下载rpm包后,上传到服务器的 /opt 目录下

服务器上切换到opt 目录下,使用rpm命令安装jre(安装的时候自己补全对应的rpm包的名字),安装完成后使用 命令 java -version 验证java的安装正确性

[root@elk2 ~]# cd /opt
[root@elk2 opt]# rpm -ivh jre-8u161-linux-x64.rpm 
Preparing...                ########################################### [100%]
   1:jre1.8                 ########################################### [100%]
Unpacking JAR files...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...
[root@elk2 opt]# java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)

2.安装ES(官网有多种方法,随意选择)

打开ES官网https://www.elastic.co/guide/en/elasticsearch/reference/current/install-elasticsearch.html

根据官网的教程下载es的tar包,


下载es的tar包

[root@elk2 opt]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.2.tar.gz

解压

[root@elk2 opt]#tar -xzf elasticsearch-6.2.2.tar.gz

解压成功后获得ES6.2.2文件夹

[root@elk2 opt]# ll
总用量 90232
drwxr-xr-x. 8 root root     4096 2月  17 03:03 elasticsearch-6.2.2
-rw-r--r--. 1 root root 29049540 2月  28 11:30 elasticsearch-6.2.2.tar.gz
-rw-r--r--. 1 root root 63333908 2月  28 11:30 jre-8u161-linux-x64.rpm

3.创建ES用户

默认ES 6.X 是不允许root用户运行的,否则ES运行的时候会报错,所以我们需要创建新的用户

[root@elk2 opt]# groupadd es
[root@elk2 opt]# useradd es -g es
[root@elk2 opt]# passwd es
更改用户 es 的密码 。
新的 密码:
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。

4.修改ES目录权限

修改ES的根目录的权限

[root@elk2 opt]# chown -R es:es elasticsearch-6.2.2

切换当前用户为es , 进入es的目录, 使用命令 

./bin/elasticsearch 就可以将ES 运行起来了

[root@elk2 opt]# su es
[es@elk2 opt]$ cd elasticsearch-6.2.2
[es@elk2 elasticsearch-6.2.2]$ ./bin/elasticsearch

正常的启动信息如下:

可以看到默认9200 9300 端口打开

[2018-02-28T11:56:02,537][INFO ][o.e.n.Node               ] [rAnzmAZ] starting ...
[2018-02-28T11:56:02,717][INFO ][o.e.t.TransportService   ] [rAnzmAZ] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
[2018-02-28T11:56:02,736][WARN ][o.e.b.BootstrapChecks    ] [rAnzmAZ] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2018-02-28T11:56:02,737][WARN ][o.e.b.BootstrapChecks    ] [rAnzmAZ] max number of threads [1024] for user [es] is too low, increase to at least [4096]
[2018-02-28T11:56:02,737][WARN ][o.e.b.BootstrapChecks    ] [rAnzmAZ] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-02-28T11:56:02,737][WARN ][o.e.b.BootstrapChecks    ] [rAnzmAZ] system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
[2018-02-28T11:56:05,848][INFO ][o.e.c.s.MasterService    ] [rAnzmAZ] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {rAnzmAZ}{rAnzmAZLR2CCkXXZY1oxAA}{qLtHLrJXRuWme98YA2DxgQ}{127.0.0.1}{127.0.0.1:9300}
[2018-02-28T11:56:05,854][INFO ][o.e.c.s.ClusterApplierService] [rAnzmAZ] new_master {rAnzmAZ}{rAnzmAZLR2CCkXXZY1oxAA}{qLtHLrJXRuWme98YA2DxgQ}{127.0.0.1}{127.0.0.1:9300}, reason: apply cluster state (from master [master {rAnzmAZ}{rAnzmAZLR2CCkXXZY1oxAA}{qLtHLrJXRuWme98YA2DxgQ}{127.0.0.1}{127.0.0.1:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-02-28T11:56:05,906][INFO ][o.e.h.n.Netty4HttpServerTransport] [rAnzmAZ] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
[2018-02-28T11:56:05,906][INFO ][o.e.n.Node               ] [rAnzmAZ] started
[2018-02-28T11:56:05,935][INFO ][o.e.g.GatewayService     ] [rAnzmAZ] recovered [0] indices into cluster_state

可以验证一下服务是否正常

[root@elk2 ~]# curl -i "http://localhost:9200"
HTTP/1.1 200 OK
content-type: application/json; charset=UTF-8
content-length: 436

{
  "name" : "linux-2",
  "cluster_name" : "li-application",
  "cluster_uuid" : "LeGL4ApCTDS-Nj76INkZAg",
  "version" : {
    "number" : "6.2.2",
    "build_hash" : "10b1edd",
    "build_date" : "2018-02-16T19:01:30.685723Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}



ps 。后台运行ES,可以加入-p 命令 让es在后台运行, -p 参数 记录进程ID为一个文件

$ ./bin/elasticsearch -p /tmp/elasticsearch-pid -d
$ cat /tmp/elasticsearch-pid && echo
15516
$ kill -SIGTERM 15516


5.配置ElasticSearch,让ElasticSearch支持外网访问,加入集群等

修改配置文件elasticsearch.yml

[es@elk2 elasticsearch-6.2.2]$ vim config/elasticsearch.yml

去掉以下注释,修改以下配置(记得配置项名称冒号后面是有一个空格的,若没有空格会报错

cluster.name: li-application #集群名称,可以自行修改
node.name: linux-2 #节点名称,自行修改
network.host: 172.16.1.177 #主机地址,这里写本机IP
http.port: 9200 #端口

修改后,再次启动ES后,会得到以下报错

[es@elk2 elasticsearch-6.2.2]$ ./bin/elasticsearch
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1024] for user [es] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

根据网上的各位大佬的解决办法,逐一去解决,使用root身份,执行以下操作

解决问题【1】【2】

[root@elk2 ~]# vim /etc/security/limits.conf

在文件未添加以下内容(开头es 为用户名)

es soft nofile 65536

es hard nofile 131072

es soft nproc 4096

es hard nproc 4096

解决问题【3】

[root@elk2 ~]# sysctl -w vm.max_map_count=262144   
[root@elk2 ~]# vim /etc/sysctl.conf     #让配置永久生效

在文末添加以下内容

vm.max_map_count=262144

解决问题【4】

Centos6不支持SecComp,而ES6默认bootstrap.system_call_filter为true

[es@elk2 elasticsearch-6.2.2]$ vim config/elasticsearch.yml

禁用:在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面: 

取消bootstrap.memory_lock的注释,添加bootstrap.system_call_filter 配置

bootstrap.memory_lock: false 
bootstrap.system_call_filter: false

再次启动es,成功启动

[es@elk2 elasticsearch-6.2.2]$ ./bin/elasticsearch
[2018-02-28T14:16:23,893][INFO ][o.e.t.TransportService   ] [linux-2] publish_address {172.16.1.177:9300}, bound_addresses {172.16.1.177:9300}
[2018-02-28T14:16:23,914][INFO ][o.e.b.BootstrapChecks    ] [linux-2] bound or publishing to a non-loopback address, enforcing bootstrap checks
[2018-02-28T14:16:27,017][INFO ][o.e.c.s.MasterService    ] [linux-2] zen-disco-elected-as-master ([0] nodes joined), reason: new_master {linux-2}{rAnzmAZLR2CCkXXZY1oxAA}{Diisd8m8SiOgBGPC_ET_Fg}{172.16.1.177}{172.16.1.177:9300}
[2018-02-28T14:16:27,031][INFO ][o.e.c.s.ClusterApplierService] [linux-2] new_master {linux-2}{rAnzmAZLR2CCkXXZY1oxAA}{Diisd8m8SiOgBGPC_ET_Fg}{172.16.1.177}{172.16.1.177:9300}, reason: apply cluster state (from master [master {linux-2}{rAnzmAZLR2CCkXXZY1oxAA}{Diisd8m8SiOgBGPC_ET_Fg}{172.16.1.177}{172.16.1.177:9300} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)]])
[2018-02-28T14:16:27,117][INFO ][o.e.h.n.Netty4HttpServerTransport] [linux-2] publish_address {172.16.1.177:9200}, bound_addresses {172.16.1.177:9200}
[2018-02-28T14:16:27,117][INFO ][o.e.n.Node               ] [linux-2] started
[2018-02-28T14:16:27,170][INFO ][o.e.g.GatewayService     ] [linux-2] recovered [0] indices into cluster_state











  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值