RHEL7 Systemctl command

target 은 기존 SysV init 의 run level 과 같은 개념이며 systemd 의 기본 타겟 명은 default.target 이며 실제로는 다중 사용자 모드(run level) 인 mutl-user.target 임.

$ systemctl get-default
 
multi-user.target

$ systemctl list-units --type target
 
 
UNIT                  LOAD   ACTIVE SUB    DESCRIPTION
basic.target          loaded active active Basic System
cryptsetup.target     loaded active active Encrypted Volumes
getty.target          loaded active active Login Prompts
local-fs-pre.target   loaded active active Local File Systems (Pre)
local-fs.target       loaded active active Local File Systems
multi-user.target     loaded active active Multi-User System
network-online.target loaded active active Network is Online
network.target        loaded active active Network
paths.target          loaded active active Paths
remote-fs.target      loaded active active Remote File Systems
slices.target         loaded active active Slices
sockets.target        loaded active active Sockets
sound.target          loaded active active Sound Card
swap.target           loaded active active Swap
sysinit.target        loaded active active System Initialization
timers.target         loaded active active Timers
 
LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type

활성화되지 않은 타겟(rescue, emergency 등) 목록도 출력하려면 –all 옵션 추가


$ systemctl list-units --type target --all

$ systemctl set-default name.target

설치시 기본 타겟은 multi-user.target 이며 부팅시 X-Windows 로 로그인하려면 graphical.target 으로 설정


$ sudo systemctl set-default graphical.target

</WRAP

시스템 복구등의 이유로 single user mode 로 진입할 필요가 있을 경우 rescue 명령어 사용


$ sudo systemctl rescue

파일 시스템이 깨졌거나 등의 이유로 single mode 로 진입할 수 없을 때 emergency 로 들어가면 부팅시 최소의 기능으로만 부팅(root 파일 시스템은 read only 로 마운트하고 다른 파일 시스템은 마운트를 안 하는 등) 하므로 응급 복구 가능


$ sudo systemctl emergency
service systemctl 설명
service name start systemctl start name.service 서비스 시작
service name stop systemctl stop name.service 서비스 중지
service name restart systemctl restart name.service 서비스 재시작
service name condrestart systemctl try-restart name.service 서비스가 구동중이었을 경우에만 재시작
service name reload systemctl reload name.service 설정 재구동
service name status systemctl status name.service
systemctl is-active name.service
서비스 구동 여부 확인
service –status-all systemctl list-units –type service –all 모든 서비스의 상태 표시
chkconfig systemctl 설명
chkconfig name on systemctl enable name.service 서비스 활성화(부팅시 자동 구동)
chkconfig name off systemctl disable name.service 서비스 비활성화
chkconfig –list name systemctl status name.service
systemctl is-enabled name.service
서비스의 활성화 여부 표시
chkconfig –list systemctl list-unit-files –type service 모든 서비스의 현재 활성화 여부 표시
chkconfig –list systemctl list-dependencies –after 지정한 target 이후에 시작하는 서비스를 표시
chkconfig –list systemctl list-dependencies –before 지정한 target 이전에 시작하는 서비스를 표시
systemctl status 서비스명

systemctl status php-fpm.service
systemctl start mariadb.service
systemctl enable mariadb.service

list-units 명령어 사용

$ sudo systemctl list-units

설치된 모든 unit 파일을 보려면 list-unit-files 사용

$ sudo systemctl list-unit-files

구동에 실패한 서비스

$ sudo systemctl list-units --state=failed

모든 active 목록

$ sudo systemctl list-units --state=active

상태가 inactive 인 목록

$ sudo systemctl list-units --all --state=inactive

서비스중에 상태가 running 인 목록

$ sudo systemctl list-units --type=service --state=running

특정 서비스가 active 상태인지 조회

서비스가 현재 active 상태인지 조회할 경우 is-active 구문 사용

$ sudo systemctl is-active nginx
 
failed

서비스가 부팅때 구동되도록 설정 여부

서비스가 현재 active 상태인지 조회할 경우 is-eabled 구문 사용

$ sudo systemctl is-enabled nginx
disabled

Query the systemd journal log.

journalctl -xn

-e(pager end) 옵션으로 마지막 에러 메시지 라인 보기

journalctl -xe
journalctl -xn --no-pager | less
로그인하면 댓글을 남길 수 있습니다.
  • rhel7_systemctl_command.txt
  • 마지막으로 수정됨: 2018/07/23 07:02
  • 저자 koov