MENU

elasticsearch 在ubuntu 安装

May 6, 2019 • Read: 3154 • 应用搭建

查看java版本

java -version 

没有的话就安装,我的是ununtu系统
更新一下源,直接装就行

apt update
sudo apt install openjdk-8-jre-headless

下载ES安装包

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.0-linux-x86_64.tar.gz

解压

tar -zxvf elasticsearch-7.0.0-linux-x86_64.tar.gz

修改文件夹权限

chown -R testuser /opt/elasticsearch-7.0.0/

创建新的用户来启动

adduser testuser
passwd testuser
su testuser

启动(用新建用户启动)

cd /opt/elasticsearch-7.0.0/etc
./elasticsearch &

查看是不是通了

curl http://localhost:9200/

有个诡异的问题,如果直接把进程杀掉,会出现起不来的问题,重装可以起来,但是还是外网访问不到,这样就造成了,修改配置文件无法生效,可以继续按照下面的步骤,不重装,直接排错。
(1)删除以前版本的ElasticSearch:

sudo apt-get --purge autoremove elasticsearch

(2) 删掉文件

rm-rf /opt/elasticsearch/

遇到问题:

安装过程中遇到几个个坑,记录一下
安装完成后,直接访问 curl http://localhost:9200 有数据,但是外网不通,我用的aws 的服务器,安全组,防火墙均没有问题,看提示报错,至少打开其中的一个服务 cluster.initial_master_nodes: ["node-1","node-2"] 进/opt/elasticsearch-7.0.0/config/中编辑配置文件elasticsearch.yml

vim /opt/elasticsearch-7.0.0/config/elasticsearch.yml

将其中#cluster.initial_master_nodes: ["node-1","node-2"],前面的#号给去掉,wq保存退出

第二个报错: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
解决办法:
编辑 /etc/security/limits.conf,追加以下内容;

* soft nofile 65536
* hard nofile 65536

此文件修改后需要重新登录用户,才会生效!!!!!!!!!!!!!!!!!很重要

其余可能出现的问题
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
解决办法:
编辑 /etc/sysctl.conf,追加以下内容:

vm.max_map_count=655360

保存后,执行:

sysctl -p

max number of threads [2048] for user [tongtech] is too low, increase to at least [4096]
错误原因:启动检查未通过

elasticsearch用户的最大线程数太低

解决办法:

vim /etc/security/limits.d/90-nproc.conf

将2048改为4096或更大

安装成功,无法通过本地子网访问
设置外网访问和按需设置iptables

vim elasticsearch-6.3.1/config/elasticsearch.yml

#修改:network.host: 0.0.0.0
jps | grep Elasticsearch
kill pid
运行./bin/elasticsearch

重启后报错虚拟机

ERROR: [2] bootstrap checks failed

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

解决:切换root账户修改配置limits.conf 添加下面两行然后重启计算机

vim /etc/security/limits.conf
#<domain><type><item><value>
* hard nofile 65536
* soft nofile 65536

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

解决:切换root账户 vim /etc/sysctl.conf
增加一行  vm.max_map_count=655360
接着执行 sysctl -p

运行./bin/elasticsearch #外网访问成功

扩展

安装中文分词器
这里选择和 elasticsearch 配套的 ik-analyzer ;

/opt/elasticsearch-7.0.0/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.0/elasticsearch-analysis-ik-7.0.0.zip

测试一下

curl -H 'Content-Type: application/json'  -XGET 'localhost:9200/_analyze?pretty' -d '{"analyzer":"ik_max_word","text":"testuser"}'

漏了一点,我内网访问localhost:9200 可以通,但是访问内网ip不行,我用的aws,需要在安全组里添加一条内网的策略

完美

兼总条贯 知至知终

最后编辑于: June 20, 2019