Hướng dẫn cài đặt chức năng autostart database trên Centos
Bước 1: Tạo file autostart
Tạo file /etc/init.d/dbora:
vi /etc/init.d/dbora
Thêm nội dung sau vào file vừa tạo:
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database software.
ORA_OWNER=oracle
case "$1" in
'start')
# Start the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
# Remove "&" if you don't want startup as a background process.
su - $ORA_OWNER -c "/home/oracle/scripts/startup.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1" &
touch /var/lock/subsys/dbora
;;
'stop')
# Stop the Oracle databases:
# The following command assumes that the oracle login
# will not prompt the user for any values
su - $ORA_OWNER -c "/home/oracle/scripts/shutdown.sh >> /home/oracle/scripts/startup_shutdown.log 2>&1"
rm -f /var/lock/subsys/dbora
;;
esac
Phân quyền cho file vừa tạo:
chmod 750 /etc/init.d/dbora
Cài đặt autostart file trên khi khởi động:
chkconfig --add dbora
Bước 2: Tạo scripts startup.sh và shutdown.sh
Tạo thư mục /home/oracle/scripts và phân quyền cho thư mục:
mkdir -p /home/oracle/scripts
chown oracle.oinstall /home/oracle/scripts
Tạo file startup.sh:
vi /home/oracle/scripts/startup.sh
Với nội dung sau:
#!/bin/bash
# Start Listener
lsnrctl start
# Start Database
sqlplus / as sysdba << EOF
STARTUP;
EXIT;
EOF
Tương tự tạo file shutdown.sh:
vi /home/oracle/scripts/shutdown.sh
Với nội dung:
#!/bin/bash
# Stop Database
sqlplus / as sysdba << EOF
SHUTDOWN IMMEDIATE;
EXIT;
EOF
# Stop Listener
lsnrctl stop
Phân quyền cho file startup.sh và shutdown.sh
chmod u+x /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
chown oracle.oinstall /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
Finish!!!
Có thể test database đã autostart chưa bằng cách khởi động lại server hoặc dùng lệnh sau:
service dbora stop
service dbora start