본문 바로가기

IT 관련정보/리눅스

리눅스 기본 이론(7) - CD-ROM, 커널 컴파일, 시스템 로그




CD-R

CD-RW ------------>CD-R을 포함----------->CD를 지웠다 썼다를 반복

DVD-R ------------>COMBO (CD-R+CD-RW)

DVD-RW------------>MULTI(CD-R+CD-RW+DVD-R)




1.CD-ROM /DVD-ROM으로 백업하기


*mkisofs 패키지 다운로드 -->iso 이미지를 생성한다

yum install -y mkisofs


*growisofs 패키지 다운로드 -->레코딩 프로그램

yum install -y dvd+rw-tools


*k3b 패키지 다운로드 -->그래픽 레코딩 프로그램

yum install -y k3b


실습]로컬 데이터 백업용 ISO 파일 만들기


mkisofs -r -J -input-charset UTF-8 -o /디렉토리/이미지파일명. iso /백업 경로


-r :긴 파일명 이름 지원


예)사용자 홈디렉토리를 /USER/USER.ISO 백업하기

mkisofs -r -J -input-charset UTF-8 -o /USER/USER.ISO /home/


실습]ISO 이미지 파일 레코딩하기


cdrecord -v speed=배속 -dao driveropts=burnfree -eject dev=디바이스명 -data 이미지 파일명.iso


예)

cdrecord -v speed=40 -dao driveropts=burnfree -eject dev=/dev/hdc -data /USER/USER.ISO


실습] CD-RW 포멧하기 (기록삭제)

cdrecord -v speed=배속 dev=디바이스명 blank=all 또는 blank=fast(권장)


실습]DVD 포멧

dvd+rw-format -force 디바이스명



------------------------------------------------------

시스템 응급복구

리눅스 부팅시 CD로 부팅하여 boot: rescue를 입력한다.


F5 => linux rescue

 

언어>English


키보드 > us


network > no


Rescue > continue | skip


커널 컴파일 순서

커널 소스 파일 압축해제 -> 커널 소스의 설정 값 초기화(make mrproper) -> 

커널 컴파일 옵션 설정 작업(make menuconfig) -> 

커널 이미지 파일 생성 작업(make bzImage) -> 커널 모듈 생성을 위한 컴파일 작업

(make modules) -> 커널 모듈 설치 작업(make modules_install)->커널 모듈 파일 복사,

grub.conf 파일 수정(make install) -> 새로운 커널 사용을 위한 시스템 재부팅



1. 커널 설정 초기화 (make mrproper)

커널 소스를 원상태대로 초기화한다.

이미 설정된 커널 설정값을 모두 초기화시키고, 컴파일된 오브젝트파일을 모두 제거하여 커널 상태를 원래의 소스상태로 되돌려 놓는 초기화 명령이다.

커널소스를 다시 설치하지 않고, 커널 소스 원상태로 돌려놓을때만 사용한다.(자주사용안함)



2. 커널 메뉴 설정(make menuconfig)

make menuconfig, make xconfig, make gconfig 와 같은 다양한 방법으로 커널 메뉴 설정을 할 수 있다.


make xconfig = QT라이브러리 이용한 그래픽 환경

gconfig = GTK+2 라이브러리를 이용한 그래픽 환경


make menuconfig 명령은 text 환경으로 설정한다.


# make menuconfig

