+ All Categories
Home > Software > About RHEL7 systemd

About RHEL7 systemd

Date post: 25-Jun-2015
Category:
Upload: ji-woong-choi
View: 2,524 times
Download: 4 times
Share this document with a friend
Description:
Red Hat Enterprise Linux 7의 systemd 에 대한 설명을 오픈소스컨설팅의 전갑일 사원이 정리한 문서입니다. 참조한 링크는 문서내 reference를 보세요.
Popular Tags:
27
2014. 07. 21 RHEL 7 (About systemd) 주식회사 오픈소스컨설팅
Transcript
Page 1: About RHEL7 systemd

2014. 07. 21

RHEL 7 (About systemd)

주식회사 오픈소스컨설팅

Page 2: About RHEL7 systemd

2 - Internal Use Only -

Who am I?

전갑일(kjeon at osci.kr)

오픈소스컨설팅 IT 인프라

서비스팀 엔지니어

리눅스를 평정하는 그 날까지 정진

또 정진~!

Page 3: About RHEL7 systemd

3 - Internal Use Only -

SysVinit & Upstarts Review

Linux System Boot Process(1)

1. System Bios read GRUB

2. GRUB display kernel select & excution

3. Kernel extracts contents of initrd(init script) into RAM disk area

Page 4: About RHEL7 systemd

4 - Internal Use Only -

SysVinit & Upstarts Review

Linux System Boot Process(2)

<Init script의 역할>

1. 메모리에 장치 드라이버들을 load 및 root file system의 mount

2. /sbin/init 프로세스 실행

/sbin/init은 기존의 초기화시스템인 SysVinit과 Upstart의 main body이며,

새로 바뀔 Systemd의 /usr/bin/systemd 와 같은 역할을 함.

Page 5: About RHEL7 systemd

5 - Internal Use Only -

SysVinit & Upstarts Review

Upstarts 동작과정

1. /sbin/init은 RHEL5 에서는 SysVinit, RHEL6에선 upstart라 불리는 작업관리

시스템의 기초

2. /sbin/init에 의해 runlevel별로 실행하며, runlevel5일경우와 아닐경우를 분류해 실행.

3. 초기과정이 미세하게 나뉘긴 하였으나 RHEL5와 거의 흡사.

4. prefdm은 init 5의 GUI환경일 경우 Xwindow부팅을 가능케 함

Page 6: About RHEL7 systemd

6 - Internal Use Only -

SysVinit & Upstarts Review

RHEL5 & RHEL6 (/etc/inittab)

RHEL5

RHEL6

Page 7: About RHEL7 systemd

7 - Internal Use Only -

Objectives of systemd

systemd의 목적

목적 상세내용

시스템의 기동시간 감소

쉘스크립트는 시리얼 오더에 있는 명령을 실행하는데 이는 멀티코어프로세스를 사용하는 최근 환경에선 비효율적임. 따라서 스크립트 내의 다양한 업무가 분할되어 평행하게 실행될 수 있다면 시스템의 기동시간을 감소시킬 수 있을 것. (병행성의 증대)

시스템 환경설정변화의

제어

시스템의 기동시간 뿐 아니라 시스템 환경설정이 변경 시 서비스들또한 start/stop이 유동적으로 변경되는 것이 필요

프로세스 shutdown에 대한 표준 제공

기존의 서비스스크립트에는 프로세스를 중단하는 표준적인 방법이 없었으며, Systemd는 forked daemons를 스스로 찾아낼 수 있도록 표준적인 방법을 제공해야 함.

프로세스 실행환경에 대한 제어

프로세스 실행환경, 즉 자원관리를 위한 cgroup과 디렉토리들에 대한 접근제어등에 관하여 Systemd가 중앙집중적으로 관리해야 함.

Page 8: About RHEL7 systemd

8 - Internal Use Only -

Minimum execution unit of systemd

systemd의 최소 실행단위

1. SysVinit에 있던 다양한 시스템 초기화 스크립트들이 여러 개로 추출되어 독립된

유닛들로 정의됨.

2. 남아있는 몇몇의 /etc/init.d/<service명> start등의 명령어 사용시 기동하긴 하지만

Via systemctl 이 출력되며 실질적으로 systemctl에 의해 동작함을 명시함.

Page 9: About RHEL7 systemd

9 - Internal Use Only -

Minimum execution unit of systemd

systemd의 최소 실행단위 (/etc/rc.d내의 파일비교)

RHEL5

RHEL6

Page 10: About RHEL7 systemd

10 - Internal Use Only -

Unit types

주요 유닛의 타입분류

분류 상세내용

Service type .service의 확장명을 지니며, 이것이 활성화 되면 연관된 daemon이 시작

Target Type .target의 확장명을 지니며, 아무 것도 하지 않음. 이 유닛은 어떠한 다른 관계들이 정의될 때 때에 맞춰 동기화 되는 것을 제공하거나 유닛 간의 의존성을 정의

