zoukankan      html  css  js  c++  java
  • elasticsearch单机部署


    安装部署elasticsearch
    1.下载地址
    下载地址:https://www.elastic.co/downloads/elasticsearch,我这里下载的是 elasticsearch-6.4.0.tar.gz


    2.解压缩并创建数据目录
    [root@localhost soft]# tar -xvf elasticsearch-6.4.0.tar.gz
    [root@localhost soft]# mv elasticsearch-6.4.0 /opt/
    [root@localhost soft]#cd /opt/elasticsearch-6.4.0
    [root@localhost soft]#mkdir data

    3.创建用户
    因为启动es不能在root用户下启动,所以要事先创建非root用户
    [root@localhost opt]# useradd esuser
    [root@localhost opt]# chown -R esuser.esuser ./elasticsearch-6.4.0/


    4.配置环境变量
    [esuser@localhost ~]$ more .bash_profile
    # .bash_profile

    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
            . ~/.bashrc
    fi

    # User specific environment and startup programs

    JAVA_HOME=/opt/jdk1.8.0_151
    PATH=$JAVA_HOME/bin:$PATH:$HOME/.local/bin:$HOME/bin
    export PATH

    5.修改配置
    vi /opt/elasticsearch-6.4.0/config/elasticsearch.yml
    A.开放network.host,如下:
    network.host: 192.168.1.85

    B.在后面添加如下两项
    http.cors.enabled: true
    http.cors.allow-origin: "*"

    C.修改日志存放路径
    # Path to directory where to store the data (separate multiple locations by comma):
    #
    path.data: /opt/elasticsearch-6.4.0/data
    path.logs:/opt/elasticsearch-6.4.0/logs

    6.修改系统配置文件
    A.修改limits.conf配置文件
    vi /etc/security/limits.conf
    root用户下添加如下2两项,然后退出使用crate用户登陆,使其生效
    *        hard    nofile           65536
    *        soft    nofile           65536

    可是,我的配置本来就已经设置成这样了的
    网上找来找去,都是修改limits.conf文件这个答案,最怕这种了,所有的人都指向同一个答案,却不能解决自己的问题
    后来突然想到是不是环境变量的问题,仔细检查了一遍,发现一个可疑的设置

    vi /etc/profile
    ulimit -n 65535 
    使用 ulimit -Hn 查看当前值,果然是65535,


    ulimit -Hn
    65535
    也就是说每次更新环境变量的时候limits.conf的hard nofile 65536设置被覆盖掉了
    这就好办了,vi /etc/profile 将 ulimit -n 65535 行注释掉,退出重新进入当前用户,再使用 ulimit -Hn 查看当前值,已经是65536了,设置成功!



    B.修改sysctl.conf文件
    vi /etc/sysctl.conf
    vm.max_map_count=262144


    执行下面命令生效
    sysctl -p


    7.配置jvm内存大小
    修改文件./config/jvm.options
    # Xms represents the initial size of total heap space
    # Xmx represents the maximum size of total heap space
    -Xms8g
    -Xmx8g

    修改文件
    ./bin/elasticsearch
    添加红色项目
    export ES_HEAP_SIZE=8g
    source "`dirname "$0"`"/elasticsearch-env

    8.退出重新登录用户登录并启动
    [root@localhost opt]# su - esuser
    [esuser@localhost bin]$ cd /opt/elasticsearch-6.4.0/bin
    [esuser@localhost bin]$./elasticsearch -d


    9.测试我们的es是否好用
    [esuser@localhost logs]$ curl http://192.168.1.85:9200/?pretty
    {
      "name" : "UyIrNGO",
      "cluster_name" : "elasticsearch",
      "cluster_uuid" : "YNvgGJC0QLeMsKt71e7tsw",
      "version" : {
        "number" : "6.4.0",
        "build_flavor" : "default",
        "build_type" : "tar",
        "build_hash" : "595516e",
        "build_date" : "2018-08-17T23:18:47.308994Z",
        "build_snapshot" : false,
        "lucene_version" : "7.4.0",
        "minimum_wire_compatibility_version" : "5.6.0",
        "minimum_index_compatibility_version" : "5.0.0"
      },
      "tagline" : "You Know, for Search"
    }
    [esuser@localhost logs]$


    10.外部浏览器调试es时需要修改的配置

    11.然后在浏览器里输入如下地址
    http://192.168.1.85:9200/

    12.配置验证(elastic默认的密码是changeme)
    修改配置文件,在配置文件最后加上
    xpack.security.enabled: true
    然后重新启动
    运行如下命令设置密码
    ./elasticsearch-setup-passwords interactive



    13.通过账目密码访问
    curl -u elastic:elastic "192.168.1.85:9200"

    14.设置开机自启动
    在/etc/systemd/system目录下创建elasticsearch.service文件
    [Unit]
    Description=elasticsearch
    [Service]
    User=yeemiao
    LimitNOFILE=100000
    LimitNPROC=100000
    ExecStart=/home/yeemiao/es/bin/elasticsearch
    [Install]
    WantedBy=multi-user.target

    设置开机自启
    systemctl enable elasticsearch

    阿里云机器
    [yeemiao@common-es01 ~]$ more /etc/systemd/system/elasticsearch.service

    1. [Unit]
    2. Description=elasticsearch.service
    3. After=network.target
    4.  
    5. [Service]
    6. Type=forking
    7. ExecStart=/usr/bin/su - esuser -c "/home/yeemiao/es/bin/elasticsearch -d -p pid"
    8.  
    9. [Install]
    10. WantedBy=multi-user.target


    15.问题
    阿里云ssh的方式登陆进去发现max file descriptors不生效,非要su - root后,再su - esuser才生效,是否生效可以用如下命令查看:
    ulimit -Hn


  • 相关阅读:
    匿名函数
    内置函数
    基础函数--3
    基础函数(2)
    基础函数(1)
    文件的相关操作
    知识点补充,set集合,深浅copy
    is 和 ==的区别
    Django-form组件中过滤当前用户信息
    Django的常用模块引入整理
  • 原文地址:https://www.cnblogs.com/hxlasky/p/11648267.html
Copyright © 2011-2022 走看看