1.1 Centos 8 安装 Elasticsearch

1、点击下载

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.16.3.tar.gz

2、上传安装包到虚拟机并解压

  • 上传至 /opt/elastic
  • 解压
tar-zxvf elasticsearch-7.16.3-linux-x86_64.tar.gz
  • 移动至 /opt/elastic文件夹
mv elasticsearch-7.16.3  /opt/elastic/elasticsearch-7.16.3

tar -zxvf elasticsearch-7.16.3-linux-x86_64.tar.gz -C /opt/elastic/elasticsearch-7.16.3
tar -zxvf kibana-7.16.3-linux-x86_64.tar.gz -C /opt/elastic/kibana-7.16.3

3、elasticsearch 目录介绍

bin:可执行文件在里面,运行es的命令就在这个里面,包含了一些脚本文件等
config:配置文件目录
JDK:java环境
lib:依赖的jar,类库
logs:日志文件
modules:es相关的模块
plugins:可以自己开发的插件
data:这个目录没有,自己新建一下,后面要用 mkdir data,这个作为索引目录

4、设置配置文件参数

配置详解参考: https://www.cnblogs.com/xiaochina/p/6855591.html

  • config 文件夹中存放着配置文件

编辑 elasticsearch.yml ,在文件最后添加

cluster.name: es-article   #配置elasticsearch的集群名称,默认是my-application。建议修改成一个有意义的名称。
node.name: es-node-1       #节点名,通常一台物理服务器就是一个节点,es会默认随机指定一个名字,建议指定一个有意义的名称,方便管理
network.host: 0.0.0.0      #绑定ip地址
http.port: 9200                 #暴露的http端口
transport.tcp.port: 9300   #内部端口
node.master: true          #主节点
node.data: true            #数据节点
path.data: /usr/local/elasticsearch-7.9.3/data   #索引目录
path.logs: /usr/local/elasticsearch-7.9.3/logs   #日志目录
cluster.initial_master_nodes: ["es-node-1"]      #集群节点
#使用head等插件监控集群信息,需要打开以下配置项
http.cors.enabled: true
http.cors.allow-origin: "*"
这个为单机配置,之后还会介绍集群配置
cluster.name 集群的名字
node.name 此节点在集群中的名字
network.host: 0.0.0.0 任意ip都可以访问我
http.port: 访问端口号
cluster.initial_master_nodes: 集群中节点名称。此名称要和node.name对应。

jvm.options文件

## JVM configuration
 
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
 
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
 
-Xms1g
-Xmx1g
 
################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################
 
## GC configuration
8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly
 
## G1GC Configuration
# NOTE: G1 GC is only supported on JDK version 10 or later
# to use G1GC, uncomment the next two lines and update the version on the
# following three lines to your version of the JDK
# 10-13:-XX:-UseConcMarkSweepGC
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
14-:-XX:+UseG1GC
14-:-XX:G1ReservePercent=25
14-:-XX:InitiatingHeapOccupancyPercent=30
 
## JVM temporary directory
-Djava.io.tmpdir=${ES_TMPDIR}
 
## heap dumps
 
# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError
 
# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data
 
# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log
 
## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m
 
# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
 

jvm配置这里我采用默认配置,没有修改,可根据自己虚拟机实际情况修改。

五、添加elastic用户

Elasticsearch不允许使用root操作Elasticsearch,需要添加用户,操作如下:

groupadd elastic    //创建用户组
useradd elastic  -g elastic -p S*Z&9J#8   //创建用户让其归属到elastic组中,然后创建密码S@Z&9J#8 
chown -R elastic:elastic /opt/elastic    //chown -R {组名}.{用户名} /usr/local/es

六、修改配置文件

修改limist.conf文件

命令: vi /etc/security/limits.conf
配置:
lorshaw soft nofile 65536
lorshaw hard nofile 131072
lorshaw soft nproc 65536
lorshaw hard nproc 65536

修改limits.d配置文件

命令:vi /etc/security/limits.d/20-nproc.conf
配置:lordshaw soft nproc 65536

修改sysctl.conf配置文件

命令:vi /etc/sysctl.conf
配置:
vm.max_map_count=655360
 
执行命令:让以上配置生效
sysctl -p

关闭防火墙

systemctl stop firewalld.service

七、启动Elasticsearch

切换到elastic的 /bin目录下执行:

./elasticsearch

后台启动 Elasticsearch 服务:

./elasticsearch -d

如果出现以下错误:
在这里插入图片描述

ERROR: [3]bootstrap checks failed
#用户拥有的可创建文件描述的权限太低,至少需要65536;

[1]: max filedescriptors [4096]forelasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3795]foruser [esuser]is too low, increase to at least [4096]
#elasticsearch用户拥有的内存权限太小,至少需要262144;

