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

1,743次阅读
没有评论

共计 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

文章搜索
一言一句话
-「
随机文章
k8s安装chatwoot后配置邮件报超时问题

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

k8s 安装好 chathoot 后配置好了邮件的相关变量 官方配置示例 SMTP_ADDRESS: ""SM...
降本增效之-实现prometheus对阿里云oss nas监控

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

阿里云 oss nas 需要时刻巡检注意监控流量以及存储大小,需要监控是担心 oss 滥用,nas 的瓶颈问题...
降本增效之-应用部署到k8s

降本增效之-应用部署到k8s

之前应用都采用了传统的服务器部署,很多服务器都会有内存或者 cpu 浪费的情况。把所有的服务准备都迁移到 k8...
MacBook Pro M4 关闭swap

MacBook Pro M4 关闭swap

Swap 是将磁盘虚拟为内存来用的,所以速度肯定比不上扎扎实实的内存的。我是 16G 内存,对于我平时使用完全...
降本增效之-自建k8s监控体系

降本增效之-自建k8s监控体系

使用阿里云 ack, 如果使用阿里云的监控体系一个月是需要几百块钱的监控费用,为了节约这笔费用。使用开源的 p...