在centos中,配置httpd为服务,自动启动

1、创建服务文件 

vi /lib/systemd/system/httpd.service

[Unit]

Description=httpd

After=network.target


[Service]

Type=forking

ExecStart=/home/program/httpd/bin/apachectl start

ExecReload=/home/program/httpd/bin/apachectl restart

ExecStop=/home/program/httpd/bin/apachectl stop

PrivateTmp=true


[Install]

WantedBy=multi-user.target


2、自动启动

systemctl enable httpd


3、启动和停止

systemctl start httpd
systemctl status httpd


4、若修改/lib/systemd/system/httpd.service文件后,需要执行下面代码才算生效

systemctl daemon-reload


httpd,service | 2018-02-18 02:34:17