例:apache開機啓動
vi /lib/systemd/system/httpd.service
apache 開機啓動配置:
[Unit]
Description=apache2.4
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/apache24/bin/apachectl start
ExecReload=/usr/local/apache24/bin/apachectl restart
ExecStop=/usr/local/apache24/bin/apachectl stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
配置項說明:
CentOS 7以上是用Systemd進行系統初始化的,Systemd 是 Linux 系統中最新的初始化系統(init),它主要的設計目標是克服 sysvinit 固有的缺點,提高系統的啓動速度。 Systemd服務文件以.service結尾,比如現在要建立nginx爲開機啓動,如果用yum install命令安裝的,yum命令會自動創建nginx.service文件,直接用命令systemctl enable nginx.service設置開機啓動即可。
命令說明: