Linux 服务器 mysql,tomcat,Nginx 开机自启动

时间:2022-01-09 05:10:21

基于Linux 的服务器开发自启动,有三种方式实现:

一. 使用定时任务

 创建定时任务来运行 .sh 脚本。在shell 脚本中编写nginx,mysql 等的启动脚本。

二. Linux使用supervisor 来管理进程

supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控、管理进程。常用于管理与某个用户或项目相关的进程。 

组成部分
supervisord:服务守护进程
supervisorctl:命令行客户端
Web Server:提供与supervisorctl功能相当的WEB操作界面
XML-RPC Interface:XML-RPC接口

supervisor 安装,基本配置详细步骤:  https://www.cnblogs.com/miskis/p/6026452.html

  1. 安装 supervisor 程序。
  2. 配置 supervisor 配置文件。
  3. supervisor 开机自启动。

supervisor 配置文件 Nginx,tomcat等,可以参照 https://blog.csdn.net/xieliaowa9231/article/details/79077873 实现

三. 使用Linux 服务器自带的 service 自动启动服务。

Linux 常用的发行版本:Redhat 系列 (如Centos) 和 Debian系列(如debina  和 Ubuntu) 等。具体可百度 Linux版本

Linux 系统service 启动的服务命令因 Linux 版本不同而不同。

  1. Linux 系统进程保存路径:/etc/init.d ,这个目录下保存用service 来操作的服务。
  2. 编写Nginx,tomcat,mysql 等 shell 脚本,将这些脚本放入/etc/init.d 路径下。
  3. 将脚本加入自启动进程。Redhat 系如 centos 系统中使用命令 chkconfig,debina 系如 Ubuntu 系统中使用命令 sysv-rc-conf

Redhat 系列相关配置,请查看 https://www.cnblogs.com/zmfly/p/6049402.html  或 https://www.jb51.net/article/94181.htm

Debian系列相关配置,请查看 https://www.cnblogs.com/linguoguo/p/5484589.html