1. 程式人生 > >自啟動檔案編寫。

自啟動檔案編寫。

vim /lib/systemd/system/nginx.service
檔案內容:

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target

設定nginx開機自啟動
systemctl enable nginx.service


開啟nginx服務:
systemctl start nginx.service

vim /lib/systemd/system/mysql.service
檔案內容:

[Unit]
Description=mysql
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecRestart=/usr/local/mysql/support-files/mysql.server restart
ExecReload=/usr/local/mysql/support-files/mysql.server reload
PrivateTmp=true
[Install]
WantedBy=multi-user.target

設定mysql服務開機自啟動
systemctl enable mysql.service

vim /etc/systemd/system/php-fpm.service
檔案內容:

[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
PrivateTmp=True
[Install]
WantedBy=multi-user.target

設定php-fpm服務開機自啟動:
systemctl enable php-fpm.service
啟動php-fpm:
systemctl start php-fpm.service