ElasticSearch安装与配置
centos 7 安装 ElasticSearch
安装elasticsearch之前 先要安装java jdk 8
这里提供下载地址:链接: https://pan.baidu.com/s/1ZIJc0JWKMyLl4Iivh-YlBw 密码: gr08
# 进入opt目录
cd /opt/
# 创建 soft文件夹 用来存储所有的软件 如果你有自己的目录,可以不创建这个目录
mkdir soft
cd soft
# 执行下载 ElasticSearch 这里使用目前最新的 7.10.1 如果没有wget命令 执行 yum install wget 进行安装
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.10.1-linux-x86_64.tar.gz
# 解压文件
tar -zxvf elasticsearch-7.10.1-linux-x86_64.tar.gz
# 修改文件夹名称和移动目录
mv elasticsearch-7.10.1 /opt/elasticsearch
# 进入elasticsearch目录
cd /opt/elasticsearch
# 默认为了安全,不要使用root进行启动,这里创建一个 elasticsearch 用户和组
# 添加 elasticsearch 组
groupadd elasticsearch
# 添加 elasticsearch 用户 并添加到elasticsearch组中 -g 后表示组
useradd elasticsearch -g elasticsearch
# 修改文件夹拥有者 表示把elasticsearch文件夹 给elasticsearch用户和elasticsearch组
# 修改这个组之前 先退到elasticsearch的目标文件夹上一级
chown -R elasticsearch:elasticsearch elasticsearch
# 修改elasticsearch配置文件
# 进入elasticsearch 的config目录
cd elasticsearch/config/
# 编辑配置文件 参考下面配置文件
vi elasticsearch.yml
## 启动
# 进入 elasticsearch/bin目录
cd bin/
# 使用elasticsearch用户进行启动
sudo -u elasticsearch ./elasticsearch -d
# 查询是否启动成功
ps -ef|grep elasticsearch
# 查看启动日志
tail -f /opt/elasticsearch/logs/yqzl-service.log
# 验证是否成功
curl http://localhost:9200
#出现这个表示成功
:`
{
"name" : "yqzl-node-1",
"cluster_name" : "yqzl-service",
"cluster_uuid" : "3wrpP4wwTFCBHdCboBqQfQ",
"version" : {
"number" : "7.10.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "1c34507e66d7db1211f66f3513706fdf548736aa",
"build_date" : "2020-12-05T01:00:33.671820Z",
"build_snapshot" : false,
"lucene_version" : "8.7.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
`
elasticsearch.yml
# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
# Before you set out to tweak and tune the configuration, make sure you
# understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster: 集群名称
#
cluster.name: yqzl-service
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node: 节点名称
#
node.name: yqzl-node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6): 运行访问的ip 0.0.0.0 表示都可以访问
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes: 初始化主节点
#
cluster.initial_master_nodes: ["yqzl-node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
安装遇到问题
elasticsearch启动时遇到的错误
elasticsearch用户拥有的内存权限太小,至少需要262144;
解决方法:
切换到root用户
执行命令:
sysctl -w vm.max_map_count=262144
查看结果:
sysctl -a|grep vm.max_map_count
显示:
vm.max_map_count = 262144
上述方法修改之后,如果重启虚拟机将失效,所以:
解决办法:
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
即可永久修改
使用ElasticSearch-head的时候,如果是在不同的服务器上,出现跨越的问题
elasticsearch用户拥有的内存权限太小,至少需要262144;
解决方法:
切换到root用户
执行命令:
sysctl -w vm.max_map_count=262144
查看结果:
sysctl -a|grep vm.max_map_count
显示:
vm.max_map_count = 262144
上述方法修改之后,如果重启虚拟机将失效,所以:
解决办法:
在 /etc/sysctl.conf文件最后添加一行
vm.max_map_count=262144
即可永久修改
使用ElasticSearch-head的时候,如果是在不同的服务器上,出现跨越的问题
//编辑配置文件
# vi elasticsearch/elasticsearch.yml
//增加下面两项
http.cors.enabled: true
http.cors.allow-origin: “*”
重启ElasticSearch就OK 了
其它资料
https://github.com/medcl/elasticsearch-analysis-ik/releases