유닛의 종류
- 서비스 유닛 (Service Units) : 리눅스 시스템에서 실행되는 백그라운드 서비스나 데몬을 관리합니다. 서비스 유닛은 보통 시스템 부팅 시 자동으로 시작되고, 시스템 종료 시에는 자동으로 중지됩니다. 예를 들어, Apache 웹 서버, Nginx, MySQL 등과 같은 백그라운드 서비스를 관리합니다.
- 타이머 유닛 (Timer Units) : 정기적인 작업을 수행하는 백그라운드 작업을 관리합니다. 타이머 유닛은 특정 시간 간격으로 작업을 실행하거나, 특정 시간에 작업을 예약할 수 있습니다. 예를 들어, 시스템 백업, 로그 파일 로테이션 등과 같은 작업을 관리합니다.
- 타겟 유닛 (Target Units) : 시스템 부팅 시에 시작되는 서비스들의 그룹을 관리합니다. 타겟 유닛은 시스템이 부팅될 때, 특정 서비스와 응용 프로그램을 시작하고, 다른 서비스와 응용 프로그램은 시작하지 않도록 설정할 수 있습니다. 예를 들어, 그래픽 인터페이스 데스크톱 환경인 GNOME, KDE, Xfce 등의 서비스들을 관리합니다.
- 디바이스 유닛 (Device Units) : 리눅스 시스템에서 사용되는 하드웨어 디바이스를 관리합니다. 디바이스 유닛은 하드웨어 디바이스가 시스템에 연결되거나 연결이 끊길 때, 자동으로 해당 디바이스를 감지하고, 관련 서비스 및 드라이버를 로드합니다.
- 소켓 유닛 (Socket Units) : 네트워크 소켓을 관리합니다. 소켓 유닛은 리눅스 시스템에서 실행되는 서비스들이 네트워크 통신을 위해 사용하는 포트를 관리합니다.
- 스코프 유닛 (Scope Units) : 프로세스들의 그룹을 관리합니다. 스코프 유닛은 프로세스들이 실행되는 환경을 구분합니다.
실습 : systemctl을 통해 서비스 유닛 관리(시작, 중지, 재시작 등)
- sudo yum -y install httpd
- systemctl status httpd : httpd 서비스의 상태를 볼 수 있음
(서비스 활성화 및 동작 여부, 로그 등)- systemctl start httpd : 서비스 시작
- systemctl enable httpd : 서비스 활성화→ 운영체제 시작 시 서비스 자동 실행
- systemctl stop httpd : 서비스 중지
- systemctl disable httpd : 서비스 비활성화
- systemctl mask httpd : 서비스 잠금
- systemctl unmask httpd : 서비스 잠금 해제
[user@localhost ~]$ sudo systemctl mask httpd [sudo] user의 암호: Created symlink from /etc/systemd/system/httpd.service to /dev/null. [user@localhost ~]$ sudo systemctl start httpd Failed to start httpd.service: Unit is masked. [user@localhost ~]$ sudo systemctl status httpd ● httpd.service Loaded: masked (/dev/null; bad) Active: inactive (dead)
- systemctl reload httpd : 리로드. PID 값 바뀌지 않음
- systemctl restart httpd : 재시작.(시작을 포함) PID 값 바뀜
Run Level | target 유닛 | 설명 |
---|---|---|
0 | poweroff.target | 시스템을 셧다운 하고 종료 |
1 | rescue.target | 복구 쉘(rescue shell) |
2 | multi-user.target | 커맨드 환경의 다중사용자 모드 |
3 | multi-user.target | 커맨드 환경의 다중사용자 모드 |
4 | multi-user.target | 커맨드 환경의 다중사용자 모드 |
5 | graphical.target | 그래픽 환경의 다중사용자 모드 |
6 | reboot.target | 시스템을 셧다운 하고 재부팅 |
1. 현재의 타겟유닛 (런레벨) 확인
[root@localhost user]# systemctl get-default ### 기본 설정값
graphical.target
[root@localhost user]# runlevel
N 5
[root@localhost user]# who -r ### 현재 런레벨
run-level 5 2023-05-03 09:26
2. 타겟유닛 (런레벨) 변경
예) multi-user로 변경 (runlevel 3)
3. 기본 설정 타겟 변경
[root@localhost user]# ls -l /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 41 5월 3 12:07 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target
퀴즈 : sshd 라는 데몬 파일이 소속된 패키지 및 정보 출력
[user@localhost ~]$ which sshd /usr/sbin/sshd [user@localhost ~]$ rpm -qif /usr/sbin/sshd Name : openssh-server Version : 7.4p1 Release : 21.el7 Architecture: x86_64 Install Date: 2023년 04월 19일 (수) 오후 05시 27분 58초 Group : System Environment/Daemons Size : 993586 ...