Link tham khảo:
- http://www.oracle-base.com/articles/linux/automating-database-startup-and-shutdown-on-linux.php
- http://www.rpm-based.org/how-to-manage-services-with-chkconfig-and-service
Đầu tiên, tạo thư mục chứa các script và cấp quyền sở hữu cho thư mục đó
Trong đó, user mình đang dùng là oracle, group là oracle luôn.mkdir -p /home/oracle/scripts
chown oracle.oracle/home/oracle/scripts
Dùng user root tạo file "/etc/init.d/dbora"
touch /etc/init.d/dboraSau đó chép đoạn nội dung này 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
Trong đó ORA_OWNER là user linux sở hữu database, của mình là user oracle (đa phần là vậy).
Cấp quyền cho file vừa tạo
chmod 750 /etc/init.d/dbora
Cấu hình để chạy file tự động khi khởi động cùng server
chkconfig --add dbora
Tạo script startup
touch /home/oracle/scripts/startup.shChép nội dung này vào file vừa tạo
#!/bin/bash
# cấu hình biến môi trường, giống file .bash_profile của user oracle
PATH=$PATH:$HOME/bin export PATH export ORACLE_BASE=/home/oracle/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1 export NLS_LANG=american_america.al32utf8 export PATH=$ORACLE_HOME/bin:$PATH export ORACLE_SID=orcl
ORAENV_ASK=NO . oraenv ORAENV_ASK=YES # Start Listener lsnrctl start # Start Database sqlplus / as sysdba << EOF STARTUP; EXIT; EOF
Tạo script shutdown
touch /home/oracle/scripts/shutdown.shChép nội dung này vào file vừa tạo
#!/bin/bash # cấu hình biến môi trường, giống file .bash_profile của user oracle PATH=$PATH:$HOME/bin export PATH export ORACLE_BASE=/home/oracle/app/oracle export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1 export NLS_LANG=american_america.al32utf8 export PATH=$ORACLE_HOME/bin:$PATH export ORACLE_SID=orcl
ORAENV_ASK=NO . oraenv ORAENV_ASK=YES # Stop Database sqlplus / as sysdba << EOF SHUTDOWN IMMEDIATE; EXIT; EOF # Stop Listener lsnrctl stop
Cấp quyền thực thi và quyền sở hữu 2 file này cho user oracle, group oracle
chmod u+x /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
chown oracle.oracle /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh
Ok xong rồi, có thể test thử lại bằng lệnh sau
Start database instance
service dbora startStop database instance
service dbora stop
Hoặc reboot lại server sẽ thấy sau khi server reboot, database instance sẽ tự động start lên
Chúc vui !
Không có nhận xét nào:
Đăng nhận xét