CentOS系统环境搭建(十二)——CentOS7安装Elasticsearch

centos系统环境搭建专栏🔗点击跳转

CentOS 7.9安装Elasticsearch 7.17.6

文章目录

1.下载

🔗https://www.elastic.co/downloads/past-releases/elasticsearch-7-17-6

若你是centos64位服务器,下载LINUX X86_64,下载后上传到linux服务器。

2.上传

上传至/usr/local/

3.解压

进入/usr/local/

bash 复制代码
cd /usr/local/

执行解压

bash 复制代码
tar -zxvf elasticsearch-7.17.6-linux-x86_64.tar.gz

4.调整es占用内存

若你电脑性能强劲,这个应该可以不改。

bash 复制代码
vim /usr/local/elasticsearch-7.17.6/config/jvm.options

修改为1g内存占用。

5.修改elasticsearch配置文件

编辑elasticsearch.yml

bash 复制代码
vim /usr/local/elasticsearch-7.17.6/config/elasticsearch.yml

设置节点名称

bash 复制代码
node.name: node-1

集群名

bash 复制代码
cluster.name: my-application

设置master节点列表

bash 复制代码
cluster.initial_master_nodes: ["node-1"]

端口

bash 复制代码
http.port: 9200

允许远程访问

bash 复制代码
network.host: 0.0.0.0

6.创建用户

elasticsearch默认不允许以root账号运行

创建用户

bash 复制代码
useradd es

设置密码

bash 复制代码
passwd es

创建所属组

bash 复制代码
chown es:es -R /usr/local/elasticsearch-7.17.6

增大es用户拥有的内存权限

复制代码
vim /etc/sysctl.conf

在最后一行添加如下

bash 复制代码
vm.max_map_count=262144

保存退出,刷新配置文件

bash 复制代码
sysctl -p

切换到es用户

bash 复制代码
su es

启动elasticsearch

bash 复制代码
cd /usr/local/elasticsearch-7.17.6/bin
bash 复制代码
./elasticsearch

7.Elasticsearch 后台启动与关闭

切换为es用户

bash 复制代码
su es

后台启动(重启)

bash 复制代码
sh /usr/local/elasticsearch-7.17.6/bin/elasticsearch -d

查看进程

bash 复制代码
ps aux | grep elasticsearch

执行后会看到如下

bash 复制代码
[es@VM-4-17-centos logs]$ ps aux | grep elasticsearch
es       31876  181 34.7 3856940 1312716 pts/0 Sl   11:52   0:27 /usr/local/elasticsearch-7.17.6/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 -Dlog4j2.formatMsgNoLookups=true -Djava.locale.providers=SPI,COMPAT --add-opens=java.base/java.io=ALL-UNNAMED -Djava.security.manager=allow -Xms1g -Xmx1g -XX:+UseG1GC -Djava.io.tmpdir=/tmp/elasticsearch-185143932475254405 -XX:+HeapDumpOnOutOfMemoryError -XX:+ExitOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m -XX:MaxDirectMemorySize=536870912 -XX:G1HeapRegionSize=4m -XX:InitiatingHeapOccupancyPercent=30 -XX:G1ReservePercent=15 -Des.path.home=/usr/local/elasticsearch-7.17.6 -Des.path.conf=/usr/local/elasticsearch-7.17.6/config -Des.distribution.flavor=default -Des.distribution.type=tar -Des.bundled_jdk=true -cp /usr/local/elasticsearch-7.17.6/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es       31899  0.0  0.1  54520  4448 pts/0    Sl   11:52   0:00 /usr/local/elasticsearch-7.17.6/modules/x-pack-ml/platform/linux-x86_64/bin/controller
es       31983  0.0  0.0 112812   984 pts/0    S+   11:52   0:00 grep --color=auto elasticsearch

关闭(杀死端口)

bash 复制代码
kill 31876 31899

查看日志

bash 复制代码
tail -f /usr/local/elasticsearch-7.17.6/logs/my-application.log

8.es管理脚本

但是这样仍然让我感到麻烦,es的今后的各种配置伴随要做大量的重启工作,我决心创建一个脚本,帮我完成这些复杂的事情。

8.1 关闭elasticsearch

脚本名称killes.sh,放到/usr/local/elasticsearch-7.17.6/bin/下。

bash 复制代码
#!/bin/bash

# 获取Elasticsearch进程ID列表
es_pids=$(ps -ef | grep elasticsearch | grep -v grep | awk '{print $2}')

# 逐个杀死Elasticsearch进程
for pid in $es_pids; do
  kill $pid
done

为脚本添加执行权限

bash 复制代码
chmod +x /usr/local/elasticsearch-7.17.6/bin/killes.sh

关闭elasticsearch

bash 复制代码
cd /usr/local/elasticsearch-7.17.6/bin
bash 复制代码
./killes.sh

8.2 启动elasticsearch

bash 复制代码
su es
bash 复制代码
sh /usr/local/elasticsearch-7.17.6/bin/elasticsearch -d
相关推荐
岳涛_daemon15 小时前
什么都没配,ES 的 HNSW 早停在 9.3 前后创建的索引默认值不一样,按创建版本算
elasticsearch
Elastic 中国社区官方博客16 小时前
从 137,306 行日志定位到一个故障副本:在 Kibana 中排查错误激增
大数据·运维·人工智能·安全·elasticsearch·搜索引擎
伊布拉西莫18 小时前
从静态参数到动态复用:Jenkins Parameters、Active Choices 与 Scriptler 实战指南
java·servlet·jenkins·devops
Elasticsearch19 小时前
无需改动一行代码:在 Java 应用中使用 OpenTelemetry 的四种方式
elasticsearch
Elasticsearch20 小时前
Kibana Enhance:一键检查并调整现有仪表板的样式
elasticsearch
岳涛_daemon1 天前
考古|ES 2.0 禁的元字段只有 10 个,_source 和 _version 不在里面
elasticsearch
岳涛_daemon1 天前
考古|ES 2.0 先整体解码再切分路径,文档 id 里的 %2F 被切开,个别 id 查不到
elasticsearch
大今野1 天前
技能六 · Linux(CentOS 7)操作系统章节习题
linux·运维·centos·专转本
Elastic 中国社区官方博客2 天前
Elasticsearch 日志写入提速:用 3 项设置和 logsdb_columnar 从每秒 5.2 万行提升到 11.2 万行
大数据·开发语言·elasticsearch·搜索引擎·全文检索
岳涛_daemon2 天前
向量|文本本来就不该切,ES 9.1 之前推理端点只会自动分块,none 让整段作为一个整体嵌入
elasticsearch