본문 바로가기

Linux/Exercise

데몬을 런레벨에 추가하기 - 소스로 설치시

데몬을 런레벨에 추가/삭제 하기

데몬을 rpm으로 설치할 경우 /etc/rec.d/init.d/ 디렉토리에 설치되어 자동으로 등록이 되지만
소스로 설치한 경우에는 각 설치 디렉토리에 실행데몬이 설치되므로
다음과 같은 설정을 하면 ntsysv나 chkconfig 명령을 통해 시스템 부팅시 on/off가 가능하다.

예) 아파치 웹서버 추가

www.apche.org
-> http server -> download -> ver.2.2.10.tar.gz  다운로드

#cd /root/Desktop
- 파일을 다운 받은 폴더로 이동

#cp httpd-2.2.10.tar.gz /usr/local/src
- /usr/local/src 폴더에 프로그램이 설치됨(대부분의 리눅스 시스템)

#tar -zxvf httpd-2.2.10.tar.gz
- httpd-2.2.10.tar.gz 폴더를 압축해제

#cd httpd-2.2.10
-압축이 풀린 폴더로 이동

#./configure
- 설치 기본 환경설정

#make
- 컴파일

#make install
- 설치

#cd /usr/local/apache2
- 기본적으로 설치되는 폴더

#cd bin
- 실행파일이 있는 폴더

#./apachectl start
-아파치 서버 시작

#./apachectl stop
-아파치 서버 종료

#cp apachectl /etc/rc.d/init.d/
- 실행파일 복사

#cd /etc/rc.d/init.d

#vi httpd

--------------- 이부분만 복사 ---------------------------
  #!/bin/bash
  #
  # httpd        Startup script for the Apache HTTP Server
  #
  # chkconfig: - 35 85 15
  # description: Apache is a World Wide Web server.  It is used to serve \
  #              HTML files and CGI.
---------------------------------------------------

#vi apachectl
- 전 단계에서 복사한 내용을 맨 위에 복사한다.
- 여기의 경로는 /etc/rc.d/init.d/apachectl

#chkconfig --add apachectl
- 서비스를 추가한다.

#ntsysv
- 서비스 항목에서 apachectl을 선택한다.

#reboot
- 재부팅한다.


또는

ntsysv에 추가 하지 않고 /etc/rc.d/rc.local에 추가해서 재부팅후에도 계속 사용할수 있다.

#vi etc/rc.d/rc.local
- /usr.local/apache2/bin/apachectl start 를 추가한다.

#reboot

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

아파치의 로그파일이 일주일에 한번씩 4번 로테이트 되도록 설정하는 방법

- 소스파일로 설치한 경우에는 설치 폴더 하위폴더로 logs폴더가 생긴다.
이것을 logrotate를 이용해 로그 파일을 백업한다.

#vi /etc/logrotate.conf

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    minsize 1M
    create 0664 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.
/usr/local/apache2/logs/* {
    weekly
    rotate 4
}

이 부분을 추가한다.

제대로 백업되는지 확인해본다.

# cd /usr/local/apache2/logs
# logrotate -f /etc/logrotate.conf      - logrotate을 강제로 실행
# ls
access_log    error_log    httpd.pid    httpd.pid.1.1    httpd.pid.1.2  httpd.pid.2.1
access_log.1  error_log.1  httpd.pid.1  httpd.pid.1.1.1  httpd.pid.2    httpd.pid.3