systemctl 模板创建和使用方式案例

1,760次阅读
没有评论

共计 1177 个字符,预计需要花费 3 分钟才能阅读完成。

公司最近有一个需求,需要在同一服务器安装 php 不同版本,我使用的方式是 systemctl 的管理方式。
为了减少 systemctl 的数量,使用的方法是 systemctl 模板的解决办法!具体方式如下

vim /lib/systemd/system/php@.service

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
Before=nginx.service

[Service]
Type=forking
#Type=notify
PIDFile=/run/%i.pid
ExecStart=/usr/local/%i/sbin/php-fpm --fpm-config /etc/%i.conf 
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

上面的定义好后执行下面命令加载配置文件

systemctl daemon-reload

systemctl 模板使用方式
需要了解占位符 %i 的意思,意思就是
%i: This references the instance name, which is the identifier following the @ in the instance unit. This is one of the most commonly used specifiers because it will be guaranteed to be dynamic. The use of this identifier encourages the use of configuration significant identifiers. For example, the port that the service will be run at can be used as the instance identifier and the template can use this specifier to set up the port specification.
中文意思就是 @之后的字符,.service 之前的字符

比如我启动 php5.6 的环境。执行下面命令就启动了 php5.6 但是要确保你的配置文件和安装路径,
这点非常重要不然启动服务会报错

systemctl start php@php5.6.service

启动 php7 的命令同理

systemctl start php@php7.2.service

需要特别注意配置问题!

PIDFile=/run/%i.pid   # 需要与你的 phpxx.fpm 的配置文件配置一致

安装路径也一样需要根据情况更改!

/usr/local/%i/sbin/php-fpm --fpm-config /etc/%i.conf 

systemctl 模板的基本使用方法就是这样!

微信扫描下方的二维码阅读本文

正文完
 0
yx
版权声明:本站原创文章,由 yx 于2019-08-26发表,共计1177字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码

bttech

文章搜索
一言一句话
-「
随机文章
ubuntu20安装部署comfyui脚本

ubuntu20安装部署comfyui脚本

基础环境参考上一篇文章安装基本的驱动 这个使用的曲线较高,有一定的学习成本。脚本如下直接使用即可! 微信扫描下...
elasticsearch7.8.0索引备份到阿里云oss以及恢复

elasticsearch7.8.0索引备份到阿里云oss以及恢复

背景需求,阿里云新建了一套 elk 但是数据需要进行迁移备份, 解决方案使用 logstash 迁移很慢,10...
降本增效之-实现prometheus对阿里云oss nas监控

降本增效之-实现prometheus对阿里云oss nas监控

阿里云 oss nas 需要时刻巡检注意监控流量以及存储大小,需要监控是担心 oss 滥用,nas 的瓶颈问题...
k8s安装chatwoot后配置邮件报超时问题

k8s安装chatwoot后配置邮件报超时问题

k8s 安装好 chathoot 后配置好了邮件的相关变量 官方配置示例 SMTP_ADDRESS: ""SM...
ubuntu20 TeslaT4 安装stable diffusion-webui

ubuntu20 TeslaT4 安装stable diffusion-webui

升级系统 执行 nvidia-smi 查看是否安装了相关驱动 如果执行 nvidia-smi 没有相关命令就需...