V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
hansonwang99
V2EX  ›  程序员

CentOS7 上 ElasticSearch 安装填坑记

  •  
  •   hansonwang99 ·
    hansonwang99 · 2018-03-08 10:17:15 +08:00 · 2002 次点击
    这是一个创建于 2213 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Apple


    下载 elastic search 5.3.0

    wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.3.0.tar.gz
    mv elasticsearch-5.3.0.tar.gz /opt
    cd /opt
    tar -xzvf elasticsearch-5.3.0.tar.gz
    cd elasticsearch-5.3.0/
    

    启动 ES

    cd /bin
    ./elasticsearch
    

    按照道理应该就可以了,然而接下来各种坑一一出现,分别阐述

    错误 1error='Cannot allocate memory' (errno=12)

    error='Cannot allocate memory'

    solutions: 由于 elasticsearch5.0 默认分配 jvm 空间大小为 2g,需要改小一点

    vim config/jvm.options  
    -Xms2g  →  -Xms512m
    -Xmx2g  →  -Xmx512m
    

    错误 2:can not run elasticsearch as root

    can not run elasticsearch as root

    solutions: 在 Linux 环境中,elasticsearch 不允许以 root 权限来运行!所以需要创建一个非 root 用户,以非 root 用户来起 es

    groupadd elk  # 创建用户组 elk
    useradd elk -g elk -p 111111  # 创建新用户 elk,-g elk 设置其用户组为 elk,-p 111 设置其密码 6 个 1
    chown -R elk:elk /opt  # 更改 /opt 文件夹及内部文件的所属用户及组为 elk:elk
    su elk # 切换到非 root 用户 elk 下来
    

    错误 3:(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]

    此错误出现在修改 config/elasticsearch.yml 中的 network.host 为 network.host: 0.0.0.0 以便让外网任何 IP 都能来访问时。

    solutions: 切换到 root 用户,然后

    vim /etc/security/limits.conf
    * soft nofile 300000
    * hard nofile 300000
    * soft nproc 102400
    * soft memlock unlimited
    * hard memlock unlimited
    

    /etc/security/limits.conf

    错误 4:max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

    vm.max_map_count is too low

    solutions: 先要切换到 root 用户; 然后可以执行以下命令,设置 vm.max_map_count,但是重启后又会恢复为原值。

    sysctl -w vm.max_map_count=262144
    

    持久性的做法是在 /etc/sysctl.conf 文件中修改 vm.max_map_count 参数:

    echo "vm.max_map_count=262144" > /etc/sysctl.conf
    sysctl -p
    

    image.png

    最后终于在外网访问成功:

    外网访问成功!


    安装可视化插件 elasticsearch-head

    git clone git://github.com/mobz/elasticsearch-head.git
    cd elasticsearch-head
    npm install   # 此处我试图用 cnpm install 有问题,用 npm 可以
    npm run start 
    

    image.png

    然后在外网访问 http://你的安装机 IP:9100

    访问 elasticsearch-head 可视化界面成功


    最后实际简单测试一下

    新建 Index,可以直接向 Elastic 服务器发出 PUT 请求。下面的例子是新建一个名叫 weather 的 Index。

    用 rest 接口向 es 添加 index

    然而刷新 elasticsearch-head 可视化界面可以看到索引已经成功插入

    索引已经插入

    后记

    关于作者更多的 elastic search 实践在此

    作者更多的原创文章在此

    SlipStupig
        1
    SlipStupig  
       2018-03-08 14:12:33 +08:00   ❤️ 1
    docker run -it elasticsearch:5.3
    hansonwang99
        2
    hansonwang99  
    OP
       2018-03-08 14:17:52 +08:00
    @SlipStupig docker 玩了不想玩了,转裸机安装
    liuzelei
        3
    liuzelei  
       2018-03-08 15:58:11 +08:00
    为啥不用 docker
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2812 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:00 · PVG 23:00 · LAX 08:00 · JFK 11:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.