프린트 하기

OS환경 : Oracle Linux 7.5 (64bit)


DB 환경 : Oracle Database 19.3.0.0


방법 : 오라클 19c 자동실행 설정

서버 기동 시 오라클DB와 리스너가 자동으로 기동되게 끔 설정하는 방법



oratab 파일 확인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ cat /etc/oratab 
#
 
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.
 
# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third field indicates
# to the dbstart utility that the database should , "Y", or should not,
"N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcl:/app/oracle/product/19c:N



기존에는 N으로 되어있는데 Y로 변경

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ cat /etc/oratab 
#
 
# This file is used by ORACLE utilities.  It is created by root.sh
# and updated by either Database Configuration Assistant while creating
# a database or ASM Configuration Assistant while creating ASM instance.
 
# A colon, ':', is used as the field terminator.  A new line terminates
# the entry.  Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively.  The third field indicates
# to the dbstart utility that the database should , "Y", or should not,
"N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
orcl:/app/oracle/product/19c:Y



기동 정지용 스크립트 생성

/home/oracle/start_all.sh 파일 생성

1
2
3
4
5
6
7
8
9
$ cat start_all.sh
#!/bin/bash
/home/oracle/.bash_profile
 
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
 
dbstart \$ORACLE_HOME



/home/oracle/stop_all.sh 파일 생성

1
2
3
4
5
6
7
8
9
$ cat stop_all.sh
#!/bin/bash
/home/oracle/.bash_profile
 
export ORAENV_ASK=NO
. oraenv
export ORAENV_ASK=YES
 
dbshut \$ORACLE_HOME



위 파일에 실행 권한 부여

1
2
$ chown oracle:dba /home/oracle/st*_all.sh
$ chmod u+/home/oracle/st*_all.sh



서비스 등록을 위한 파일생성

root 권한으로 /lib/systemd/system/{SID}.service 파일 생성

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# cat /lib/systemd/system/orcl.service
[Unit]
Description=The Oracle Database Service
After=syslog.target network.target
 
[Service]
# systemd ignores PAM limits, so set any necessary limits in the service.
Not really a bug, but a feature.
# https://bugzilla.redhat.com/show_bug.cgi?id=754285
LimitMEMLOCK=infinity
LimitNOFILE=65535
 
#Type=simple
# idle: similar to simple, the actual execution of the service binary is delayed
#       until all jobs are finished, which avoids mixing the status output with shell output of services.
RemainAfterExit=yes
User=oracle
Group=dba
Restart=no
ExecStart=/bin/bash -'/home/oracle/start_all.sh'
ExecStop=/bin/bash -'/home/oracle/stop_all.sh'
 
[Install]
WantedBy=multi-user.target



새로 생성한 서비스를 systemd 가 인식할 수 있도록 리로드 작업 진행

1
# systemctl daemon-reload



서비스 시작 전 프로세스 확인

1
2
3
4
5
$ ps -ef | grep tns
root        15     2  0 10:57 ?        00:00:00 [netns]
oracle   13512  9474  0 11:11 pts/0    00:00:00 grep --color=auto tns
$ ps -ef | grep pmon
oracle   13516  9474  0 11:12 pts/0    00:00:00 grep --color=auto pmon

db와 리스너가 내려가 있음



서비스 시작 후 재기동 시 자동으로 오라클이 실행됨

1
2
3
# systemctl start orcl.service
# systemctl enable orcl.service
Created symlink from /etc/systemd/system/multi-user.target.wants/orcl.service to /usr/lib/systemd/system/orcl.service.



서비스 시작 후 프로세스 확인

1
2
3
4
5
6
$ ps -ef | grep tns
root        15     2  0 10:57 ?        00:00:00 [netns]
oracle   13512  9474  0 11:11 pts/0    00:00:00 grep --color=auto tns
$ ps -ef | grep pmon
oracle   13609     1  0 11:13 ?        00:00:00 ora_pmon_orcl
oracle   13962  9474  0 11:13 pts/0    00:00:00 grep --color=auto pmon

db는 정상적으로 기동됬지만 리스너는 기동되지 않음