[3]: max virtual memory areas vm.max_map_count [65530]is too low, increase to at least [262144]
需要切换到root用户修改配置:

  • 修改 /etc/security/limits.conf 文件 添加以下内容:

    soft nofile 65536
    hard nofile 131072
    soft nproc 4096
    hard nproc 4096
    
  • 修改 /etc/sysctl.conf 增加 vm.max_map_count=262145

    	vm.max_map_count=262145
    
    处理第一个错误: vim /etc/security/limits.conf //文件最后加入
    esuser soft nofile 65536
    esuser hard nofile 65536
    esuser soft nproc 4096
    esuser hard nproc 4096
     
    处理第二个错误:
    进入limits.d目录下修改配置文件。
    vim /etc/security/limits.d/20-nproc.conf 修改为 esuser soft nproc 4096
     
    处理第三个错误:
    vim /etc/sysctl.conf vm.max_map_count=655360
    执行以下命令生效: sysctl -p
    关闭防火墙:systemctl stop firewalld.service
    再次启动成功!
    

    修改完后 sysctl -p 刷新一下
    再次切换到 elastic 进行启动
    访问192.168.100.100:9200

八、部署Kibana

1. 下载软件包

cd /opt/elastic          # 先导航到要存放的目录下
wget  https://artifacts.elastic.co/downloads/kibana/kibana-7.16.3-linux-x86_64.tar.gz # 下载
tar-xzf kibana-7.16.3-linux-x86_64.tar.gz               # 解压
chown -R elastic.elastic kibana-7.16.3-linux-x86_64/    # 给用户赋权限
rm -f kibana-7.16.3-linux-x86_64.tar.gz                 # 删除压缩文件
cd kibana-7.16.3-linux-x86_64/                          # 导航到解压之后的目录之下

2. 修改配置文件

vi config/kibana.yml 

**修改以下配置 **

server.port:5601   # 监听端口
server.host:"192.168.52.129"    # 监听IP地址,换成自己的IP
elasticsearch.hosts:["http://192.168.52.129:9200"]   # elasticsearch连接kibana的URL

3. 运行

此时位于kibana-7.16.3-linux-x86_64目录之下

su elastic.elastic # 切换用户,不要用root,第一步已经给了用户elastic.elastic权限
./bin/kibana

4. 运行效果

修改限制信息

  1. 目的是修改系统中允许应用最多创建多少文件等的限制权限。Linux默认来说,一般限制应用最多创建的文件是65535个。但是Elasticsearch至少需要65536的文件创建权限。
  2. Elasticsearch至少需要4096的线程池预备。Elasticsearch在5.x版本之后,强制要求在linux中不能使用root用户启动Elasticsearch进程。所以必须使用其他用户启动Elasticsearch进程才可以。
  3. 修改系统控制权限
    系统控制文件是管理系统中的各种资源控制的配置文件。Elasticsearch需要开辟一个65536字节以上空间的虚拟内存。Linux默认不允许任何用户和应用直接开辟虚拟内存。

配置开机启动
创建开机启动文件

vim  /usr/lib/systemd/system/elasticsearch.service

内容如下:

[Unit]
Description=elasticsearch
[Service]
User=es    #此处为刚才设置的用户名
LimitNOFILE=100000
LimitNPROC=100000
ExecStart=/usr/local/elasticsearch/bin/elasticsearch
[Install]
WantedBy=multi-user.target

设置开机启动

systemctl daemon-reload                   #加载文件配置
systemctl enable elasticsearch      #设置开机启动
systemctl start|stop|status|restart elasticsearch   #启动|停止|状态|重启es
1.1 启动报错:

在这里插入图片描述

解决方式:
bin/elasticsearch -Des.insecure.allow.root=true
或者 
修改bin/elasticsearch:
加上ES_JAVA_OPTS属性: ES_JAVA_OPTS="-Des.insecure.allow.root=true"
1.2 再次启动:

在这里插入图片描述

这是出于系统安全考虑设置的条件。
由于ElasticSearch可以接收用户输入的脚本并且执行,为了系统安全考 虑,建议创建一个单独的用户用来运行ElasticSearch。

groupadd elsearch
useradd elsearch -g elsearch -p elasticsearch
chown -R elsearch.elsearch /opt/elasticsearch-6.4.0/
    异常:Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch-6.6.2/config/jvm.options
elasticsearch用户没有该文件夹的权限,执行命令
chown -R es:elasticsearch /usr/local/
1.3 再次启动显示已杀死:

在这里插入图片描述

需要调整JVM的内存大小:
vi bin/elasticsearch ES_JAVA_OPTS="-Xms512m -Xmx512m"
再次启动:启动成功
1.4 如果显示如下类似信息:

[INFO ][o.e.c.r.a.DiskThresholdMonitor] [ZAds5FP] low disk watermark [85%] exceeded on [ZAds5FPeTY-ZUKjXd7HJKA][ZAds5FP][/opt/elasticsearch-6.2.4/data/nodes/0] free: 1.2gb[14.2%], replicas will not be assigned to this node
需要清理磁盘空间。
后台运行:./bin/elasticsearch -d
测试连接:curl 127.0.0.1:9200
会看到一下JSON数据:

[root@localhost ~]# curl 127.0.0.1:9200
  {
  "name" : "rBrMTNx",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "-noR5DxFRsyvAFvAzxl07g",
  "version" : {
    "number" : "5.1.1",
    "build_hash" : "5395e21",
    "build_date" : "2016-12-06T12:36:15.409Z",
    "build_snapshot" : false,
    "lucene_version" : "6.3.0"
  },
  "tagline" : "You Know, for Search"
 }
1.5 实现远程访问: 需要对config/elasticsearch.yml进行
配置: network.host: 192.168.25.131
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值