Python技巧
网站建设
向Mysql插入Emoji表情时失败了,python代码报以下异常:InternalError: 1366
将MYSQL数据库从一台服务器移植到另一台服务器
MYSQL数据库常用操作命令
Centos7,Centos8防火墙相关的命令
Centos7+nginx下为域名免费安装ssl证书
Centos7.5+nginx布署python3+django WEB服务器
js/jQuery技巧
VPS推荐
python+django开发网站时更新某个应用的models后如何重新生成数据表
CentOS7系统systemd设置nginx开机自启动
CentOS7下配置Supervisor自启动的方法
域名申请
NameSilo域名注册的流程
构建安卓APP
Android Studio 如何修改 Package Name
Android使用WebView加载网站,无法上传图片的解决方法
Android使用WebView将H5网站打包成apk,如何去掉标题,如何更换应用图标
CentOS7系统systemd设置nginx开机自启动
服务器每次重启(或因各种故障掉线,断电后重启),都需要手动启动一些服务,这不是一个程序员可以忍受的,因为服务会中断,严重影响用户体验,再说也没有时间经常去查看服务是否中断。 CentOS7中使用,其配置文件为/usr/lib/systemd/system/ 和 /etc/systemd/system/ 中的文件。 systemd的设计思路是:尽可能的快速启动服务;尽可能的减少系统资源占用。
一,systemctl常用命令如下: systemctl --version # 查看版本。 whereis systemctl # 查看位置。 systemctl list-unit-files # 列出所有可用单元(服务)。 systemctl list-units # 列出所有运行中的单元。 systemctl --failed # 列出所有失败的单元。 systemctl list-unit-files | grep enable # 查看自启动的软件。 systemctl is-enabled mysqld.service # 查看某个单元是否开机启动。 systemctl status mysqld.service # 查看某个单元的状态。 systemctl start mysqld.service # 启动某个单元。 systemctl restart mysqld.service # 重启某个单元。 systemctl stop mysqld.service # 停止某个单元。 systemctl daemon-reload # 修改了某个单元的配置文件后,重载配置文件。 systemctl reload mysqld.service # 重载某个单元。 systemctl enable mysqld.service # 设置开机自启动。 systemctl disable mysqld.service # 关闭开机自启动。 systemctl kill mysqld # 杀死单元。
二,CentOS7设置开机启动 手动安装的nginx,该怎样设置开机自启动? 在系统服务目录里创建nginx.service文件 [root@localhost ~]# vi /usr/lib/systemd/system/nginx.service # 写入内容如下: [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/usr/sbin/nginx -s reload KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true [Install] WantedBy=multi-user.target
三,[Unit]:服务的说明 Description:描述服务 After:描述服务类别 [Service]服务运行参数的设置 Type=forking是后台运行的形式 ExecStart为服务的具体运行命令 ExecReload为重启命令 ExecStop为停止命令 PrivateTmp=True表示给服务分配独立的临时空间 注意:[Service]的启动、重启、停止命令全部要求使用绝对路径 [Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
四,设置开机自启动: [root@localhost ~]# systemctl enable nginx.service Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → usr/lib/systemd/system/nginx.service. [root@ls-921866-24158 ~]# systemctl is-enabled nginx enabled -----》出现:enabled 表示开启开机自启动了 查看nginx状态 [root@localhost ~]# systemctl status nginx.service ● nginx.service - nginx Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor> Active: inactive (dead) # 很奇怪,明明启动成功了,为什么显示Active: inactive (dead)?
五,杀死nginx再重启nginx: [root@localhost ~]# pkill -9 nginx [root@localhost ~]# ps -aux|grep nginx root 29703 0.0 0.1 12112 1108 pts/0 R+ 04:10 0:00 grep --color=auto nginx [root@localhost ~]# systemctl start nginx 再次查看状态,变成了active,搞定。
六,重启服务器 [root@localhost ~]# reboot 再次用xshell连接后,查看服务状态 [root@calm-path-6 ~]# systemctl status nginx.service ● nginx.service - nginx - high performance web server Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled) Active: active (running) since Mon 2023-05-08 03:12:47 EDT; 2 months 23 days ago Docs: http://nginx.org/en/docs/ Main PID: 2608 (nginx) CGroup: /system.slice/nginx.service ├─2608 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf ├─9975 nginx: worker process ├─9976 nginx: worker process ├─9977 nginx: worker process └─9978 nginx: worker process May 08 03:12:47 calm-path-6.localdomain systemd[1]: Starting nginx - high performance web server... May 08 03:12:47 calm-path-6.localdomain systemd[1]: Started nginx - high performance web server. Active: active (running) since Mon 2023-05-08 03:12:47 EDT; 2 months 23 days ago 显示为录色的 running
删除文章
展示文章
友情链接
生活小妙招
赚钱小秘籍
开心一刻