一、简单配置方式
在Linux系统中,安装好oracle数据库服务后,并不像在Windows系统下一样,oracle服务在默认情况下会随时系统的启动自动启动。Linux系统中,是需要用户去手动进行设置,才能实现oracle开机自动启动的。 1、查询确认oracle11g后自带的启动关闭脚本是否存在 [oracle oracle]$ cat /etc/oratab 在此脚本的最后一行会记录oracle安装的oracle_home目录,正常情况下在$ORACLE_HOME/bin目录下存在dbstart和dbshut脚本 ls $ORACLE_HOME/bin/dbstart ls $ORACLE_HOME/bin/dbshut ls $ORACLE_HOME/bin/lsnrctl 2、打开oracle设置的关卡,需要使用root用户取修改 [root ~]# vi /etc/oratab 改前:ipems:/u01/app/oracle/product/11.2.0/dbhome_1:N 改后:ipems:/u01/app/oracle/product/11.2.0/dbhome_1:Y 3、手动测试各脚本是否可正常启动,关闭相关服务,使用oracle用户测试 [root ~]# su - oracle [oracle ~]$ /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbshut ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener Usage: /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbshut ORACLE_HOME Processing Database instance "ipems": log file /u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log 测试脚本执行报有错误,监听没有关闭,但oracle数据库正常关闭了。这个脚本默认要传入 ORACLE_HOME参数[oracle ~]$ /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener Usage: /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart ORACLE_HOME Processing Database instance "ipems": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log 测试脚本执行报有错误,监听没有启动,但oracle数据库正常启动了。这个脚本默认要传入 ORACLE_HOME参数 修改两个脚本中的ORACLE_HOME_LISTNER=$1为ORACLE_HOME_LISTNER=$ORACLE_HOME,重新实验,监听和数据库可以正常启动和关闭 [oracle@db bin]$ /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbshut Processing Database instance "ipems": log file /u01/app/oracle/product/11.2.0/dbhome_1/shutdown.log [oracle@db bin]$ lsnrctl status[oracle@db bin]$ /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart
Processing Database instance "ipems": log file /u01/app/oracle/product/11.2.0/dbhome_1/startup.log [oracle@db bin]$ lsnrctl status 4、编辑/etc/rc.d/rc.local文件,调用oracle的启动关闭文件设置开机自启动,需要使用root用户执行 [oracle@db bin]$ su - root Password: [root@db ~]# vi /etc/rc.d/rc.local如果命令需要带参数而有空格时需要用双引号包围起来。
5、测试效果 可以正常开机自启动二、通过配置oracle服务项,通过chkconfig配置开机自启动,及命令方式启动oracle
1、前3个步骤与上述方式一致 2、以root身份建立开机启动oracle服务的脚本/etc/init.d/oracle #!/bin/sh #chkconfig: 35 20 80 #description: Oracle dbstart / dbshut #以上两行为chkconfig所需 ORA_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 ORA_OWNER=oracle LOGFILE=/var/log/oracle.log echo "#################################" >> ${LOGFILE} date +"### %T %a %D: Run Oracle" >> ${LOGFILE} if [ ! -f ${ORA_HOME}/bin/dbstart ] || [ ! -f ${ORA_HOME}/bin/dbshut ]; then echo "Error: Missing the script file ${ORA_HOME}/bin/dbstart or ${ORA_HOME}/bin/dbshut!" >> ${LOGFILE} echo "#################################" >> ${LOGFILE} exit fi start(){ echo "###Startup Database..." su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}" echo "###Done." #echo "###Run database dbconsole..." #su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl start dbconsole" #echo "###Done." } stop(){ #echo "###Stop database control..." #su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl stop dbconsole" #echo "###Done." echo "###Shutdown Database..." su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}" echo "###Done." } case "$1" in 'start') start >> ${LOGFILE} ;; 'stop') stop >> ${LOGFILE} ;; 'restart') stop >> ${LOGFILE} start >> ${LOGFILE} ;; esac date +"### %T %a %D: Finished." >> ${LOGFILE} echo "#################################" >> ${LOGFILE} echo ""注释:
第一行,告诉系统使用的shell,所以的shell脚本都是这样。 第二行,chkconfig后面有三个参数2345,20和80告诉chkconfig程序,需要在rc3.d和rc5.d目录下,创建名字为 S20oracle的文件连接,连接到/etc/init.d目录下的的oracle脚本。第一个字符是S,系统在启动的时候,运行脚本oracle,就会添加一个start参数,告诉脚本,现在是启动模式。同时在rc0.d和rc6.d目录下,创建名字为K80oracle的文件连接,第一个字符为K,系统在关闭系统的时候,会运行oracle,添加一个stop,告诉脚本,现在是关闭模式。 在脚本中通过变量给启动和关闭脚本传入了参数,所以默认脚本即可正常使用(不用修改脚本的ORACLE_HOME_LISTNER)3、设置脚本的可执行权限
[root@db ~]# chmod +x /etc/init.d/oracle 4、手动测试 [root@db ~]# /etc/init.d/oracle start [root@db ~]# /etc/init.d/oracle stop [root@db ~]# /etc/init.d/oracle restart 5、将oracle服务添加到chkconfig中 [root@db ~]# chkconfig --add oracle 注释: 添加完成后可以在 [root@db ~]# ll /etc/rc.d/rc0.d/K80oracle lrwxrwxrwx 1 root root 16 Nov 6 12:53 /etc/rc.d/rc0.d/K80oracle -> ../init.d/oracle [root@db ~]# ll /etc/rc.d/rc6.d/K80oracle lrwxrwxrwx 1 root root 16 Nov 6 12:53 /etc/rc.d/rc6.d/K80oracle -> ../init.d/oracle[root@db ~]# ll /etc/rc.d/rc3.d/S20oracle
lrwxrwxrwx 1 root root 16 Nov 6 12:54 /etc/rc.d/rc3.d/S20oracle -> ../init.d/oracle [root@db ~]# ll /etc/rc.d/rc5.d/S20oracle lrwxrwxrwx 1 root root 16 Nov 6 12:54 /etc/rc.d/rc5.d/S20oracle -> ../init.d/oracle6、可以手动修改oracle服务开机启动的级别
[root@db ~]# chkconfig | grep oracle oracle 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@db ~]# chkconfig --level 24 oracle off You have mail in /var/spool/mail/root [root@db ~]# chkconfig | grep oracle oracle 0:off 1:off 2:off 3:on 4:off 5:on 6:off [root@db ~]# chkconfig --level 35 oracle on [root@db ~]# chkconfig | grep oracle oracle 0:off 1:off 2:off 3:on 4:off 5:on 6:off7、使用简单明了启动关闭oracle
[root@db ~]# service oracle stop [root@db ~]# service oracle start [root@db ~]# su - oracle -c "lsnrctl status" [root@db ~]# su - oracle -c "sqlplus / as sysdba"8、重启测试
以正常开机自启动三、chkconfig命令
Centos6.5系统之前: 1.chkconfig命令用法 语法: chkconfig --list [name] chkconfig --add name chkconfig --del name chkconfig [--level levels] name <on|off|reset> chkconfig [--level levels] name说明:
chkconfig提供一种简单的命令行工具来帮助管理员对/etc/rc[0-6].d目录层次下的众多的符号链接进行直接操作。 此命令使用是由chkconfig命令在IRIX操作系统提供授权。不用在/etc/rc[0-6].d目录下直接维护配置信息,而是直接在/etc/rc[0-6]下管理链接文件。在运行级别的目录下的配置信息通知在将会初始启动哪些服务。Centos7:
#关闭默认初始化的数据库 systemctl stop mysqld.service #启动 systemctl start mysqld@3306 #取消默认实例的开机自启动 systemctl disable mysqld #将自定义实例加入开机自启动 systemctl enable mysqld@3306linux自定义开机启动服务和chkconfig使用方法
服务概述 在linux操作系统下,经常需要创建一些服务,这些服务被做成shell脚本,这些服务需要在系统启动的时候自动启动,关闭的时候自动关闭。 将需要自动启动的脚本/etc/rc.d/init.d目录下,然后用命令chkconfig --add filename将自动注册开机启动和关机关闭。实质就是在rc0.d-rc6.d目录下生成一些文件连接,这些连接连接到/etc/rc.d /init.d目录下指定文件的shell脚本。