centos开机启动脚本

nginx开机启动

cd /lib/systemd/system/
vim nginx.service

[Unit]
Description=nginx service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

systemctl enable nginx
systemctl daemon-reload

###########################################

redis开机启动

vim /etc/systemd/system/redis-server.service
  1. [Unit]
  2. Description=redis-server
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/usr/local/redis/bin/redis-server /etc/redis/redis.conf
  7. PrivateTmp=true
  8. [Install]
  9. WantedBy=multi-user.target

#######################################

ElasticSearch开机启动

#!/bin/bash
#
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-7.4.0

ES_HOME=/usr/local//usr/local/elasticsearch-7.4.0

case $1 in
  start)

       su es<<!        【es 这个是启动es的账户,如果你的不是这个记得调整】
       cd $ES_HOME
       ./bin/elasticsearch -d -p pid

    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 - es -c "$ES_HOME/bin/elasticsearch -d -p pid"
    echo "elasticsearch is started"
    ;;
  *)
  echo "start|stop|restart"
  ;;
esac
exit 0

 

posted @ 2021-01-21 15:26  小阿Q的博客  阅读(233)  评论(0编辑  收藏  举报