make: *** 타겟 `menuconfig'를 만들 규칙이 없음.  멈춤.


위와 같은 에러가 발생할 경우 명령을 실행하는 위치가 잘못되었기 때문에

발생하는 문제로 cd /usr/src/linux 디렉토리(소스가 설치되어있는)로 이동하여

명령을 다시 실행해준다.


3. 커널 컴파일(커널 이미지 생성, make)

이명령을 실행하면 커널이미지와 커널모듈을 함께 컴파일한다.

CPU 아키텍처에 따라서 경로가 다를수 있으며, 디렉토리별로 새로운 커널이미지가 생성된다.



4.커널 모듈 설치(make modules_install)

커널모듈은 /lib/modules/커널버전/kernel)디렉토리에 위치한다.

make 명령으로 컴파일된 모듈은 이 디렉토리로 설치된다.


이 명령을 사용하면 커널에 맞는 디렉토리에 설치할 수 있다.


5.커널 이미지 복사 및 initrd 이미지 생성

컴파일된 커널이미지를 /boot 디렉토리로 복사한다.



실습]커널 컴파일 한번에 실행하기

make; make modules_install;make install


moduleinfo ext3

=>모듈 정보확인


----------------------------------------------------------------------------

시스템 log


리눅스 시스템은 부팅하면서 커널에서 일어나는 모든 기록은 syslogd 데몬과

klogd 데몬에 의해서 /var/log 디렉토리에 로그 파일로 저장된다.


syslogd가 설치되어 있지 않다면 설치해준다.


vi /etc/syslog.conf

선택자 필드 액션 필드


*선택자 필드는 메시지 종류와 메시지 우선순위를 지정할 수 있다

*액션필드는 어느 파일에 로그를 기록할 것인지를 결정한다.


# Log all kernel messages to the console.

# Logging much else clutters up the screen.

#kern.*                                                 /dev/console


# Log anything (except mail) of level info or higher.

# Don't log private authentication messages!

*.info;mail.none;authpriv.none;cron.none                /var/log/messages


# The authpriv file has restricted access.

authpriv.*                                              /var/log/secure


# Log all the mail messages in one place.

mail.*                                                  -/var/log/maillog



# Log cron stuff

cron.*                                                  /var/log/cron


# Everybody gets emergency messages

*.emerg                                                 *


# Save news errors of level crit and higher in a special file.

uucp,news.crit                                          /var/log/spooler


*메시지 우선순위

emerg 0 매우 위한한 상황

alert 1 즉각 조치를 취해야 하는 상황

crit 2 위급은 아니지만 치명적인 시스템 문제가 발생 시

err 3 에러가 방생한 상황

warnig 4 주의를 요하는 상황

notice 5 에러메시지가 아닌 단순 정보메시지

info 6 단순 정보 프로그램

debug 7 프로그램 실행시 발생되는 오류메시지


모든 레벨을 지정할 때는 *기호를 사용한다.

어떤 레벨로 사용하지 않을 때는 none으로 표시한다.

해달 레벨만 적용할 경우 = 기호를 사용한다.

해당 레벨만 제외시킬 경우 ! 기호를 사용한다.


기본설정이 끝나면 syslogd 데몬 재실행


service syslog restart


logrotate


일정 간격으로 로그파일이 백업되도록하여 어느 한계에 도달하면 로그파일을 삭제하여

효율적인 관리를 할 수 있게 해준다.


vi /etc/logrotate.conf


# see "man logrotate" for details

# rotate log files weekly

weekly =>주 단위로


# keep 4 weeks worth of backlogs

rotate 4 =>작업 간격


# create new (empty) log files after rotating old ones

create =>백업 로그파일 생성후에 새로운 로그파일 생성


# uncomment this if you want your log files compressed

#compress =>로그파일 압축


# RPM packages drop log rotation information into this directory

include /etc/logrotate.d =>/etc.logrotate.d 디렉토리를 참조하세요



# no packages own wtmp -- we'll rotate them here

/var/log/wtmp {

    monthly

    minsize 1M

    create 0664 root utmp

    rotate 1

}


실습] rotate 

rotate 지시자로 로그파일을 몇회 간격으로 순환시킬지 결정한다.


/var/log/messages 파일이 생성되고


cat /var/log/secure


/var/log/wtmp {

    monthly

    minsize 1M

    create 0664 root utmp

    rotate 1

}


로그 분석도구(logwatch)

logwatch는 centos는 기본으로 제공하고, cron 데몬으로 주기적으로 동작하여

하루 단위 체계로 로그를 시스템 관리자에게 메일을 보내주는 도구이다.

관리자는 메일만 등록해주면 매일 시스템에 관한 사항들을 모니터링 할  수 있게 된다.


*로그와치 설치

yum install -y log watch


*환경설정

cp /usr/share/logwatch/default.conf/logwatch.conf /etc/logwatch/conf/logwatch.conf


vi/etc/logwatch/conf/logwatch.conf


LogDir=/var/log

TmpDir=/var/cache/logwatch

MailRo=관리자계정(이메일주소)

Range = yesterdat 로그를 보고할 시간 범위(All/today/yesterday)

Detail = Low

Service =ALL

Logfile = messages

mail = "sendmail -t" 로그발송 메일을 센드메일로 지정한다.


# Default Log Directory

# All log-files are assumed to be given relative to this directory.

LogDir = /var/log


# You can override the default temp directory (/tmp) here

TmpDir = /var/cache/logwatch


# Default person to mail reports to.  Can be a local account or a

# complete email address.

MailTo = root


# The default time range for the report...

# The current choices are All, Today, Yesterday

Range = yesterday


# The 'Service' option expects either the name of a filter

# (in /usr/share/logwatch/scripts/services/*) or 'All'.

# The default service(s) to report on.  This should be left as All for

# most people.

Service = All



실습]오후 4시 30분에 cron에 의해 logwatch가 동작해서 관리자에게 메일을 발송하도록 한다.