서비스 확인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# systemctl status orcl.service
?? orcl.service - The Oracle Database Service
   Loaded: loaded (/usr/lib/systemd/system/orcl.service; enabled; vendor preset: disabled)
   Active: active (exited) since Mon 2020-06-08 14:41:36 KST; 19s ago
  Process: 9257 ExecStart=/bin/bash -/home/oracle/start_all.sh (code=exited, status=0/SUCCESS)
 Main PID: 9257 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/orcl.service
           ???€9378 ora_pmon_orcl
           ???€9380 ora_clmn_orcl
           ???€9382 ora_psp0_orcl
           ???€9384 ora_vktm_orcl
           ???€9388 ora_gen0_orcl
           ???€9390 ora_mman_orcl
           ???€9394 ora_gen1_orcl
           ???€9397 ora_diag_orcl
           ???€9399 ora_ofsd_orcl
           ???€9402 ora_dbrm_orcl
           ???€9404 ora_vkrm_orcl
           ???€9406 ora_svcb_orcl
           ???€9408 ora_pman_orcl
           ???€9410 ora_dia0_orcl
           ???€9412 ora_dbw0_orcl
           ???€9414 ora_lgwr_orcl
           ???€9416 ora_ckpt_orcl
           ???€9418 ora_smon_orcl
           ???€9420 ora_smco_orcl
           ???€9422 ora_reco_orcl
           ???€9424 ora_w000_orcl
           ???€9426 ora_lreg_orcl
           ???€9428 ora_w001_orcl
           ???€9430 ora_pxmn_orcl
           ???€9434 ora_mmon_orcl
           ???€9436 ora_mmnl_orcl
           ???€9438 ora_d000_orcl
           ???€9440 ora_s000_orcl
           ???€9442 ora_tmon_orcl
           ???€9448 ora_m000_orcl
           ???€9455 ora_tt00_orcl
           ???€9457 ora_tt01_orcl
           ???€9459 ora_tt02_orcl
           ???€9461 ora_aqpc_orcl
           ???€9468 ora_cjq0_orcl
           ???€9494 ora_w002_orcl
           ???€9731 ora_m001_orcl
           ???€9733 ora_m002_orcl
           ???€9752 ora_w003_orcl
           ???€9758 ora_m003_orcl
           ???€9761 ora_s001_orcl
           ???€9764 ora_w004_orcl
           ???€9769 ora_qm02_orcl
           ???€9771 ora_q001_orcl
           ???€9773 ora_qm03_orcl
           ???€9775 ora_q003_orcl
           ???€9777 ora_q004_orcl
 
Jun 08 14:41:36 oel7 systemd[1]: Started The Oracle Database Service.
Jun 08 14:41:36 oel7 bash[9257]: stty: standard input: Inappropriate ioctl for device
Jun 08 14:41:36 oel7 bash[9257]: The Oracle base remains unchanged with value /app/oracle
Jun 08 14:41:36 oel7 bash[9257]: mkdir: cannot create directory ??$ORACLE_HOME??: Permission denied
Jun 08 14:41:36 oel7 bash[9257]: Failed to auto-start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr
Jun 08 14:41:36 oel7 bash[9257]: Processing Database instance "orcl": log file /app/oracle/product/19c/rdbms/log/startup.log

8번째 줄부터 54번째 줄까지가 서비스 기동시 기동된 프로세스 목록임

상태 확인 시 아래에 몇가지 메세지가 발생함



확인해봐야 할 두가지 메세지

1
2
mkdir: cannot create directory ??$ORACLE_HOME??: Permission denied
Failed to auto-start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr



해당 내용은 $ORACLE_HOME/bin/dbstart 쉘 안에서 실행된 내용임

110번째 라인을 보면 mkdir 구문이 있는데 이부분에서 Permission denied 메세지가 발생함

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ vi $ORACLE_HOME/bin/dbstart
110번 라인
  # Determine location of listener.log
  mkdir --- $ORACLE_BASE_HOME/network/log
  LOG=$ORACLE_BASE_HOME/network/log/listener.log
 
  # Start Oracle Net Listener
  if [ -x $ORACLE_HOME/bin/tnslsnr ] ; then
    echo "$0: Starting Oracle Net Listener" >> $LOG 2>&1
    $ORACLE_HOME/bin/lsnrctl start >> $LOG 2>&1 &
    VER10LIST=`$ORACLE_HOME/bin/lsnrctl version | grep "LSNRCTL for " | cut -d' ' -f5 | cut -d'.' -f1`
    export VER10LIST
  else
    echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr"
  fi
fi



