centos6
编辑文件将需要执行的脚本添加到下方
vi /etc/rc.local
添加可执行的权限
chmod +x /etc/rc.d/rc.local
ps:tomcat启动可能存在问题
export JAVA_HOME=/soft/jdk1.8.0_191
在执行tomcat启动命令之前先加载环境变量
centos7开机自启以nginx为例
编辑内容
vi /lib/systemd/system/nginx.service
输入脚本
[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
开启服务
systemctl start nginx.service
添加自启动
systemctl enable nginx.service