在/etc/systemd/system目录下创建elasticsearch.service文件
[Unit]
Description=elasticsearch
[Service]
User=elasticsearch
LimitNOFILE=100000
LimitNPROC=100000
# elasticsearch安装路径 (指定自己的安装路径)
ExecStart=/usr/local/elasticsearch/elasticsearch-7.6.2/bin/elasticsearch
[Install]
WantedBy=multi-user.target
开机自启动服务
sudo systemctl daemon-reload
#设置启动服务
sudo systemctl enable elasticsearch.service
#启动elasticsearch
sudo systemctl start elasticsearch.service