(0.1)elasticsearch安装

【0】官网参考

https://www.elastic.co/guide/en/elasticsearch/reference/7.11/targz.html

【1】Centos7 下载安装

【1.1】下载

官网:https://www.elastic.co/cn/downloads/elasticsearch

选择好自己想要的相关版本即可;

  

【2】Centos7.X 前置环境配置(ulimit,vm.max_map_count,JDK)

(1)ulimit

它至少要65535

vim /etc/security/limits.conf
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
* soft stack 65535
* hard stack 65535

  

 ulimit -a,如下图,发现没有生效

  

 退出登录重登后生效;su root

  

(2)vm.max_map_count >= 262144

vim /etc/sysctl.conf 

然后在里面加上参数:

vm.max_map_count=2655350

保存,然后重新加载参数:

sysctl -p

  

 

(3)JDK安装,1.8+

检查是否有JAVA环境:

  

如果没有,参考下面文档

参考安装文档:

  https://www.cnblogs.com/gered/p/9056819.html

注意,Elasticsearch7.x版本 建议使用 jdk 11版本以上,但其实1.8版本及以上也够了,如果没有设置 $JAVA_HOME 环境变量,那么将会默认使用自带jdk(自带11版本的);

所以其实不装问题也不大,设置一下$JAVA_HOME 环境变量在这个目录即可

  

(4)Swapping 设置

vim /etc/sysctl.conf

vm.swappiness=1

 

【3】Centos7.X下载安装 Elasticsearch7.X

【3.1】下载解压

(1)手动下载

那很明显,我们下载的就是这个

  LINUX X86_64shaasc

  

(1)自动下载

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gz.sha512
shasum -a 512 -c elasticsearch-7.11.1-linux-x86_64.tar.gz.sha512 
tar -xzf elasticsearch-7.11.1-linux-x86_64.tar.gz

【3.2】建立ES启动账户elk、授权

不知道从什么版本开始,elasticsearch 认为用 root 启动不安全,所以需要额外建立账户

groupadd elk
useradd elk -g elk
chown -R elk:elk ./elasticsearch-7.11.1
mv elasticsearch-7.11.1 /usr/local/elasticsearch

【3.3】配置 ElasticSearch 配置文件

cd /usr/local/elasticsearch
vim config/elasticsearch.yml
 
#添加配置
discovery.seed_hosts: ["127.0.0.1"]
network.host: 0.0.0.0
cluster.initial_master_nodes: ["node-1"]

【3.4】启动:使用守护进程

# -d 是作为守护进程运行 , -p 是把进程id 存到文件
su - elk -c "exec /usr/local/elasticsearch/bin/elasticsearch -d -p /tmp/elasticsearch.pid" 

【3.5】核验安装是否成功

(1)查看9200端口是否启用、监听

  

 

(2)访问本机 9200 端口

 You can test that your Elasticsearch node is running by sending an HTTP request to port 9200 on localhost:

就是说默认是本机9200端口,用就完事了;如下图:这就表示成功了!

  

(3)URL上访问

注意,如果这个不行,请注意查看防火墙、配置文件中的  network.host: 0.0.0.0 是否配置

  

【3.6】怎么关闭退出?

(1)pkill -F /tmp/elasticsearch.pid   (推荐,但前提是前面启动时使用了 -p 并文件是这个位置 )

(2)直接 kill pid

  

 #重启

su - elk -c "exec /usr/local/elasticsearch/bin/elasticsearch -d -p /tmp/elasticsearch.pid" 

【3.7】查阅:日志位置

  

  

 

 

这里面有很多日志,框出来的是错误日志,启动报错之类的信息看这里就好了;

至于其他的,gc 垃圾回收日志,slowlog 慢日志,audit.json 审计信息;

我这里有 log2 data2,是因为我之前有开多个实例;

【3.8】elasticsearch linux二进制版本目录介绍

 

 

