目录
一、Linux系统-方法1-rc.local方式
1、 修改oracle配置文件/etc/oratab:
mesorcl:/oracle/app/oracle/product/11.2.0/db_1:Y
设置从N 修改为Y,允许启动
2.、在/etc/rc.d/rc.local中加入如下语句即可实现实例与系统一起启动:
su - oracle -c "lsnrctl start" su - oracle -c "dbstart"
二、Linux系统-方法2:systemctl方式(Linux7)
1、 修改oracle配置文件/etc/oratab:
mesorcl:/oracle/app/oracle/product/11.2.0/db_1:Y
2、 在/etc/init.d目录下新建oracle文件,
(1)创建oracle文件
vi /etc/init.d/oracle
#!/bin/sh # chkconfig: 35 80 10 # description: Oracle auto start-stop script. # # Set ORA_HOME to be equivalent to the $ORACLE_HOME # from which you wish to execute dbstart and dbshut; # # Set ORA_OWNER to the user id of the owner of the # Oracle database in ORA_HOME. ORA_HOME=/oracle/app/oracle/product/11.2.0/db_1 ORA_OWNER=oracle #下面判断先去掉,开机启动时总是判断dbstart为非f文件。 #if [ ! -f $ORA_HOME/bin/dbstart ] #then #echo "Oracle startup: cannot start" #exit #fi case "$1" in 'start') # Start the Oracle databases: echo "Starting Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle echo "Done" # Start the Listener: echo "Starting Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle echo "Done." echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle touch /var/lock/subsys/oracle ;; 'stop') # Stop the Oracle Listener: echo "Stoping Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle echo "Done." rm -f /var/lock/subsys/oracle # Stop the Oracle Database: echo "Stoping Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle echo "Done." echo "" echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle ;; 'restart') $0 stop $0 start ;; esac
ORA_HOME根据oracle实际安装路径进行修改。
(2)更改可执行权限
chmod +x /etc/init.d/oracle
3、配置oracle.service服务
(1)在/usr/lib/systemd/system创建oracle.service并编辑
vi /usr/lib/systemd/system/oracle.service
增加如下内容:
[Unit] Description=Oracle RDBMS After=network.target [Service] ExecStart=/etc/init.d/oracle start ExecStop=/etc/init.d/oracle stop RemainAfterExit=yes [Install] WantedBy=multi-user.target
(3)配置权限为非全局可写(644)
chmod 644 /usr/lib/systemd/system/oracle.service
如果如执行,会报错:Please remove executable permission bits. Proceeding anyway.
(4)重新加载
systemctl daemon-reload
3、置开机自启动
systemctl enable oracle systemctl start oracle (启动测试) systemctl stop oracle (停止测试)
三、Linux系统-方法3:service方式(Linux6或7)
1、 修改oracle配置文件/etc/oratab:
mesorcl:/oracle/app/oracle/product/11.2.0/db_1:Y
2、 在/etc/init.d目录下新建oracle文件,
(1)创建oracle文件
vi /etc/init.d/oracle
#!/bin/sh # chkconfig: 35 80 10 # description: Oracle auto start-stop script. # # Set ORA_HOME to be equivalent to the $ORACLE_HOME # from which you wish to execute dbstart and dbshut; # # Set ORA_OWNER to the user id of the owner of the # Oracle database in ORA_HOME. ORA_HOME=/oracle/app/oracle/product/11.2.0/db_1 ORA_OWNER=oracle #下面判断先去掉,开机启动时总是判断dbstart为非f文件。 #if [ ! -f $ORA_HOME/bin/dbstart ] #then #echo "Oracle startup: cannot start" #exit #fi case "$1" in 'start') # Start the Oracle databases: echo "Starting Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle echo "Done" # Start the Listener: echo "Starting Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle echo "Done." echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle touch /var/lock/subsys/oracle ;; 'stop') # Stop the Oracle Listener: echo "Stoping Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle echo "Done." rm -f /var/lock/subsys/oracle # Stop the Oracle Database: echo "Stoping Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle echo "Done." echo "" echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle ;; 'restart') $0 stop $0 start ;; esac
ORA_HOME根据oracle实际安装路径进行修改。
(2)配置为可执行权限
chmod +x /etc/init.d/oracle
3、配置service服务自动启动服务
(1)添加服务
chkconfig --add oracle
(2)增加开启自动启动
chkconfig --level 2345 oracle on
四、Oracle在Windows下随系统启动
1、安装后默认即为自动启动
如果要改为手动,可以选择手动即可。
2、此值默认(可以修改为实例不随oracle服务启动)
这个功能如果把服务和实例启动分开后,我们可以单独startup mount。
(1)打开Oracle菜单
(2)找到数据库
(3)数据库实例是否需要随服务启动
如果不勾选,则和linux下类似,sqlplus / as sysdba后是一个idle instance.
需要手动startup启动。