在 CentOS 系統中,要實現 Apache2(通常稱為 httpd)的自動重啟,您可以使用以下方法:
方法一:使用 systemctl 命令
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl restart httpd
方法二:使用 cron 任務
sudo crontab -e
0 1 * * * /usr/sbin/service httpd restart
這樣,Apache2 服務將根據您設置的時間間隔自動重啟。請注意,自動重啟可能會導致正在進行的請求中斷,因此請謹慎設置重啟時間。