目录结构说明,在配置文件里操作使用
• home目录 :使用$ES_HOME表示,如上图,就是 /usr/local/elasticsearch
• bin/ : 位置 $ES_HOME/bin,包含了elasticsearch和elasticsearch-plugin等脚本
• conf/ :位置 $ES_HOME/config,包含了 配置文件 elasticsearch.yml 和 log4j2.properties,使用 path.conf 指定
• data/ :位置 $ES_HOME/data,包含了每个index/shard的数据文件,可以指定多个位置,使用 path.data 指定
• logs/ : 位置 $ES_HOME/logs,使用 path.logs 指定
• plguins/ : 位置$ES_HOME/plugins
• repo/ :使用 path.repo指定,没有默认位置,表示共享文件系统repository的位置。可以指定多个位置。
• script/ :位置$ES_HOME/scripts,使用 path.scripts 指定。

【4】基本查询使用 

(1)查看健康情况(_cat/health)

  

 

(2)查看所有索引(_cat/indices)

  

(3)查看所有节点(_cat/nodes)

   

【错误处理】

(1)FileAlreadyExistsException:/root/elasticsearch/........

表示之前可能启动过一次,但是被中止或者失败了;

后续的路径文件已经生产,删掉这个文件即可;

(2)uncaught exception in thread [main]org.elasticsearch.bootstrap.StartupException:

寻找主要信息:failed to obtain node locks

导致的原因可能是因为之前运行的es还没有正常关闭。

第一步:通过命令:ps aux | grep ‘elastic’ 进行查看

    ES可能已经起了两个进程,把进程kill掉之后重新启动就可以了。

第二步:通过命令: kill -9 进程号 关闭此进程。

第三步:重新启动es。./bin/elasticsearch

(3)ElasticsearchUncaughtExceptionHandler

这是因为不知从哪个版本后,elasticsearch为了安全性,是不能用root用户启动的。

   

解决的办法:当然是创建一个用户,用创建的用户启动啦,注意权限的问题,目录也应该改为创建的用户权限!

我是用elk的用户启动,exec参数指定命令,这样就可以了
su - elk -c "exec /opt/appl/elasticsearch-6.5.4/bin/elasticsearch -d"

 

(4)【bootstrap checks failed】max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]

每个进程最大同时打开文件数太小:解决,见【2】中(1)

[root@DB1 config]# ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[3]: the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured
ERROR: Elasticsearch did not exit normally - check the logs at /usr/local/elasticsearch-7.11.1/logs/elasticsearch.log

(5)【bootstrap checks failed】max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

elasticsearch用户拥有的内存权限太小,至少需要262144

(6)【bootstrap checks failed】the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

看提示可知:缺少默认配置,至少需要配置discovery.seed_hosts/discovery.seed_providers/cluster.initial_master_nodes中的一个参数.

discovery.seed_hosts:  集群主机列表
discovery.seed_providers: 基于配置文件配置集群主机列表
cluster.initial_master_nodes: 启动时初始化的参与选主的node,生产环境必填

vim config/elasticsearch.yml
 
 
#添加配置
discovery.seed_hosts: ["127.0.0.1"]
 
cluster.initial_master_nodes: ["node-1"]

(7)could not find java; set JAVA_HOME or ensure java is in PATH

JAVA 缺失,确定装了JDK

 【开发模式与生产模式】

默认情况下,Elasticsearch假定您正在开发模式下工作。如果上述任何设置的配置不正确,都会在日志文件中写入警告,但是您将能够启动和运行Elasticsearch节点。

一旦您配置了类似的网络设置network.host,Elasticsearch就会假设您即将投入生产,并将上述警告升级为异常。这些异常将阻止您的Elasticsearch节点启动。这是一项重要的安全措施,可确保不会因服务器配置错误而丢失数据。

请注意,可以通过http.host单独配置HTTP和传输transport.host这对于将单个节点配置为可通过HTTP进行访问以进行测试(而不触发生产模式)很有用。

设置开发者模式:(如果是具体IP,则是生产模式,他们的区别就是是否能够需要做启动自检)

http.host: localhost
transport.bind_host: localhost
discovery.type: single-node

开机启动检查相关参数:

  

 

 

【参考文档】

小白从入门到精通:https://www.cnblogs.com/chenyanbin/p/13419497.html

  真想的强力推荐,这篇是真的概念+基本增删改的神器;

 

posted @ 2021-02-24 18:14  郭大侠1  阅读(253)  评论(0编辑  收藏  举报