Swap area Type .swap의 확장명을 지니며, 활성화 시 연관된 swap area가 enabled됨

Device Type .device의 확장명을 지니며, udev가 새로운 장치를 인식하면, 관련된 유닛들이 정의되고 자동적으로 활성화됨

1. 유닛은 다양한 타입들을 가지고 있으며, 확장자명을 통해 알 수 있음.

2. 몇몇 유닛들은 자동으로 생성되기에 모든 유닛에 대해 일일이 정의할 필요는 없음.

3. Service와 Target은 직접 설정이 필요하며, Mount와 Swap은 /etc/fstab에 의해,

Device는 udev에 의해 자동으로 설정됨.

Page 11: About RHEL7 systemd

11 - Internal Use Only -

Location of unit configuration files

유닛설정파일들의 위치

1. /etc/systemd/system (어드민 커스터마이징 파일들이 위치)

2. /usr/lib/systemd/sytem (rpm패키지에 의해 설치된 디폴트 시스템파일들이 위치)

1. 기본적으로 설정파일들은 위의 두 위치에 존재하며, 설정파일의 이름은

유닛의 이름과 일치함.

2. 중요한 점은 각각의 장소에 같은 이름을 가진 설정파일이 있다면

/etc/systemd/system의 파일이 실행되며, /usr/lib/systemd/system의

파일은 무시된다. 따라서 만약 디폴트 설정의 변경을 원할 시

/usr~/system의 파일을 /etc~/system으로 복사하여 복사본을 변경해야함.

Page 12: About RHEL7 systemd

12 - Internal Use Only -

Basic unit operations

기본적인 유닛 동작방법

추가로 service startup scripts의 비정규 옵션들은 systemd에서는 사용하지 못하며,

위와 같은 메시지를 출력.

분류 상세

systemctl enable/disable <unit명> 자동시작될 유닛들을 지정가능

systemctl start/stop/restart <unit명> 유닛의 start/stop/restart기능. (reload옵션의 경우 해당유닛이 설정파일에 ExecReload 옵션을 가졌을 경우에만 가능)

systemctl status <unit명> 해당하는 유닛의 현재 동작상태를 출력

systemctl daemon-reload systemd가 새로 추가된, 혹은 변경된 유닛들에 대해 scan

Page 13: About RHEL7 systemd

13 - Internal Use Only -

Unit dependencies and orders

유닛의 Dependencies와 Orders

1. 유닛간의 관계에 Dependency와 Order의 두 가지 종류가 존재.

2. Dependency는 어떤 유닛 A가 활성화 시 유닛B도 같이 되어야 함을 의미하며

Order는 어떤 유닛 A는 반드시 유닛 B 이후에 활성화 되어야 함을 의미함.

3. 기동 시에 systemd는 default.target을 활성화 시키며 이 때 default.target의

의존성에 걸려있는 모든 유닛들이 같이 활성화 됨. (Dependency)

Page 14: About RHEL7 systemd

14 - Internal Use Only -

Unit dependencies and orders

주요 dependencies (의존성 트리)

대표적인 dependencies의 예시이며, 예를들어 default.target의 경우

gui환경으로 설치 시에 graphical.target에 심볼릭링크가 되어있는데 이것을 multi-

user.target으로 심볼릭링크로 바꾸고 재부팅하면 runlevel3의 multiuser환경으로 접속됨.

즉, default.target을 바꾸는 것은 runlevel의 변경과 같은 의미를 지님.

Page 15: About RHEL7 systemd

15 - Internal Use Only -

Unit dependencies and orders

Default.target을 통한 runlevel 변경

Runlevel 변경

Page 16: About RHEL7 systemd

16 - Internal Use Only -

Unit dependencies and orders

Dependency와 order의 정의(1)

1. 기동 시에 systemd는 모든 유닛들에 대해서 해당 유닛들이 가진 dependency를

검토하여 동시에 활성화 시키는 것을 시도함.

2. Dependency는 requires와 wants로 정의됨.

requires: 앞서 실행되어야 할 유닛이 기동에 실패했을 경우, 해당 유닛도 실행하지 말 것.

wants: 앞서 실행되어야 할 유닛이 기동에 실패하더라도, 해당유닛은 어떻게든 실행할 것.

3. 추가로 confilcts옵션을 통해 동시에 활성화되지 말아야 할 유닛을 지정할 수 있음.

Page 17: About RHEL7 systemd

17 - Internal Use Only -

Unit dependencies and orders

Dependency와 order의 정의(2)

1. 유닛명.want의 디렉토리들은 서비스들의 자동시작설정파일들을 가지고 있음.

(즉, wants디렉토리는 systemctl enable/disable에 따라 자동시작될 서비스의 심볼릭링크의

등록/해제가 되는 곳)

