Voici comment démarrer * Apache * avec * httpd.conf * dans * systemd * de * CentOS7 * ou * CentOS8 *.
On suppose qu'il existe un fichier de configuration myhttpd.conf sous le répertoire / etc / httpd / conf que vous souhaitez utiliser lors du démarrage de * Apache *.
Modifiez le fichier de définition d'unité * Apache * * systemd * / usr / lib / systemd / system / httpd.service.
Le httpd.service avant modification est le suivant.
/usr/lib/systemd/system/httpd.service (avant modification)
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
/usr/lib/systemd/system/httpd.service (après modification)
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
/usr/lib/systemd/system/httpd.service (différence)
-ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
-ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
+ExecStart=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -DFOREGROUND
+ExecReload=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -k graceful
Démarrez * Apache * avec le fichier de définition d'unité (httpd.service) modifié par la commande suivante.
systemctl start httpd
Résultat d'exécution
[root@CENTOS7 ~]# systemctl start httpd
[root@CENTOS7 ~]#
Vérifiez le processus * Apache (httpd) * avec la commande suivante et assurez-vous qu'il est démarré dans / etc / httpd / conf / myhttpd.conf.
ps -ef | grep httpd
Résultat d'exécution
[root@CENTOS7 ~]# ps -ef | grep httpd
root      1332     1  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1333  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1334  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1335  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1336  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache    1337  1332  0 22:20 ?        00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
root      1341  1295  0 22:21 pts/0    00:00:00 grep --color=auto httpd
[root@CENTOS7 ~]#
Cette fois, j'ai ajouté -f / etc / httpd / conf / myhttpd.conf directement à ʻExecStart et ʻExecReload de / usr / lib / systemd / system / httpd.service, mais en fait une variable. Vous pouvez également.
Reportez-vous à ce qui suit pour savoir comment utiliser les variables dans le fichier de définition d'unité.
Comment utiliser les variables dans le fichier de définition d'unité systemd
c'est tout
Recommended Posts