ES安装教程详解

                       
                                                                                

 
0. 安装前准备
 
    centos7 +
    java 8  +
    elastic 6.2.4+

   
  • 1
  • 2
  • 3
 
2. 在官方网站下载ES
 
wget http://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.1.tar.gz

   
  • 1
 
3. 安装JDK(必须JDK1.8+)
 
rpm -ivh jdk-8u181-linux-x64.rpm
    /*注意:默认安装位置 /usr/java/jdk1.8.0_171-amd64*/

   
  • 1
  • 2
 
4. 配置环境变量
 
vim /etc/profile
在文件末尾加入:
    export JAVA_HOME=/usr/java/jdk1.8.0_171-amd64
    export PATH=$PATH:$JAVA_HOME/bin

   
  • 1
  • 2
  • 3
  • 4
 
5. 重载系统配置
 
    source /etc/profile

   
  • 1
 
6. 安装elasticsearche
 
    tar -zxvf elasticsearch-6.4.1.tar.gz

   
  • 1
 
7. elasticsearche的目录结构
 
    bin                         可执行的二进制文件的目录
    config                        配置文件的目录
    lib                         运行时依赖的库
    logs  modules               运行时日志文件
    plugins                       es中提供的插件

   
  • 1
  • 2
  • 3
  • 4
  • 5
 
8. 运行es服务
 
    在bin目录中执行   ./elasticsearch
    
    注意:root用户启动[2018-09-19T14:50:04,029][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root

   
  • 1
  • 2
  • 3
 
9. 不能以root用户身份启动
 
a.在linux系统中创建新的组
    groupadd es

b.创建新的用户es并将es用户放入es组中

c.修改es用户密码
    passwd es

d.将root用户解压的文件移动到es用户目录中
    mv /root/elasticsearch-6.2.4  /home/es/

f.改变文件的所有者
    chown -R es:es 当前es的安装目录(这里是:/home/es/elasticsearch)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
 
10. 登录es用户启动ES
 
    ./elasticsearch   启动ES

 
  • 1
 
11. 测试ES是否启动成功
 
在命令终端中执行: curl http://localhost:9200 出现以下信息:
    {
      "name" : "xQK1cwT",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "t7IYk7LKQ0mXcyyrdFWpLg",
      "version" : {
        "number" : "6.2.4",
        "build_hash" : "ccec39f",
        "build_date" : "2018-04-12T20:37:28.497551Z",
        "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"
    }

 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
 
12. 开启ES远程访问
 
    vim elasticsearch.yml 将原来network修改为以下配置:
    network.host: 0.0.0.0

 
  • 1
  • 2
 
13. 启动时错误解决方案
 
a.重新启动es出现如下错误
  **ERROR: bootstrap checks failed[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]**
  解决方案:
   # 切换到root用户修改
    vim /etc/security/limits.conf
   # 在最后面追加下面内容
    *               soft    nofile          65536
    *               hard    nofile          65536
    *               soft    nproc           4096
    *               hard    nproc           4096
   # 退出重新登录检测配置是否生效:
    ulimit -Hn
    ulimit -Sn
    ulimit -Hu
    ulimit -Su

b.重新启动出现如下错误
  ERROR: max number of threads [3802] for user [chenyn] is too low,increase to at least [4096]
   解决方案:
   #进入limits.d目录下修改配置文件。
    vim /etc/security/limits.d/20-nproc.conf 
   # 修改为 启动ES用户名 soft nproc 4096
   
c.重新启动出现如下错误
  ERROR: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
   解决方案:
    vim /etc/sysctl.conf
    vm.max_map_count=655360
   #执行以下命令生效:
    sysctl -p

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
 
14. 关闭网络防火墙
 
    systemctl stop firewalld
    systemctl disable firewalld

 
  • 1
  • 2
 
15. 外部浏览器访问即可
 
http://es的主机名:9200 出现如下信息说明安装成功:
{
    "name" : "xQK1cwT",
    "cluster_name" : "elasticsearch",
    "cluster_uuid" : "t7IYk7LKQ0mXcyyrdFWpLg",
    "version" : {
    "number" : "6.2.4",
    "build_hash" : "ccec39f",
    "build_date" : "2018-04-12T20:37:28.497551Z",
    "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"
}

 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16