一、背景介绍

1、加入系统服务

CentOS7: systemctl restart xxxx
CentOS6: service xxxxx restart

目录文件存放在

/usr/lib/systemd/system

比如:/usr/lib/systemd/system/php-fpm.service

  1. [root@zjt-ecs-1 system]# cat /usr/lib/systemd/system/php-fpm.service
  2. # It's not recommended to modify this file in-place, because it
  3. # will be overwritten during upgrades. If you want to customize,
  4. # the best way is to use the "systemctl edit" command.
  5. [Unit]
  6. Description=The PHP FastCGI Process Manager
  7. After=network.target
  8. [Service]
  9. Type=simple
  10. PIDFile=/usr/local/php/var/run/php-fpm.pid
  11. ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
  12. ExecReload=/bin/kill -USR2 $MAINPID
  13. PrivateTmp=true
  14. [Install]
  15. WantedBy=multi-user.target

image.png

  1. [Unit]
  2. Description=nginx - high performance web server
  3. Documentation=http://nginx.org/en/docs/
  4. After=network-online.target remote-fs.target nss-lookup.target
  5. Wants=network-online.target
  6. [Service]
  7. Type=forking
  8. PIDFile=/var/run/nginx.pid
  9. ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
  10. ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/nginx.pid)"
  11. ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"
  12. [Install]
  13. WantedBy=multi-user.target
  14. ~

image.png
系统服务目录

2、文件说明

i386是指386上编译的,386以上机器可以安装。i586以此类推。
有的rpm包是在红帽子下编译的,有的是在其他平台下编译的,含有noarch的包说明,你可以在任何平台上安装这个软件包,就是说它并不依赖于哪个特定的linux发布版。
noarch是no architecture的意思,表示这个包可以在各种不同cpu的电脑上通用

二、配置

目录

vim /usr/lib/systemd/system/nginx.service
vim /usr/lib/systemd/system/mysql.service

三、使文件生效

systemctl daemon-reload

五、操作命令

  1. CentOS7: systemctl restart mysql
  2. CentOS6: service mysql restart
  3. 启动
  4. systemctl start nginx
  5. systemctl start mysql
  6. systemctl start xxxx
  7. 关闭
  8. systemctl stop nginx
  9. systemctl stop mysqld
  10. systemctl stop xxxx
  11. 重启nginx
  12. systemctl restart nginx
  13. systemctl restart mysqld
  14. systemctl restart xxxx
  15. 状态
  16. systemctl status nginx
  17. systemctl status mysqld
  18. systemctl status xxxx