如何yum部署Elasticsearch?
- By : Will
- Category : Elastic Stack
- Tags: CentOS, Elasticsearch, install, yum

1 基础知识
1.1 Elasticsearch的简介
– Elasticsearch是一个分布式、RESTful风格和数据分析引擎
– Elasticsearch能够应对不断涌现的各种用例
– Elasticsearch作为Elastic堆栈的核心可集中存储你的数据
1.2 Elasticsearch的特点
1.2.1 架构的优点
– 弹性扩展,分布式部署,可随时进行横向扩展或称增加节点
– 高可用性,多个节点集群联合提供索引和搜索功能,正分片节点故障可自动故障转移至副分片节点
– 节点修复,自动使用副本代替故障节点
– 分片平衡,集群自动管理并平行正副分片的分布
– 机架意识,自动分开正副分片存储位置,确保正副分片不在同一物理节点、同一个机架或同一分区
– 集群复制,支持跨集群复制(CCR)将远程集群数据中的索引复制到本地集群中(支持跨数据中心)
1.2.2 数据阶层管理
– 热节点,有更新且可查询
– 温节点,无更新但可查询
– 冷节点,无更新且少查询
– 删节点,无更新且无查询
1.3.3 索引管理
– 允许用户定义自动执行策略控制某个索引四个阶段的停留时间
– 允许用户定义自动执行的各个节点针对索引所采取的行动集合
1.3.4 快照备份
– Elasticsearch支持快照备份单个索引或集群
– Elasticsearch支持快照存储到共享文件系统中
– Elasticsearch支持通过插件支持远程存储库
– Elasticsearch支持对象存储(Amazon S3、Azure Storage或Google Cloud Storage)备份分片
– Elasticsearch支持快照生命周期管理(SLM)API能够允许管理员定义集群的快照的频率
– Elasticsearch支持通过专属UI与SLM允许定义快照保留时限、自动创建和删除时间
– Elasticsearch支持支持直接从快照中查询索引(无需还原数据即可查询)
– Elasticsearch支持存元数据快照(只包含字段和索引元数据,不包含索引或文件所以占用空间只有50%且不能搜索)
2 最佳实践
2.1 环境信息
OS = CentOS 7.x x86_64
IP Address = any
Host Name = any
2.2 安装前的准备
2.2.1 准备需要的工具
yum install -y vim wget
2.2.2 配置安装源
vim /etc/yum.repos.d/elasticsearc.repo
加入如下配置,
[elasticsearch] name=Elasticsearch repository for 7.x packages baseurl=https://artifacts.elastic.co/packages/7.x/yum gpgcheck=1 gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch enabled=1 autorefresh=1 type=rpm-md
2.2.3 关闭SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0
2.3 安装elasticsearch
2.3.1 安装指定的版本
yum install -y elasticsearch-7.10.1
2.3.2 启动服务并设置自启动
systemctl start elasticsearch.service systemctl enable elasticsearch.service
另外,建议你使用如下命令检查服务状态,
systemctl status elasticsearch.service
可见如下提示,
● elasticsearch.service - Elasticsearch Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2020-12-31 16:57:50 CST; 11min ago Docs: https://www.elastic.co Main PID: 8112 (java) CGroup: /system.slice/elasticsearch.service ├─8112 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.netw... └─8267 /usr/share/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller Dec 31 16:57:23 localhost.localdomain systemd[1]: Starting Elasticsearch... Dec 31 16:57:50 localhost.localdomain systemd[1]: Started Elasticsearch.
由以上可知elasticsearch是由Java开发的,如果需要查询运行的进程号,可使用如下命令,
/usr/share/elasticsearch/jdk/bin/jps
可见如下显示,
8112 Elasticsearch 8410 Jps
或者,也可以使用如下命令,
pgrep -u elasticsearch java -a
可见如下显示,
8112 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -XX:+ShowCodeDetailsInExceptionMessages -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.locale.providers=SPI,COMPAT -Xms1g -Xmx1g -XX:+UseG1GC -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -Djava.io.tmpdir=/tmp/elasticsearch-14152068828873697594 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/lib/elasticsearch -XX:ErrorFile=/var/log/elasticsearch/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=/var/log/elasticsearch/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=536870912 -Des.path.home=/usr/share/elasticsearch -Des.path.conf=/etc/elasticsearch -Des.distribution.flavor=default -Des.distribution.type=rpm -Des.bundled_jdk=true -cp /usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -p /var/run/elasticsearch/elasticsearch.pid --quiet
然后,服务倾听的端口可使用如下命令,
netstat -anp | grep `pgrep -u elasticsearch java`
可见如下显示,
tcp6 0 0 127.0.0.1:9200 :::* LISTEN 8112/java tcp6 0 0 ::1:9200 :::* LISTEN 8112/java tcp6 0 0 127.0.0.1:9300 :::* LISTEN 8112/java tcp6 0 0 ::1:9300 :::* LISTEN 8112/java unix 3 [ ] STREAM CONNECTED 30155 8112/java unix 2 [ ] STREAM CONNECTED 30303 8112/java
注:可见当前配置并不适合生产环境
2.3.3 修改数据存储目录和JVM
cp /etc/elasticsearch/elasticsearch.yml /etc/elasticsearch/elasticsearch.yml.default vim /etc/elasticsearch/elasticsearch.yml
修改如下配置,
path.data: /data/elasticsearch
根据配置文件创建服务所需的目录,
mkdir -p /data/elasticsearch chown elasticsearch:elasticsearch /data/elasticsearch chmod 750 /data/elasticsearch chmod g+s /data/elasticsearch
另外,建议修改JVM内存值,
vim /etc/elasticsearch/jvm.options
修改如下配置,
-Xms1g -Xmx1g
重启服务使配置生效,
systemctl restart elasticsearch.service
参阅文档
=============
安装教程
———-
https://www.elastic.co/guide/en/elasticsearch/reference/7.10/rpm.html#rpm-repo
https://www.elastic.co/guide/en/elastic-stack/current/index.html
https://www.elastic.co/guide/index.html
软件的下载
———–
https://www.elastic.co/cn/downloads/past-releases#elasticsearch
https://www.elastic.co/cn/downloads/elasticsearch
产品首页
———–
https://www.elastic.co/cn/elasticsearch/
没有评论