becool

20210420 (화) 본문

linux

20210420 (화)

gusalstm 2021. 4. 20. 16:21
반응형

9:31 review

 

# vgextend VGNAME PV

# lvextend LVSIZE LV_DEVICE   (-r옵션 추가)

# resize2fs LV_DEVICE  : ext4

# xfs_growfs LV_DEVICE : xfs

# vgreduce VGNAME PV_DEVICE

# vpremove PV_DEVICE

 

[fdisk 통한 LVM 변환 후]

[root@localhost ~]# pvcreate /dev/sdd1
  Physical volume "/dev/sdd1" successfully created.
[root@localhost ~]# pvcreate /dev/sdd2
  Physical volume "/dev/sdd2" successfully created.
[root@localhost ~]# pvcreate /dev/sde1
  Physical volume "/dev/sde1" successfully created.
[root@localhost ~]# pvdisplay
[root@localhost ~]# vgcreate vgmain /dev/sde1
  Volume group "vgmain" successfully created
[root@localhost ~]# vgdisplay vgmain
[root@localhost ~]# vgextend vgmain /dev/sdd2
  Volume group "vgmain" successfully extended
[root@localhost ~]# vgdisplay vgmain
[root@localhost ~]# lvcreate -n lvtest -l 2560 /dev/vgmain
  Logical volume "lvtest" created.
[root@localhost ~]# lvdisplay 
[root@localhost ~]# vgdisplay 
[root@localhost ~]# mkfs -t ext4 /dev/vgmain/lvtest
[root@localhost ~]# mkdir /mnt/data
[root@localhost ~]# mount -t ext4 /dev/vgmain/lvtest /mnt/data/

[root@localhost ~]# lvextend -L 11G /dev/vgmain/lvtest 
  Size of logical volume vgmain/lvtest changed from 10.00 GiB (2560 extents) to 11.00 GiB (2816 extents).
  Logical volume vgmain/lvtest successfully resized.
[root@localhost ~]# lvextend -L +1G /dev/vgmain/lvtest 
  Size of logical volume vgmain/lvtest changed from 11.00 GiB (2816 extents) to 12.00 GiB (3072 extents).
  Logical volume vgmain/lvtest successfully resized.

[root@localhost ~]# resize2fs /dev/vgmain/lvtest 

[root@localhost ~]# df -hT

 확장완료

============================================

 [sdd2 제거 시나리오]

[root@localhost ~]# vgextend vgmain /dev/sdd1   -> 추가 디스크 
  Volume group "vgmain" successfully extended

[root@localhost ~]# pvmove /dev/sdd2    -> 데이터 이동
  /dev/sdd2: Moved: 0.19%
  /dev/sdd2: Moved: 100.00%
[root@localhost ~]# pvdisplay /dev/sdd2  -> 빈공간 확인

[root@localhost ~]# vgreduce vgmain /dev/sdd2 ->  VG에서 제거
  Removed "/dev/sdd2" from volume group "vgmain"

[root@localhost ~]# pvremove /dev/sdd2  -> PV에서 제거
  Labels on physical volume "/dev/sdd2" successfully wiped.

-r 옵션을 통한 lv 확장과 fs 리사이즈를 한번에 처리 (ext4)

[root@localhost ~]# lvextend -L 13G  /dev/vgmain/lvtest -r

============================================
[lvextend -r 옵션 사용 비교]
[root@localhost ~]# lvcreate -n lvtemp -L 1G vgmain
[root@localhost ~]# lvdisplay /dev/vgmain/lvtemp
[root@localhost ~]# vgdisplay 
[root@localhost ~]# mkfs -t xfs /dev/vgmain/lvtemp
[root@localhost ~]# mkdir /mnt/temp
[root@localhost ~]# mount -t xfs /dev/vgmain/lvtemp /mnt/temp
[root@localhost ~]# mount
[root@localhost ~]# lvextend -L 2G /dev/vgmain/lvtemp   → 증설
  Size of logical volume vgmain/lvtemp changed from 1.00 GiB (256 extents) to 2.00 GiB (512 extents).
  Logical volume vgmain/lvtemp successfully resized.
[root@localhost ~]# xfs_growfs /dev/vgmain/lvtemp  → 파일시스템 리사이즈 (xfs)
[root@localhost ~]# df -hT
[root@localhost ~]# lvextend -L 3G /dev/vgmain/lvtemp -r  → 증설 + 파일시스템 리사이즈 (-r옵션)
[root@localhost ~]# df -hT
============================================

 

Systemd

 기존의 init 프로세스를 대체하는 프로세스로 최신 리눅스 배포판에서 도입된 PID 1번 프로세스이다.

 

Systemd 기능 및 특징

 - init 기반의 시스템에 대한 호환성 제공

 - systemd 유닛에 의한 제어

 - 의존성 기반의 서비스 제어

 - systemctl 사용자 정의 명령어 미지원

 - systemd에 의해 실행된 서비스만 관리

 - 시스템 종료시 실행중인 서비스만 중지

 - 서비스에 5분의 timeout 적용

 - 통합 로그 관리 (systemd-journald)

 

System UNIT 종류

 service unit : 서비스를 제공하기 위한 unit 

 socket unit : systemd에 의해 제어되는 process간의 통신(IPC, 네트워크socket) 등에 대한 정보를 가진 unit

 device unit : device 추가, 파티션 생성등의 작업 수행 시에 생성되는 unit

 mount unit : mount를 관리하는 unit

 swap unit : swap 영역을 관리하는 unit

 target unit : 부팅 타겟을 관리하는 unit

 timer unit :  일정 주기마다 unit 을 실행할때 사용하는 unit 

 

 

