1、chkconfig
2、systemd
chkconfig方式:
在目录/etc/init.d/下建立可执行程序的拷贝或链接, 比如:cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
然后执行:
chkconfig --add httpd
chkconfig --levels 345 httpd on
service httpd start
systemd方式:
建立service文件,比如 httpd.service, 文件内容类似:
[Unit] Description=httpd service After=network.target [Service] Type=forking ExecStart=/usr/local/httpd/bin/apachectl start ExecStop=/usr/local/httpd/bin/apachectl stop User=nobody Restart=on-abort [Install] WantedBy=multi-user.target并将此文件保存到目录:/etc/systemd/system/
启用服务:
sudo systemctl daemon-reload
sudo systemctl enable httpd.service
sudo systemctl start httpd.service