2. 위의 명령이 실행될 때 want디렉토리엔 wanted by 옵션을 통해 해당 서비스의 심볼릭

링크가생성됨.

Page 18: About RHEL7 systemd

18 - Internal Use Only -

Unit dependencies and orders

Dependency와 order의 정의(3)

1. Order는 before와 after로 정의됨.

2. Before는 해당 유닛이 A, B, C유닛의 실행 전에 실행되어야함을 의미하며,

After는 해당유닛이 A, B, C 유닛의 실행 후에 실행되어야함을 의미함.

3. Target 유닛은 여러 유닛들에 대한 동기화 지점으로 정의됨. (중간지점)

Page 19: About RHEL7 systemd

19 - Internal Use Only -

Unit dependencies and orders

Dependency와 order의 정의(4)

1. systemctl list-dependencies <unit명> 명령으로 dependency와 order들을 확인 가능.

2. basic.target에 대한 before명령 실행 시 해당 화면과 같이 basic.target이 multi-

user.target보다 먼저 실행되어야함을 알 수 있음.

systemctl list-dependencies

basic.target –before --all 실행

Page 20: About RHEL7 systemd

20 - Internal Use Only -

Listing units

유닛 리스트출력

systemctl list-unit-files --type=service 와 같이 –type옵 션을 통해 해당하는 타입들만

출력하는 것이 가능. 이것은 RHEL6의 chkconfig –list와 비슷한데 이것을 7에서 실행할

경우 위와 같이 systemctl list-unit-files를 사용권장하는 메시지를 확인가능.

분류 상세

systemctl list-unit-files 모든 정의된 유닛들과 그 상태들을 출력

systemctl list-units 현재 동작중인, 혹은 동작해야될 유닛들과 그 상태들을 출력

Page 21: About RHEL7 systemd

21 - Internal Use Only -

Listing cgroups

croups 관련내용 출력

위와같이 systemd-cgtop 명령을 실행할 시 프로세스의 cpu 점유율 등과 같은 정보를

출력 가능

분류 상세

systemd-cgls cgoups의 group tree를 출력

systemd-cgtop 그룹이 사용하는 자원에 대해 실시간으로 출력

Page 22: About RHEL7 systemd

22 - Internal Use Only -

Sending signal to process groups

프로세스 kill

killall이 먹히지않는, 예를 들어 postfix.service의 경우

systemctl kill –s9 postfix.service로 postfix.service에 해당하는 모든 프로세스를

종료가능하며 이 메커니즘은 systemctl stop 에도 적용됨.

(즉, systemd가 순차적으로 설정파일에게 ExecStop, SIGTERM, SIGKILL명령을 차례로

보내는 원리를 따름)

분류 상세

kill -9 <pid> killall <프로세스명>

RHEL6에서 사용하던대로 사용가능. (ps –ef옵션검색)

systemctl kill –s9 <프로세스명> 같은 croup에 포함되는 모든 프로세스를 동시에 종료가능.

Page 23: About RHEL7 systemd

23 - Internal Use Only -

Log management mechanism of systemd

systemd에서의 로그관리

1. 기존의 /var/log/에서 여전히 로그파일들을 확인이 가능함.

2. 추가된 journalctl 명령어를 통해 확인이 가능

3. 그림의 /run/systemd/journal/syslog를 RHEL7에서는 rsyslog가 읽을 필요가 없는데 이는

최근버전의 rsyslog가 journald database에 imjournal모듈을 통해 직접접근하기

때문이며, RHEL7에서는 imjournal모듈을 default로 사용하기 때문

Page 24: About RHEL7 systemd

24 - Internal Use Only -

Log management mechanism of systemd

journalctl의 옵션

옵션 상세

journalctl –u <unit명> 해당 유닛과 관련된 로그메세지 출력

journalctl -b 마지막 system boot이후 로그메세지 출력

journalctl -f tail –f 옵션 (마지막10줄 출력)

journalctl -a 긴 메시지를 삭제없이 출력

journalctl --no-pager more옵션 사용없이 출력

journalctl --since=“YYYY-MM-DD hh:mm:ss” 해당날짜/시각 부터의 로그 출력

journalctl --until=“YYYY-MM-DD hh:mm:ss” 해당날짜/시각 까지의 로그 출력

Page 25: About RHEL7 systemd

25 - Internal Use Only -

Disabled with masking

mask옵션으로 서비스 활성화 금지

1. mask 사용 시 systemctl로 해당 서비스를 실행 불가능

2. 이미 실행되고 있는 서비스를 masking해도 종료시키지는 않음

3. masking 시의 /etc/systemd/system 상태

Page 26: About RHEL7 systemd

26 - Internal Use Only -

Reference

Your first dive into systemd

http://www.slideshare.net/enakai/systemd-study-v14e

Page 27: About RHEL7 systemd

감사합니다


Recommended