mkdir 윗 라인에 export 구문 추가 후 $ORACLE_BASE_HOME을 $ORACLE_HOME으로 변경

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ vi $ORACLE_HOME/bin/dbstart
110번 라인
  # Determine location of listener.log
  export ORACLE_HOME=/app/oracle/product/19c
  mkdir --- $ORACLE_HOME/network/log
  LOG=$ORACLE_HOME/network/log/listener.log
 
  # Start Oracle Net Listener
  if [ -x $ORACLE_HOME/bin/tnslsnr ] ; then
    echo "$0: Starting Oracle Net Listener" >> $LOG 2>&1
    $ORACLE_HOME/bin/lsnrctl start >> $LOG 2>&1 &
    VER10LIST=`$ORACLE_HOME/bin/lsnrctl version | grep "LSNRCTL for " | cut -d' ' -f5 | cut -d'.' -f1`
    export VER10LIST
  else
    echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME/bin/tnslsnr"
  fi
fi



root 계정으로 서비스 재시작 후 상태 확인

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# systemctl stop orcl.service
# systemctl start orcl.service
# systemctl status orcl.service
?? orcl.service - The Oracle Database Service
   Loaded: loaded (/usr/lib/systemd/system/orcl.service; enabled; vendor preset: disabled)
   Active: active (exited) since Wed 2020-06-10 11:18:13 KST; 19s ago
  Process: 14279 ExecStop=/bin/bash -/home/oracle/stop_all.sh (code=exited, status=0/SUCCESS)
  Process: 14442 ExecStart=/bin/bash -/home/oracle/start_all.sh (code=exited, status=0/SUCCESS)
 Main PID: 14442 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/orcl.service
           ???€14481 /app/oracle/product/19c/bin/tnslsnr LISTENER -inherit
           ???€14582 ora_pmon_orcl
           ???€14584 ora_clmn_orcl
           ???€14586 ora_psp0_orcl
           ???€14588 ora_vktm_orcl
           ???€14592 ora_gen0_orcl
           ???€14594 ora_mman_orcl
           ???€14598 ora_gen1_orcl
           ???€14602 ora_diag_orcl
           ???€14606 ora_ofsd_orcl
           ???€14614 ora_dbrm_orcl
           ???€14616 ora_vkrm_orcl
           ???€14618 ora_svcb_orcl
           ???€14620 ora_pman_orcl
           ???€14622 ora_dia0_orcl
           ???€14624 ora_dbw0_orcl
           ???€14626 ora_lgwr_orcl
           ???€14628 ora_ckpt_orcl
           ???€14630 ora_smon_orcl
           ???€14632 ora_smco_orcl
           ???€14634 ora_w000_orcl
           ???€14636 ora_reco_orcl
           ???€14638 ora_w001_orcl
           ???€14640 ora_lreg_orcl
           ???€14642 ora_pxmn_orcl
           ???€14646 ora_mmon_orcl
           ???€14648 ora_mmnl_orcl
           ???€14650 ora_d000_orcl
           ???€14652 ora_s000_orcl
           ???€14654 ora_tmon_orcl
           ???€14660 ora_m000_orcl
           ???€14666 ora_tt00_orcl
           ???€14668 ora_tt01_orcl
           ???€14670 ora_tt02_orcl
           ???€14672 ora_aqpc_orcl
           ???€14674 ora_qm02_orcl
           ???€14676 ora_q001_orcl
           ???€14678 ora_qm03_orcl
           ???€14680 ora_cjq0_orcl
           ???€14906 ora_w002_orcl
           ???€14922 ora_m001_orcl
           ???€14924 ora_m002_orcl
           ???€14947 ora_w003_orcl
           ???€14950 ora_s001_orcl
 
Jun 10 11:18:13 oel7 systemd[1]: Started The Oracle Database Service.
Jun 10 11:18:13 oel7 bash[14442]: stty: standard input: Inappropriate ioctl for device
Jun 10 11:18:13 oel7 bash[14442]: The Oracle base remains unchanged with value /app/oracle
Jun 10 11:18:13 oel7 bash[14442]: Processing Database instance "orcl": log file /app/oracle/product/19c/rdbms/log/startup.log

11번째 줄부터 54번째 줄까지가 서비스 기동시 기동된 프로세스 목록임

db와 리스너가 정상적으로 기동됨



참조 : 

https://oracle-base.com/articles/19c/oracle-db-19c-installation-on-oracle-linux-7

https://oracle-base.com/articles/linux/linux-services-systemd#creating-linux-services