以elasticsearch为例子
写实际运行的脚本
vi /home/iscas/autostart.sh
#!bin/bash
su iscas<<!
nohup /home/iscas/es/elasticsearch-6.1.3/bin/elasticsearch > /home/iscas/es/elasticsearch-6.1.3/logs/elasticsearch_start.log 2>&1 &
给执行权限
chmod 777 /home/iscas/autostart.sh
配置开机自启动
vi /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
sh /home/iscas/autostart.sh
给执行权限
chmod 777 /etc/rc.d/rc.local