UNIT 실행 상태 확인
 - 실행중인 unit 확인
   # systemctl list-units

 - service unit 확인
   # systemctl list-units --type service

 - 시스템의 모든 unit 확인
   # systemctl list-units --all

유닛 제어 명령어 사용방법
  # systemctl  SUBCOMMAND  UNIT

 stop, start, restart, enable, disable 등

[user@localhost system]$ systemctl stop cups.service
Warning: Stopping cups.service, but it can still be activated by:
  cups.path
  cups.socket
[user@localhost system]$ systemctl status cups.service
● cups.service - CUPS Printing Service
   Loaded: loaded (/usr/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Tue 2021-04-20 12:15:37 KST; 2s ago
  Process: 1255 ExecStart=/usr/sbin/cupsd -f (code=exited, status=0/SUCCESS)
 Main PID: 1255 (code=exited, status=0/SUCCESS)
[user@localhost system]$ systemctl start cups.service
[user@localhost system]$ systemctl status cups.service
● cups.service - CUPS Printing Service
   Loaded: loaded (/usr/lib/systemd/system/cups.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2021-04-20 11:32:37 KST; 40min ago
 Main PID: 1255 (cupsd)
    Tasks: 1
   CGroup: /system.slice/cups.service
           └─1255 /usr/sbin/cupsd -f

restart 시 PID 값 갱신됨.

reload 시 PID 값 갱신x 유지

 

disable : 즉시 종료되진 않지만, 부팅될때 실행되지 않음. loaded 참고

● cups.service - CUPS Printing Service
   Loaded: loaded (/usr/lib/systemd/system/cups.service; disabled; vendor preset: enabled)

 

현재 상태 확인

[root@localhost ~]# systemctl list-units   → 전체

[root@localhost ~]# systemctl list-units --type socket → .socket 으로 끝나는 유닛만 출력

 

마스크 - 언마스크

[root@localhost ~]# systemctl mask crond.service

[root@localhost ~]# systemctl stop crond.service 
[root@localhost ~]# systemctl start crond.service
Failed to start crond.service: Unit is masked.

[root@localhost ~]# systemctl unmask crond.service
Removed symlink /etc/systemd/system/crond.service.

 

두 가지 유닛이 충돌되는 경우 하나를 마스킹 하고 다른하나를 작업하는 등에 사용.

[root@localhost ~]# ls -l /etc/systemd/system/crond.service
lrwxrwxrwx. 1 root root 9 Apr 20 13:06 /etc/systemd/system/crond.service -> /dev/null

 

 

================================

init 부팅

 

~CentOS 6.X : 부팅 시 initd 메인 프로세스 동작 > /etc/inittab 파일 내부 내용을 확인하여 부팅할 런레벨 결정

<CentOS 6버전 /etc/inittab 의 런레벨 설명>

# runlevel 로 확인 가능.

runlevel 0 : halt (시스템 종료) >> 시스템 종룡 명령어 init 0 은 런레벨 0 동작
runlevel 1 : single user mode (CLI , only root, 최소한의 service 동작, 백업/복구용으로 사용)
runlevel 2 : multi user mode without NFS (CLI , all user , network 제외)
runlevel 3 : full multi user mode ( CLI , all user, network 포함) 
runlevel 4 : unused (사용하지 않음)
runlevel 5 : X11 (GUI, all user, all service 동작)
runlevel 6 : reboot (시스템 재부팅) >> 시스템 재부팅 명령어 init 6 은 런레벨 6 동작 

================================

systemd 부팅

 

- CentOS 7.0 버전부터 런레벨 방식이 변경

[root@localhost ~]# cat /etc/inittab 
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.

...

 

POWER ON → BIOS/UEFI : power on self test → BOOT Loader

 

default.target

[root@localhost ~]# cd /usr/lib/systemd/system

[root@localhost ~]# vim default.target

[root@localhost ~]# vim graphical.target

[root@localhost ~]# vim multi-user.target

[root@localhost ~]# vim basic.target

[root@localhost ~]# vim sysinit.target

[root@localhost ~]# vim local-fs.target

 

[root@localhost system]# ls -l /usr/lib/systemd/system/runlevel?.target
lrwxrwxrwx. 1 root root 15 Mar 31 12:58 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Mar 31 12:58 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Mar 31 12:58 /usr/lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Mar 31 12:58 /usr/lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Mar 31 12:58 /usr/lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Mar 31 12:58 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Mar 31 12:58 /usr/lib/systemd/system/runlevel6.target -> reboot.target

 

target 대상 목적
graphical.target 멀티유저, 그래픽 & 텍스트 기반 로그인
multi-user.target 멀티유저, 텍스트 기반 로그인
rescue.target sulogin 프롬프트, 기본 시스템 초기화
emergency.target sulogin 프롬프트. initramfs 피벗 완료 / 에 읽기전용, 시스템 루트에 사용

[root@localhost system]# systemctl get-default

graphical.target

[root@localhost system]# systemctl set-default [target] 

[root@localhost system]# systemctl set-default multi-user.target → 부팅 시 전환

 

# systemctl isolate TARGET_UNIT

[root@localhost system]# systemctl isolate multi-user.target → 즉시 전환

 

================================

 

1AA-2104-0858306

Kernel

initramfs

 

 

 

 

 

 

 

728x90

'linux' 카테고리의 다른 글

20210422 (목)  (0) 2021.04.22
20210421 (수)  (0) 2021.04.21
20210419 (월)  (0) 2021.04.19
20210416 (금)  (0) 2021.04.16
20210415 (목)  (0) 2021.04.15
Comments