Contents

systemctl进行管理php-fpm_Nginx_Frpc_Redis等

Contents

systemctl进行管理php-fpm_Nginx_Frpc_Redis等

每次开机需要手动启动各种程序比较麻烦,可以使用systemctl进行管理XXX程序的启动、关闭、重启、开机自启功能。 php注册服务的方式: 1.编辑新的服务文件 vim /etc/systemd/system/php-fpm.service 2.输入以下内容 [Unit] Description=The PHP 7.4 FastCGI Process Manager Documentation=man:php-fpm7.4 After=network.target

[Service] Type=simple PIDFile=/var/run/php74-fpm.pid ExecStart=/usr/local/php74/sbin/php-fpm –nodaemonize –fpm-config /usr/local/php74/etc/php-fpm.conf #根据php-fpm和配置文件的位置进行更改 ExecReload=/bin/kill -USR2 $MAINPID

[Install] WantedBy=multi-user.target

3.保存退出然后执行 systemctl reload-daemon 进行重新加载(#如果新安装了一个服务,使用systemctl 管理,使新服务的服务程序配置文件生效,需进行重新加载。) 然后就可以使用systemctl命令进行管理php了。 systemctl start php-fpm systemctl enable php-fpm systemctl stop php-fpm

每次开机需要手动启动nginx比较麻烦,可以使用systemctl进行管理php的启动、关闭、重启、开机自启功能。 Nginx注册服务的方式: 1.编辑新的服务文件 vim /etc/systemd/system/nginx.service 2.输入以下内容 [Unit] Description=nginx After=network.target remote-fs.target nss-lookup.target

[Service] Type=forking PIDFile=/var/run/nginx.pid ExecStartPost=/bin/sleep 0.1 ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf #根据nginx和配置文件的位置进行更改 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #根据nginx和配置文件的位置进行更改 ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true

[Install] WantedBy=multi-user.target

3.保存退出然后执行 systemctl reload-daemon 进行重新加载(#如果新安装了一个服务,使用systemctl 管理,使新服务的服务程序配置文件生效,需进行重新加载。) 然后就可以使用systemctl命令进行管理Nginx了。 systemctl start nginx systemctl enable nginx systemctl stop nginx

Frpc注册服务的方式: 1.编辑新的服务文件 vim /etc/systemd/system/frpc.service 2.输入以下内容 [Unit] Description=Frp Client Service After=network.target

[Service] Type=simple User=nobody Restart=on-failure RestartSec=5s ExecStart=/opt/frp/frpc -c /opt/frp/frpc.ini ExecReload=/opt/frp/frpc reload -c /opt/frp/frpc.ini

[Install] WantedBy=multi-user.target

3.保存退出然后执行 systemctl reload-daemon 进行重新加载(#如果新安装了一个服务,使用systemctl 管理,使新服务的服务程序配置文件生效,需进行重新加载。) 然后就可以使用systemctl命令进行管理frpc了,同理frps亦可以使用这种方式进行管理。   Redis注册服务的方式: 1.编辑新的服务文件 vim /etc/systemd/system/redis.service 2.输入以下内容 [Unit] Description=Redis server v5.0.8 daemon After=network.target

[Service] Type=forking ExecStart=/usr/local/bin/redis-server /data/redis/conf/redis.conf –daemonize yes #根据redis-server的位置进行更改 ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/bin/redis-cli -p 6379 -a password shutdown #根据redis端口进行更改 User=root Group=root PrivateTmp=true

[Install] WantedBy=multi-user.target

3.保存退出然后执行 systemctl reload-daemon 进行重新加载(#如果新安装了一个服务,使用systemctl 管理,使新服务的服务程序配置文件生效,需进行重新加载。) 然后就可以使用systemctl命令进行管理redis了。 systemctl start redis #启动 systemctl enable redis #开机自启 systemctl stop redis #关闭