LPIC‐202
Lab 4
Lab 4 : Configuration générale d’Apache sur CentOS 7
Objectifs :
Modifier les options de démarrage d’Apache
Choisir et configurer son MPM
Configurer et vérifier l’affectation des interfaces réseau et ports d’écoute
Mesurer les performances du serveur avec ab.
Séquence 0 :
Installez Apache :
[root@localhost ~]# yum install httpd
Séquence 1 :
Dans cette séquence on désire identifier les différents fichiers intervenants dans le
fonctionnement d’Apache, processus de démarrage, gestion des journaux, fichier de PID et
applications tierces.
1. En utilisant les commandes du système (RedHat, Fedora ou CentOS) vérifiez si le service
« httpd » est activé pour le démarrage et s’il est actuellement en cours d’exécution ou pas.
[root@localhost ~]# systemctl is-enabled httpd
disabled
[root@localhost ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor
preset: disabled)
Active: inactive (dead)
Docs: man:httpd(8)
man:apachectl(8)
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl is-active httpd
Active
cat /var/run/httpd/httpd.pid
3151
[root@localhost ~]# ss -tlnp '( src :443 or src :80 )'
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :::80 :::*
users:(("httpd",pid=9812,fd=4),("httpd",pid=9811,fd=4),("httpd",pid=9810,fd
Advertisement
=4),("httpd",pid=9809,fd=4),("httpd",pid=9808,fd=4),("httpd",pid=9807,fd=4)
)
[root@localhost ~]# netstat -ntaupe | grep httpd
tcp6 0 0 :::80 :::* LISTEN 0 53095 9807/httpd
[root@localhost ~]# which httpd
/usr/sbin/httpd
Elies Jebri
Page 1 sur 4
LPIC‐202
Lab 4
Lorsque vous avez l'adresse IP de votre serveur, entrez‐la dans la barre d'adresse de votre
navigateur :
http://your_server_ip
Vous verrez la page Web par défaut de CentOS 7 Apache:
indique qu'Apache fonctionne correctement. Il contient également des
Cette page
informations de base sur les fichiers Apache importants et les emplacements de répertoires.
2. Apache MPM (Multi‐Processing Modules) sont des modules Apache permettant de créer
des processus enfants dans Apache, l'installation par défaut utilise le MPM Prefork.
[root@localhost ~]# httpd -V | grep MPM
Server MPM: prefork
[root@localhost ~]# httpd -V
Server version: Apache/2.4.6 (CentOS)
Server built: Jul 29 2019 17:18:49
Server's Module Magic Number: 20120211:24
Server loaded: APR 1.4.8, APR-UTIL 1.5.2
Compiled using: APR 1.4.8, APR-UTIL 1.5.2
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
Advertisement
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT="/etc/httpd"
-D SUEXEC_BIN="/usr/sbin/suexec"
-D DEFAULT_PIDLOG="/run/httpd/httpd.pid"
-D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
-D DEFAULT_ERRORLOG="logs/error_log"
-D AP_TYPES_CONFIG_FILE="conf/mime.types"
-D SERVER_CONFIG_FILE="conf/httpd.conf"
Elies Jebri
Page 2 sur 4
LPIC‐202
Lab 4
[root@localhost ~]# ps afux | grep httpd
root 9807 0.0 0.1 224052 5004 ? Ss 16:37 0:02 /usr/sbin/httpd -DFOREGROUND
apache 9808 0.0 0.0 224052 2952 ? S 16:37 0:00 \_ /usr/sbin/httpd -DFOREGROUND
apache 9809 0.0 0.0 224052 2952 ? S 16:37 0:00 \_ /usr/sbin/httpd -DFOREGROUND
apache 9810 0.0 0.0 224052 2952 ? S 16:37 0:00 \_ /usr/sbin/httpd -DFOREGROUND
apache 9811 0.0 0.0 224052 2952 ? S 16:37 0:00 \_ /usr/sbin/httpd -DFOREGROUND
apache 9812 0.0 0.0 224052 2952 ? S 16:37 0:00 \_ /usr/sbin/httpd -DFOREGROUND
Vous pouvez également lister tous les modules chargés :
[root@localhost ~]# apachectl -D DUMP_MODULES
Pour activer le MPM event dans Apache commencez par éditer le fichier de configuration
dans votre éditeur de texte préféré.
vi /etc/httpd/conf.modules.d/00-mpm.conf
Commentez les lignes LoadModule pour mpm_prefork_module et mpm_worker_module et
décommentez la ligne LoadModule pour mpm_event_module, comme indiqué ci‐dessous :
#LoadModule mpm_prefork_module modules / mod_mpm_prefork.so
#LoadModule mpm_worker_module modules / mod_mpm_worker.so
LoadModule mpm_event_module modules / mod_mpm_event.so
Puis redémarrez le service et vérifiez que c’est bien ce nouvel MPM qui démarre et non plus
Advertisement
l’ancien :
systemctl restart httpd
[root@localhost ~]# httpd -V | grep MPM
Server MPM: event
[root@localhost ~]# ps axfo ppid,pid,user,command | grep httpd
1 10249 root /usr/sbin/httpd -DFOREGROUND
10249 10250 apache \_ /usr/sbin/httpd -DFOREGROUND
10249 10251 apache \_ /usr/sbin/httpd -DFOREGROUND
10249 10252 apache \_ /usr/sbin/httpd -DFOREGROUND
10249 10253 apache \_ /usr/sbin/httpd -DFOREGROUND
[root@localhost ~]# pstree -ph 10249
httpd(10249)─┬─httpd(10250)
├─httpd(10251)─┬─{httpd}(10283)
│ ├─{httpd}(10284)
│ ├─{httpd}(10307)
│ └─{httpd}(10308)
├─httpd(10252)─┬─{httpd}(10309)
│ ├─{httpd}(10310)
.......
│ └─{httpd}(10334)
└─httpd(10253)─┬─{httpd}(10257)
├─{httpd}(10258)
.......
.......
└─{httpd}(10282)
3. Une des raisons des mauvaises performances d’Apache est qu’Apache a du mal à gérer la
charge. Nous allons maintenant modifier le comportement du MPM prefork.
Elies Jebri
Page 3 sur 4
LPIC‐202
Lab 4
Editez le fichier :
vi /etc/httpd/conf.modules.d/00-mpm.conf
LoadModule mpm_prefork_module modules / mod_mpm_prefork.so
#LoadModule mpm_worker_module modules / mod_mpm_worker.so
Advertisement
#LoadModule mpm_event_module modules / mod_mpm_event.so
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
Redémarrez Apache et faites les vérifications nécessaires.
Modifiez la directive StartServers à la valeur 50 puis redémarrez Apache et observez le nombre
de processus.
4. Pour le MPM prefork, nous mesurons sa performance et l'utilisation de mémoire comme
suit :
D’abord nous testons le MPM en envoyant 1000 requêtes avec 12 utilisateurs simultanés. Ceci
donne au MPM la chance de monter en charge quelles que soient les ressources nécessaires.
Ceci est fait avec l'outil ab d’Apache, Prenez note des ressources du système d’abord :
uptime
free -m
ab -n 1000 -c 12 http://localhost/
ab -k -n 1000 -c 5 http://localhost/
Pour garder les résultats dans des fichiers au format csv utilisez l’option ‐e ou bien dans un
format utilisable sous Excel ou gnuplot utilisez l’option ‐g.
ab -k -n 1000 -c 2 -e apache2r1.cvs http://localhost/
ab -k -n 1000 -c 2 -g apache2r2.txt http://localhost/
5. Ensuite, nous envoyons 50.000 requêtes en tout avec 12 utilisateurs simultanés.
ab -k -n 50000 -c 12 -e apache2r3.cvs http://localhost/
ab -k -n 50000 -c 12 -g apache2r4.txt http://localhost/
Mesurez l'utilisation de mémoire de système actuelle avec l'outil 'free'.
Enfin consultez les différentes données collectez et faites une analyse.
Refaites les mêmes tests en mettant la directive KeepAlive à on et en modifiant la valeur de
la directive MaxRequestsperChild.
Elies Jebri
Page 4 sur 4