>建立服務文件
>保存目錄
>設置開機自啟動
>其他命令
1.建立服務文件
文件路徑
vim /usr/lib/systemd/system/nginx.service
服務文件內容
1.nginx.service
[Unit]
Description=nginx - high performance web serverAfter=network.target remote-fs.target nss-lookup.target
[Service]
Type=forkingExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.confExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
2.mysql.service
[Unit]
Description=mysqlAfter=network.targetremote-fs.targetnss-lookup.target
[Service]
Type=forkingExecStart=/usr/local/mysql/support-files/mysql.serverstart#ExecReload=/usr/local/mysql/support-files/mysql.server restart
#ExecStop=/usr/local/mysql/support-files/mysql.server stop
#PrivateTmp=true
[Install]
WantedBy=multi-user.target
3.php-fpm.service
[Unit]
Description=phpAfter=network.target remote-fs.target nss-lookup.target
[Service]
Type=forkingExecStart=/usr/local/php/sbin/php-fpm
[Install]
WantedBy=multi-user.target
4.redis.service
[Unit]
Description=RedisAfter=network.target remote-fs.target nss-lookup.target
[Service]
Type=forkingExecStart=/usr/local/bin/redis-server /etc/redis.confExecStop=kill -INT `cat /tmp/redis.pid`User=wwwGroup=www
[Install]
WantedBy=multi-user.target
5.supervisord.service
[Unit]
Description=Process Monitoring and Control DaemonAfter=rc-local.service
[Service]
Type=forkingExecStart=/usr/bin/supervisord -c /etc/supervisord.confSysVStartPriority=99
[Install]
WantedBy=multi-user.target
文件內容解釋
[Unit]:服務的說明
Description:描述服務
After:描述服務類別
[Service]服務運行參數(shù)的設置
Type=forking是后臺運行的形式
ExecStart為服務的具體運行命令
ExecReload為重啟命令
ExecStop為停止命令
PrivateTmp=True表示給服務分配獨立的臨時空間注意:啟動颖榜、重啟、停止命令全部要求使用絕對路徑
[Install]服務安裝的相關設置,可設置為多用戶
以754的權限保存在目錄:
/usr/lib/systemd/system
任意目錄下執(zhí)行
systemctl enable nginx.service
啟動nginx服務
systemctlstartnginx.service
設置開機自啟動
systemctl enable nginx.service
停止開機自啟動
systemctl disable nginx.service
查看服務當前狀態(tài)
systemctl status nginx.service
重新啟動服務
systemctl restart nginx.service
查看所有已啟動的服務
systemctllist-units --type=service
轉載自:http://blog.csdn.net/chenxiabinffff/article/details/51374635