栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Elasticsearch在CentOs7环境中设置开机启动

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Elasticsearch在CentOs7环境中设置开机启动

当前系统版本是CentOS7.4,ES版本是7.13.3。需求是设置ES在系统重启后自动开机启动。

一、创建es 的系统启动服务文件

进入到 cd /etc/init.d 目录;编写开机启动脚本

cd /etc/init.d
vi elasticsearch

 下面是脚本添加的内容:

#!/bin/sh
#chkconfig: 345 63 37
#description: elasticsearch 7.13.3
#processname: elasticsearch

#export JAVA_HOME=/usr/java/jdk1.8.0_112
#export JAVA_BIN=/usr/java/jdk1.8.0_112/bin
#export PATH=$PATH:$JAVA_HOME/bin
#export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#export JAVA_HOME JAVA_BIN PATH CLASSPATH

case "$1" in
start)
    # Es startup account
    su es< 

脚本中的各种路径需要根据自己服务器修改;JDK的环境变量根据自己需要设置,我这里是注释掉的。

二、为启动脚本增加执行权限
chmod +x /etc/init.d/elastisearch

三、添加服务并设置启动方式

添加服务

chkconfig --add elasticsearch

删除服务

chkconfig --del elasticsearch

四、设置服务开机启动

开启

chkconfig elasticsearch on

关闭

chkconfig elasticsearch off

五、验证是否已启动的命令

查看是否有es的进程

ps -ef | grep elasticsearch

查询结果:

[root@testmachine init.d]# ps -ef | grep elasticsearch
es        1341     1  8 13:00 ?        00:05:11 /home/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 --add-opens=java.base/java.io=ALL-UNNAMED -XX:+UseG1GC -Djava.io.tmpdi
r=/tmp/elasticsearch-3668041173047372859 -XX:+HeapDumponOutOfMemoryError -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 -Xms3991m -Xmx3991m -XX:MaxDirectMemorySize=2092957696 -XX:G1HeapRegionSize=4m -XX:InitiatingHea
pOccupancyPercent=30 -XX:G1ReservePercent=15 -Des.path.home=/home/elasticsearch -Des.path.conf=/home/elasticsearch/config -Des.distribution.flavor=default -Des.
distribution.type=tar -Des.bundled_jdk=true -cp /home/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -d
es        1371  1341  0 13:00 ?        00:00:00 /home/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller
root      1749  1650  0 14:02 pts/0    00:00:00 grep --color=auto elasticsearch
[root@testmachine init.d]# 
六、其他说明

Elastisearch操作命令:

启动ES服务

service elastisearch start

停止ES服务

service elasticsearch stop

重启ES服务

service elasticsearch restart

先查看当前的开机启动服务

chkconfig --list
[root@testmachine init.d]# chkconfig --list elasticsearch

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

elasticsearch   0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@testmachine init.d]# 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/270398.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号