美文网首页
CentOS7分分钟无痛下载安装Elasticsearch

CentOS7分分钟无痛下载安装Elasticsearch

作者: 果女郎 | 来源:发表于2018-11-15 16:12 被阅读0次

前言

谁还不是个标题党呢。(:з」∠)
还没有安装JDK的请先安装JDK,传送门在此QAQ
安装中遇到颇多问题,在此我都做了问题记录。
请合理使用ctrl+F在文中进行问题定位。

安装须知

  1. 请先创建一个elasticsearch目录,并在目录执行下载操作。
  2. 因为版本原因,ES不允许root用户启动,所以启动时注意切换 用户角色su 其他用户所以没有创建其他用户的朋友请先创建用户useradd 新用户
[root@localhost ~]# useradd zyla
[root@localhost ~]# passwd zyla
更改用户 zyla 的密码 。
新的 密码:
重新输入新的 密码:
抱歉,密码不匹配。
新的 密码:
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# 
  1. 因为安装过程中,需要到/etc目录下修改文件,由于权限限制,注意切换为root用户进行操作。

下载

指定目录下执行命令wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.5.0.tar.gz
下载失败,点击此处传送至官网,魔法传送阵
如图所示

红框为tar.gz格式
  1. 解压
    命令tar -zxvf elasticsearch-6.5.0.tar.gz
  2. 切换用户并执行
  • su 除root外用户
  • 进入elasticsearch-6.5.0/bin执行./elasticsearch
    如果以root用户执行,会出现
    不能以root用户运行es

稍等一会,直到加载出startingstarted说明成功,再打开一个连接窗口输入curl -X GET http://localhost:9200检验。

[root@localhost ~]# curl -X GET http://localhost:9200
{
  "name" : "gQmdXvU",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "mUi47EFHQuat6RcdM-l6Kg",
  "version" : {
    "number" : "6.5.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "816e6f6",
    "build_date" : "2018-11-09T18:58:36.352602Z",
    "build_snapshot" : false,
    "lucene_version" : "7.5.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

如果遇到AccessDeniedException:xxxx/elasticsearch-6.5.0/config/jvm.options问题

权限问题
说明当前用户没有用户权限,请以root用户登录情况下使用chown 你的非root用户名 es安装目录 -R来赋予权限。

你以为到此就完了吗?too young too simple。打开主机浏览器输入ip:9200发现访问失败。
根据网上的方案,我首先添加了network.host
任一用户打开/elasticsearch-6.5.0/config/elasticsearch.yml,在network注释附近添加

network.host: 你的ip
discovery.zen.ping.unicast.hosts: ["你的ip"]

添加后,重启./elasticsearch,出现vm.max_map_count [65530] is too low, increase to at least [262144]这类vm.max_map_count错误。

  1. 请以root用户打开文件vi /etc/sysctl.conf
  2. 添加vm.max_map_count = 655360
  3. 保存退出后执行sysctl -p

根据我的经验,如果执行以上步骤后,切换为非root用户启动es还是会失败并遇到以下问题

max number of threads [3829] for user [xxx] is too low, increase to at least [4096]
所以继续打开/etc/security/limits.conf文件新增以下内容
#<domain>      <type>  <item>         <value>
#

#*               soft    core            0
#*               hard    rss             10000
#@student        hard    nproc           20
#@faculty        soft    nproc           20
#@faculty        hard    nproc           50
#ftp             hard    nproc           0
#@student        -       maxlogins       4
你的用户名            soft    nofile          65536
你的用户名            hard    nofile          65536
你的用户名            soft    nproc           4096
你的用户名            hard    nproc           4096

保存退出后,用户退出重新登录以非root用户再启动es,发现:在你修改network之后启动es不再报错了。但是依然无法在主机以及其他机器访问es。那我上述操作有什么用?


坑爹啊

然后根据我的探索发现,获取了一下信息:

  1. centos默认只打开22端口,所以9200外面访问不到。
  2. centos7加强了防火墙[1],以firewall替代iptables

通过以上信息我想你应该知道怎么做了吧。
执行firewall-cmd --zone=public --add-port=9200/tcp --permanent添加9200端口
执行service firewalld restart重启防火墙
执行firewall-cmd --zone=public --query-port=9200/tcp 查看9200端口是否加入名单,会返回yes
最后在确保es启动的情况下,在主机浏览器上访问ip:9200,会发现成功,喜极而泣。

参考链接:
Linux:centos7防火墙开放端口
elasticSearch本地可以访问网页无法访问的解决方法
Linux /etc/profile文件详解


  1. --zone 作用域
    --add-port=80/tcp 添加端口,格式为:端口/通讯协议
    --permanent 永久生效,没有此参数重启后失效

相关文章

网友评论

      本文标题:CentOS7分分钟无痛下载安装Elasticsearch

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