리눅스에서 Apache 웹 서버를 관리하는 유용한 명령어

이 튜토리얼에서는 개발자 또는 시스템 관리자로서 알아야 할 가장 일반적으로 사용되는 Apache (HTTPD) 서비스 관리 명령어 중 일부를 설명하고 이러한 명령어를 손쉽게 사용할 수 있도록 해야 합니다. 우리는 SystemdSysVinit를 위한 명령어를 보여줄 것입니다.

추가로 읽기: 모든 리눅스 사용자가 알아야 할 가장 많이 사용되는 Nginx 명령어 10가지

다음 명령어는 반드시 루트 또는 sudo 사용자로 실행되어야 하며 CentOS, RHEL, Fedora, Debian, Ubuntu와 같은 모든 리눅스 배포판에서 작동해야 합니다.

Apache 서버 설치

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 웹 서버에 설치된 버전을 확인하려면 다음 명령어를 실행하십시오.

$ 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

아파치 서비스 시작

아파치 서비스를 시작하려면 다음 명령을 실행하십시오.아파치

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

아파치 서비스 활성화

이전 명령은 일시적으로 아파치 서비스를 시작하는 것뿐입니다. 시스템 부팅 시 자동으로 시작하도록 활성화하려면 다음 명령을 실행하십시오.

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

아파치 서비스 재시작

아파치를 재시작하려면 (중지한 다음 시작하려면) 다음 명령을 실행하십시오.

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

아파치 서비스 상태 보기

아파치 서비스 실행 시간 상태 정보를 확인하려면 다음 명령을 실행하십시오.

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

아파치 서비스 다시로드

아파치 서버 구성에 변경 사항이 있으면 다음 명령을 실행하여 서비스가 구성을 다시로드하도록 할 수 있습니다.

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

아파치 서비스 중지

아파치 서비스를 중지하려면 다음 명령을 사용하십시오.

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

아파치 명령 도움말 표시

마지막으로, 시스템디에서 아파치 서비스 명령에 대한 도움말을 얻을 수 있습니다. 다음 명령을 실행하면 됩니다.

$ 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에 대한 자세한 정보는 다음을 참조하십시오: 리눅스에서 ‘Systemctl’을 사용하여 ‘Systemd’ 서비스 및 유닛 관리하기.

또한 다음 아파치 관련 기사를 읽어보시기 바랍니다.

  1. 아파치 웹 서버 성능 향상을 위한 5가지 팁
  2. 아파치 웹 서버 부하 및 페이지 통계 모니터링 방법
  3. “아파치 GUI” 도구를 사용한 아파치 웹 서버 관리 방법
  4. 리눅스에서 아파치 HTTP 포트 변경하는 방법
  5. 13가지 아파치 웹 서버 보안 및 강화 팁
  6. Mod_Security 및 Mod_evasive 모듈을 사용하여 아파치를 브루트 포스나 DDoS 공격으로부터 보호하는 방법

지금까지입니다! 이 기사에서는 아파치/HTTPD 서비스 관리에 가장 많이 사용되는 명령어인 시작, 활성화, 재시작 및 중지하는 방법을 설명했습니다. 궁금한 점이나 의견이 있으시면 아래 피드백 양식을 통해 언제든지 저희에게 연락하실 수 있습니다.

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