'자동실행'에 해당하는 글 2건

systemctl 로 자동실행을 설정할 수도 있지만 기존의 init.d 를 사용할 수도 있다.

 

 

1. oracle 서비스 스크립트 작성

 

# vi /etc/rc.d/init.d/oracle

#!/bin/bash
# oracle: Start/Stop Oracle Database 11g R2
#
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
# processname: oracle
 
. /etc/rc.d/init.d/functions
 
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/app/oracle/product/11.2.0/dbhome_1
ORACLE_USER=oracle
 
case "$1" in
'start')
    if [ -f $LOCKFILE ]; then
        echo $0 already running.
        exit 1
    fi
    echo -n $"Starting Oracle Database:"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
    touch $LOCKFILE
    ;;
'stop')
    if [ ! -f $LOCKFILE ]; then
        echo $0 already stopping.
        exit 1
    fi
    echo -n $"Stopping Oracle Database:"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
    su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
    rm -f $LOCKFILE
    ;;
'restart')
    $0 stop
    $0 start
    ;;
'status')
    if [ -f $LOCKFILE ]; then
        echo $0 started.
    else
        echo $0 stopped.
    fi
    ;;
*)
    echo "Usage: $0 [start|stop|status]"
    exit 1
esac
 
exit 0
# End of file

 

 

2. /etc/oratab 수정

 

orcl:/app/oracle/product/11.2.0/dbhome_1:Y

 

부팅시 dbstart 유틸리티를 사용하도록 설정(Y)

 

 

3. chkconfig 등록

 

# chmod 755 /etc/rc.d/init.d/oracle
# chkconfig --add oracle
# chkconfig oracle on

 

 

4. 재부팅 후 프로세스 확인

 

# /etc/init.d/oracle status
oracle started.
# ps ax | grep ora

 


WRITTEN BY
손가락귀신
정신 못차리면, 벌 받는다.

,

systemctl 는 RHEL 7 에 도입된 systemd 를 관리/제어하는 명령어이다. /usr/lib/systemd/system/ 디렉토리에 .service 파일을 만들어 서비스를 추가할 수 있다. Oracle 구동에 필요한 lsnrctl 과 dbstart 역시 직관적으로 사용할 수도 있지만 부팅시 자동실행을 위해 서비스에 등록해 본다.

 

  • /usr/lib/systemd/system/oracle_listener.service
  • /usr/lib/systemd/system/oracle_instance.service

 

 

1. listener 서비스 작성

 

# vi /usr/lib/systemd/system/oracle_listener.service

[Unit]
Description=oracle listener
After=network.target

[Service]
Type=forking
User=oracle
Group=dba
Environment=ORACLE_BASE=/app/oracle
Environment=ORACLE_HOME=/app/oracle/product/11.2.0/dbhome_1
Environment=ORACLE_SID=orcl
ExecStart=/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start
ExecStop=/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl stop

[Install]
WantedBy=multi-user.target

 

 

2. instance 서비스 작성

 

# vi /usr/lib/systemd/system/oracle_instance.service

[Unit]
Description=oracle instance
After=network.target syslog.target

[Service]
Type=forking
User=oracle
Group=dba
Environment=ORACLE_BASE=/app/oracle
Environment=ORACLE_HOME=/app/oracle/product/11.2.0/dbhome_1
Environment=ORACLE_SID=orcl
ExecStart=/app/oracle/product/11.2.0/dbhome_1/bin/dbstart ORACLE_HOME
ExecStop=/app/oracle/product/11.2.0/dbhome_1/bin/dbshut ORACLE_HOME

[Install]
WantedBy=multi-user.target

 

 

3. systemd 에 등록 후 자동실행 설정

 

# systemctl daemon-reload
# systemctl enable oracle_listener.service
# systemctl enable oracle_instance.service

 

 

4. /etc/oratab 수정

 

orcl:/app/oracle/product/11.2.0/dbhome_1:Y

 

부팅시 dbstart 유틸리티를 사용하도록 설정(Y)

 

 

5. 재부팅 후 프로세스 확인

 

 

 


WRITTEN BY
손가락귀신
정신 못차리면, 벌 받는다.

,