# 格式: SID:ORACLE_HOME:Y|N
orcl:/u01/app/oracle/product/11.2.0/dbhome_1:Y
將末尾 N 改為 Y,標記該實例允許自啟動。
# 找到行:
ORACLE_HOME_LISTNER=$ORACLE_HOME
# 確保指向正確的 ORACLE_HOME (通常無需改動,若多 Home 需顯式指定)
#!/bin/bash
# 自啟動腳本需可執行權限
chmod +x /etc/rc.d/rc.local
cat >> /etc/rc.d/rc.local <<'EOF'
su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"
su - oracle -c "/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
EOF
ls -l /etc/rc.d/rc.local 確認可執行位 (x)systemctl status rc-local (CentOS 7+) 確認服務啟用ps -ef | grep pmon、lsnrctl statuscat > /etc/systemd/system/oracle-db.service <<'EOF'
[Unit]
Description=Oracle Database & Listener Auto Start
After=network.target syslog.target
[Service]
Type=forking
User=oracle
Group=oinstall
Environment=ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
Environment=ORACLE_SID=orcl
ExecStart=/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart
ExecStop=/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbshut
TimeoutSec=300
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable oracle-db
systemctl start oracle-db
優勢:依賴管理、日誌集中 (journalctl)、啟動超時控制、狀態查詢標準化。
在 /home/oracle/.bash_profile 統一定義:
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
自啟動腳本通過 su - oracle -c 會加載該 Profile,保證環境一致。