centos7 elasticsearch开机自启动失败
1.在 /etc/systemd/system 创建了 elasticsearch
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
2.在/etc/init.d 创建了 elasticsearch
#!/bin/bash
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-7.3.2
export ES_HOME=/usr/local/elasticsearch-7.3.2
case $1 in
start)
su elastic<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
stop)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
;;
restart)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
sleep 1
su elastic<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0
chmod 777 elasticsearch
chkconfig --add elasticsearch
得到的结果
[root@VM-24-12-centos system]# systemctl status elasticsearch
● elasticsearch.service - SYSV: elasticsearch
Loaded: loaded (/etc/rc.d/init.d/elasticsearch; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Mon 2023-04-03 10:34:54 CST; 12min ago
Docs: man:systemd-sysv-generator(8)
Main PID: 715 (code=exited, status=217/USER)
Apr 03 10:34:54 VM-24-12-centos systemd[1]: Started elasticsearch.
Apr 03 10:34:54 VM-24-12-centos systemd[1]: elasticsearch.service: main proc...R
Apr 03 10:34:54 VM-24-12-centos systemd[1]: Unit elasticsearch.service enter....
Apr 03 10:34:54 VM-24-12-centos systemd[1]: elasticsearch.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
关于权限
[root@VM-24-12-centos es]# ll
total 8
drwxr-xr-x 6 shcms root 4096 Mar 31 18:12 elasticsearch-7.6.1
drwxr-xr-x 4 root root 4096 Apr 3 09:04 kibana
[root@VM-24-12-centos es]# cd elasticsearch-7.6.1/
[root@VM-24-12-centos elasticsearch-7.6.1]# ll
total 16
drwxrwxr-x 3 shcms shcms 4096 Mar 31 16:57 data
drwxr-xr-x 11 shcms shcms 4096 Mar 31 16:32 elasticsearch-7.6.1
drwxrwxr-x 2 shcms shcms 4096 Mar 31 18:11 installtation
drwxrwxr-x 2 shcms shcms 4096 Apr 3 01:07 log
[root@VM-24-12-centos elasticsearch-7.6.1]#