Noderīgas komandas, lai pārvaldītu Apache tīmekļa serveri Linux


Šajā apmācībā mēs aprakstīsim dažas no visbiežāk izmantotajām Apache (HTTPD) pakalpojumu pārvaldības komandām, kuras jums jāzina kā izstrādātājam vai sistēmas administratoram, un jums šīs rokas jātur pa rokai. Mēs parādīsim komandas gan Systemd, gan SysVinit.

Pārliecinieties, ka šādas komandas ir jāizpilda kā root vai sudo lietotājam, un tām vajadzētu darboties ar jebkuru Linux izplatīšanu, piemēram, CentOS, RHEL, Fedora Debian un Ubuntu.

Instalējiet Apache Server

Lai instalētu Apache tīmekļa serveri, izmantojiet noklusējuma izplatīšanas pakotņu pārvaldnieku, kā parādīts.

$ 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]

Pārbaudiet Apache versiju

Lai Linux sistēmā pārbaudītu Apache tīmekļa servera instalēto versiju, izpildiet šo komandu.

$ sudo httpd -v
OR
$ sudo apache2 -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Nov  5 2018 01:47:09

Ja vēlaties parādīt Apache versijas numuru un apkopot iestatījumus, izmantojiet karodziņu -V , kā parādīts.

$ 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"

Pārbaudiet Apache konfigurācijas sintakses kļūdas

Pirms pakalpojuma restartēšanas pārbaudiet, vai Apache konfigurācijas failos nav sintakses kļūdu, izpildiet šo komandu, kas pārbaudīs konfigurācijas failu derīgumu.

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

Sāciet Apache pakalpojumu

Lai palaistu Apache pakalpojumu, palaidiet šo komandu.

------------ 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]

Iespējot Apache pakalpojumu

Iepriekšējā komanda Apache pakalpojumu palaiž tikai uz laiku, lai iespējotu automātisko palaišanu sistēmas sāknēšanas laikā, palaidiet šo komandu.

------------ 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]

Restartējiet Apache pakalpojumu

Lai restartētu Apache (apturiet un pēc tam palaidiet pakalpojumu), palaidiet šādu komandu.

------------ 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]

Skatīt Apache pakalpojuma statusu

Lai pārbaudītu Apache pakalpojuma darbības laika statusa informāciju, izpildiet šo komandu.

------------ 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]

Pārlādēt Apache pakalpojumu

Ja esat veicis kādas izmaiņas Apache servera konfigurācijā, varat norādīt dienestam atkārtoti ielādēt tā konfigurāciju, izpildot šo komandu.

------------ 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]

Pārtrauciet Apache pakalpojumu

Lai apturētu Apache pakalpojumu, izmantojiet šo komandu.

------------ 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]

Parādīt Apache komandu palīdzību

Visbeidzot, bet ne mazāk svarīgi, jūs varat saņemt palīdzību par Apache pakalpojuma komandām sistēmā systemd, palaižot šo komandu.

$ 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)

Plašāku informāciju par systemctl varat atrast, konsultējoties: Kā pārvaldīt “Systemd” pakalpojumus un vienības, izmantojot “Systemctl” Linux.

Jūs varētu vēlēties arī izlasīt šos ar Apache saistītos rakstus.

  1. 5 padomi, kā uzlabot Apache tīmekļa servera veiktspēju
  2. Kā pārraudzīt Apache tīmekļa servera ielādes un lapu statistiku
  3. Kā administrēt Apache tīmekļa serveri, izmantojot rīku “Apache GUI”
  4. Kā nomainīt Apache HTTP portu Linux
  5. 13 Apache tīmekļa servera drošības un cietēšanas padomi
  6. Aizsargājiet Apache pret rupju spēku vai DDoS uzbrukumiem, izmantojot Mod_Security un Mod_evasive moduļus

Tas pagaidām ir viss! Šajā rakstā mēs esam izskaidrojuši visbiežāk izmantotās Apache/HTTPD pakalpojumu pārvaldības komandas, kas jums jāzina, tostarp Apache palaišanu, iespējošanu, restartēšanu un apturēšanu. Jebkurus jautājumus vai komentārus vienmēr varat sazināties ar mums, izmantojot zemāk esošo atsauksmju veidlapu.