当前位置: 首页 > news >正文

nginx服务和uwsgi服务如何设置开机自启动

上次学到了在云服务器下如何部署Django项目,用到了nginx服务和uwsgi服务,需要手工启动这2个服务的命令。

现在考虑如何设置开机自启动,为什么要这样考虑?因为服务器万一出问题,意外重启了,那我们部署的Django项目不就挂了吗?到时候还是要人工去启动吗?

所以最好还是配置开机自启动以防万一。

网上查了很多开机自启动配置,最后选择:修改系统文件 /etc/rc.d/rc.local ,添加启动命令脚本。

测试过程中,发现nginx服务自启动比较容易,直接添加就行。但是发现 uwsgi 服务,配置该服务开机自启几种方式,reboot后,导致云服务器挂掉,无法再登录,只能通过云服务官网重启才能进入,所以谨慎操作!!!

经过多次测试和网上经验总结,确定了一个可行方案:

1. 在 /etc/init.d/ 路径下面,建立 uwsgi.sh 启动命令脚本,注意“一定要放到 /etc/init.d/ 路径下面!!!”,其他路径容易导致云服务器挂掉,我试过多次了。

2.  vim /etc/init.d/uwsgi.sh

添加如下内容:注意“执行命令的文件一定要用绝对路径!!!”

#!/bin/bash
/usr/python3/bin/uwsgi --ini /home/django_pro/mysite/uwsgi.ini;

esc 退出编辑,:wq 保存修改

将 /etc/init.d/uwsgi.sh修改为可执行

chmod 777 /etc/init.d/uwsgi.sh

3. 添加开机自启动脚本 到  /etc/rc.d/rc.local 上。

vim /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.#开机自启动 nginx 服务
/usr/sbin/nginx
#开机自启动 uwsgi 服务,一定要用绝对路径执行该sh
/etc/init.d/uwsgi.sh

esc 退出编辑,:wq 保存修改

将rc.local修改为可执行

chmod 777 /etc/rc.d/rc.local

4. reboot 重启检验结果

[root@~]# ps -ef|grep uwsgi
root      1056     1  0 16:23 ?        00:00:00 /usr/python3/bin/uwsgi --ini /home/django_pro/mysite/uwsgi.ini
root      1408  1056  0 16:23 ?        00:00:00 /usr/python3/bin/uwsgi --ini /home/django_pro/mysite/uwsgi.ini
root      1572  1473  0 16:48 pts/0    00:00:00 grep --color=auto uwsgi
[root@~]# ps -ef|grep nginx
root      1017     1  0 16:23 ?        00:00:00 nginx: master process /usr/sbin/nginx
nginx     1023  1017  0 16:23 ?        00:00:00 nginx: worker process
root      1574  1473  0 16:49 pts/0    00:00:00 grep --color=auto nginx

http://www.lryc.cn/news/162203.html

相关文章:

  • 算法-分治算法
  • react 实现监听逻辑
  • vue项目一个页面包含多个时间选择器的处理方案
  • 机器学习入门教学——决策树
  • 文献阅读:Chain-of-Thought Prompting Elicits Reasoning in Large Language Models
  • 从零开发一款ChatGPT VSCode插件
  • go基础09-Go语言的字符串类型
  • 【C++模拟实现】手撕AVL树
  • 如何重置 docker中的mariadb的root
  • 设计模式系列-原型模式
  • 家用电脑可以用做服务器吗
  • CRM软件管理系统的基本功能
  • 手机喊话应用实现思路
  • 【ARM CoreLink 系列 3 -- CCI-550 控制器介绍 】
  • 最长递增子序列 -- 动规
  • linux 进程管理命令
  • 第一章:计算机网络和因特网
  • Android后退堆栈
  • 网络原理(一)网络基础,包括IP ,网络相关的定义
  • Python语义分割与街景识别(2):环境搭建
  • stm32(GD32,apm32),开优化后需要特别注意的地方
  • LLVM 与代码混淆技术
  • R语言---使用runway进行机器学习模型性能的比较
  • C++斩题录|递归专题 | leetcode50. Pow(x, n)
  • 详解Redis之Lettuce实战
  • 【3】单着色器文件读取
  • 祝贺埃文科技入选河南省工业企业数据安全技术支撑单位
  • Chinese-LLaMA-Alpaca-2模型的测评
  • SLAM论文详解(5) — Bundle_Adjustment_LM(BALM)论文详解
  • C语言对单链表所有操作与一些相关面试题