CAB TA 4기 19일차의 기록

Urban Jungle·2025년 4월 8일

CAB TA 4기

목록 보기
19/28

통합 시스템 설정 실습

1. root 비밀번호 설정

passwd root

  • 비밀번호로 cccr1234 입력

2. GRUB 타이머 10초 설정

vim /etc/default/grub

  • GRUB_TIMEOUT=10 으로 수정

grub2-mkconfig -o /boot/grub2/grub.cfg

3. eth1 고정 IP 설정

nmcli con add con-name static1 ifname eth1 type ethernet ip4 192.168.56.211/24
nmcli con up static1

4. 인터넷 repo 설정

cd /etc/yum.repos.d/
mkdir backup
mv *.repo backup/

vim net.repo

[NET_BaseOS]
name=BaseOS
baseurl=http://dl.rockylinux.org/$contentdir/$releasever/BaseOS/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9

[NET_AppStream]
name=AppStream
baseurl=http://dl.rockylinux.org/$contentdir/$releasever/AppStream/$basearch/os/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-Rocky-9

dnf makecache

5. /dev/sdb 파티션 (4,4,6,6)

fdisk /dev/sdb

  • n → primary → +4G, +4G, +6G, +6G
  • w로 저장

partprobe
lsblk

6. 포맷 및 마운트

mkfs.xfs /dev/sdb1
mkdir /mnt1
mount /dev/sdb1 /mnt1
vim /etc/fstab
/dev/sdb1 /mnt1 xfs defaults 0 0

mkswap /dev/sdb2
swapon /dev/sdb2
echo "/dev/sdb2 swap swap defaults 0 0" >> /etc/fstab

7. LVM 설정

pvcreate /dev/sdb3 /dev/sdb4
vgcreate vg0 /dev/sdb3 /dev/sdb4
lvcreate -n lv01 -L 4G vg0
mkfs.xfs /dev/vg0/lv01
mkdir /home1
echo "/dev/vg0/lv01 /home1 xfs defaults 0 0" >> /etc/fstab
mount -a

8. lv01 확장

lvextend -L +2G /dev/vg0/lv01
xfs_growfs /home1

9. 사용자 default home 디렉토리 변경

vim /etc/default/useradd

  • HOME=/home1 으로 변경

10. user01 생성 + sudo 권한

useradd user01
passwd user01
usermod -aG wheel user01

11. 그룹 및 디렉토리 설정

groupadd sggroup
mkdir -p /ptest/dir01 /ptest/dir02
chgrp sggroup /ptest/dir01
chmod 2775 /ptest/dir01

12. cron 등록

crontab -e -u user01
0 17 31 1 * date >> /ptest/dir02/datefile

13. httpd 설치 및 활성화

dnf install -y httpd
systemctl enable httpd --now


web 실습

Apache 가상 호스트 설정 (HTTP 기반)

설정 파일 위치

/etc/httpd/conf.d/

가상 호스트 vhost0

vi /etc/httpd/conf.d/00-vhost.conf

<VirtualHost *:80>
    DocumentRoot /var/www/html0
    ServerName vhost0.cccr1.org
    ServerAlias vhost0
</VirtualHost>

<Directory /var/www/html0>
    AllowOverride None
    Require all granted
</Directory>

mkdir /var/www/html0
echo vhost0 > /var/www/html0/index.html

가상 호스트 vhost1

vi /etc/httpd/conf.d/01-vhost.conf

<VirtualHost *:80>
    DocumentRoot /var/www/html1
    ServerName vhost1.cccr1.org
    ServerAlias vhost1
</VirtualHost>

<Directory /var/www/html1>
    AllowOverride None
    Require all granted
</Directory>

mkdir /var/www/html1
echo vhost1 > /var/www/html1/index.html

/etc/hosts 에 가상호스트 도메인 매핑

vi /etc/hosts

192.168.56.100    server.cccr1.org  vhost0.cccr1.org  vhost0  vhost1.cccr1.org  vhost1

httpd 서비스 시작 및 방화벽 설정

systemctl start httpd

firewall-cmd --add-service=http --permanent
firewall-cmd --reload

정상 동작 확인

curl server.cccr1.org
curl vhost0
curl vhost1

HTTPS 리다이렉션 설정

방법 1: 간단한 리다이렉트

RewriteEngine on
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

방법 2: 다양한 조건에 따른 리다이렉트

RewriteEngine on
RewriteMap lowercase int:tolower

RewriteCond "${lowercase:%{HTTPS}}" !on
RewriteCond "${lowercase:%{REQUEST_SCHEME}}" !https
RewriteCond "${lowercase:%{SERVER_PORT}}" !443

RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

  • 위 조건이 하나라도 만족되면, HTTPS로 강제 리다이렉션이 수행됨

HTTPS 실습

SSL 관련 패키지 설치 및 인증서 생성

yum -y install mod_ssl

openssl genrsa -out private.key 2048
openssl req -new -key private.key -out cert.csr
openssl x509 -req -signkey private.key -in cert.csr -out cert.crt

chmod 600 private.key cert.crt
mv private.key /etc/pki/tls/private/
mv cert.* /etc/pki/tls/certs/

Apache SSL 설정 수정 (/etc/httpd/conf.d/ssl.conf)

vi /etc/httpd/conf.d/ssl.conf

수정 포인트

  • DocumentRoot "/var/www/html" → 제거
  • ServerName server.cccr1.org:443 → 추가 또는 수정
  • SSLCertificateFile/etc/pki/tls/certs/cert.crt
  • SSLCertificateKeyFile/etc/pki/tls/private/private.key

HTTP → HTTPS 리다이렉션 설정 (가상호스트)

/etc/httpd/conf.d/00-vhost.conf

<VirtualHost *:80>
    DocumentRoot /var/www/html0
    ServerName vhost0.cccr1.org
    ServerAlias vhost0
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<Directory /var/www/html0>
    AllowOverride None
    Require all granted
</Directory>

/etc/httpd/conf.d/01-vhost.conf

<VirtualHost *:80>
    DocumentRoot /var/www/html1
    ServerName vhost1.cccr1.org
    ServerAlias vhost1
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
</VirtualHost>

<Directory /var/www/html1>
    AllowOverride None
    Require all granted
</Directory>

Apache 서비스 재시작 및 방화벽 설정

systemctl restart httpd

firewall-cmd --add-service=https --permanent
firewall-cmd --reload


profile
똑똑해지고 싶은 공학도

0개의 댓글