פקודות שימושיות לניהול שרת אינטרנט Apache ב־Linux

בהדרכה זו, אנחנו נתאר חלק מהפקטים הכי נפוצים בשימוש ב Apache (HTTPD) לניהול שירותים שצריך לדעת אותם אם אתה מפתח או מנהל מערכת, ואתה צריך לשמור על הפקטים האלה ממש מסביב לאצבעות שלך. אנחנו נראה פקטים עבור Systemd ועבור SysVinit באותו זמן.

קרא גם: 10 הפקטים הנעשים הכי הרבה ב Nginx שכל משתמש ב Linux חייב לדעת

והודע לך שאחרי הפקטים האלה צריך להיות בוצעים בתור root או משתמש sudo והם צריכים לעבד על כל ספקס לינוקס כמו CentOS, RHEL, Fedora, Debian, וUbuntu.

התקנת שרת האפאש

כדי להתקין שרת האינטרנט Apache, השתמש במנהלן החלקים המקובלים בספקס שלך.

$ sudo apt install apache2	    [On Debian/Ubuntu]
$ sudo yum install httpd	    [On RHEL/CentOS]
$ sudo dnf install httpd	    [On Fedora 22+]
$ sudo zypper install apache2	    [On openSUSE]

בדיקת הגירסה של Apache

כדי לבדוק את הגירסא של שרת האינטרנט Apache שמותקע במערכת הלינUX שלך, השתמש בפקט הבא.

$ sudo httpd -v
OR
$ sudo apache2 -v
תוצאה דוגמא
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09

אם תרצה להציג את מספר הגירסא של Apache ואת ההגדרות המאורגנות, תשתמש בסימן -V כפי שנראה.

$ sudo httpd -V
OR
$ sudo apache2 -V
תוצאה דוגמא
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09
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)
 -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"

בדיקת השגיאות בסינתטיקת ההגדרות של Apache

כדי לבדוק את הקבצים המורכבים בהגדרות של Apache על מנת שיוודא אם יש שגיאות בסי

$ sudo httpd -t
OR
$ sudo apache2ctl -t
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using tecmint.com. 
Set the 'ServerName' directive globally to suppress this message
Syntax OK

הפעלת שירות Apache

כדי להפעיל את שירות Apache, הריצו את הפקודה הבאה.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl start httpd     [On Systemd]
$ sudo service httpd start 	 [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl start apache2   [On Systemd]
$ sudo service apache2 start     [On SysVInit]

הפעלת שירות Apache

הפקודה הקודמת מפעילה את שירות Apache לזמן מועט, כדי לאפשר לו להפעיל אוטומטית בעת האתחול של המערכת, הריצו את הפקודה הבאה.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl enable httpd     [On Systemd]
$ sudo chkconfig httpd on 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl enable apache2   [On Systemd]
$ sudo chkconfig apache2 on       [On SysVInit]

איפוס שירות Apache

כדי לאפשר את הפקודה הבאה (עצירה ואז התחלה של השירות), הריצו את הפקודה הבאה.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl restart httpd     [On Systemd]
$ sudo service httpd restart 	   [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl restart apache2   [On Systemd]
$ sudo service apache2 restart     [On SysVInit]

צפייה במצב שירות Apache

כדי לבדוק את מידע סטטוס הריצה של שירות Apache, הריצו את הפקודה הבאה.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl status httpd     [On Systemd]
$ sudo service httpd status 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl status apache2   [On Systemd]
$ sudo service apache2 status     [On SysVInit]

טעינה מחדש שירות Apache

אם ביצעתם שינויים להגדרות השרת של Apache, ניתן להורות לשירות לטעון מחדש את ההגדרות שלו על ידי הרצת הפקודה הבאה.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl reload httpd     [On Systemd]
$ sudo service httpd reload 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl reload apache2   [On Systemd]
$ sudo service apache2 reload     [On SysVInit]

עצירת שירות Apache

כדי לעצור את שירות Apache, השתמשו בפקודה הבאה.

------------ On CentOS/RHEL ------------ 
$ sudo systemctl stop httpd       [On Systemd]
$ sudo service httpd stop 	  [On SysVInit]

------------ On Ubunt/Debian  ------------
$ sudo systemctl stop apache2     [On Systemd]
$ sudo service apache2 stop     [On SysVInit]

הצגת עזרת פקודות Apache

לבסוף, ניתן לקבל עזרה בנוגע לפקודות השירות של Apache ב systemd על ידי הרצת הפקודה הבאה.

$ sudo httpd -h
OR
$ sudo apache2 -h		
OR
$ systemctl -h apache2	
Usage: httpd [-D name] [-d directory] [-f file]
             [-C "directive"] [-c "directive"]
             [-k start|restart|graceful|graceful-stop|stop]
             [-v] [-V] [-h] [-l] [-L] [-t] [-T] [-S] [-X]
Options:
  -D name            : define a name for use in  directives
  -d directory       : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C "directive"     : process directive before reading config files
  -c "directive"     : process directive after reading config files
  -e level           : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                 : show version number
  -V                 : show compile settings
  -h                 : list available command line options (this page)
  -l                 : list compiled in modules
  -L                 : list available configuration directives
  -t -D DUMP_VHOSTS  : show parsed vhost settings
  -t -D DUMP_RUN_CFG : show parsed run settings
  -S                 : a synonym for -t -D DUMP_VHOSTS -D DUMP_RUN_CFG
  -t -D DUMP_MODULES : show all loaded modules 
  -M                 : a synonym for -t -D DUMP_MODULES
  -t                 : run syntax check for config files
  -T                 : start without DocumentRoot(s) check
  -X                 : debug mode (only one worker, do not detach)

ניתן למצוא מידע נוסף על systemctl על ידי עיון ב: איך לנהל שירותים ויחידות 'Systemd' באמצעות 'Systemctl' ב-Linux.

אפשר גם לקרוא את המאמרים הבאים הקשורים ל- Apache.

  1. 5 טיפים לשיפור את ביצועי השרת האפסקי שלך
  2. איך להשגיח על משקל השרת ונתוני הדף של השרת האפסקי
  3. איך לנהל את השרת האפסקי בעזרת הכלי "Apache GUI"
  4. איך לשנות את הפורט של האפסקי HTTP בלינוקס
  5. 13 טיפים לאבטחת ולהחזקת את השרת האפסקי המקורי
  6. להגנה על האפסקי נגד התקפים החדשות או התקפים DDoS בעזרת המודלים Mod_Security ו Mod_evasive

זה הכל עכשיו! במאמר הזה, אנחנו הסברנו את הפקידים המקוריים הנוכחים ביותר של שירות Apache/HTTPD שצריך לדעת, כולל התחלת, האפשרה, השינוי המחזרה והעצורת של Apache. אתה תמיד יכול להגיע אלינו בעזרת הטופס המשוב למטה עבור שאלות או תגובות.

Source:
https://www.tecmint.com/manage-apache-web-server-in-linux/