在/etc/systemd/system/
下新建文件elasticsearch.service
touch elasticsearch.service
編輯elasticsearch.service文件
vi elasticsearch.service
[Unit]
Description=ElasticSearchAutoStartService
[Service]
Type=forking
User=es
ExecStart=/opt/elasticsearch/bin/elasticsearch
[Install]
WantedBy=multi-user.target
啓動服務
systemctl enable elasticsearch
systemctl start elasticsearch
驗證是否自動啓動
# 重啓系統
reboot
# 查看ElasticSearch進程是否已啓動
ps -ef|grep elasticsearch
如需瞭解Centos開機自啓詳細信息請查看我的博文Shell腳本配置Centos7開機自啓動