设为首页 收藏本站
查看: 695|回复: 0

[经验分享] linux中配置oracle11g R2与tomcat先后启动

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-4-9 10:08:25 | 显示全部楼层 |阅读模式
参考自(亲自试验,并稍作修改):

http://www.oracle-base.com/artic ... utdown-on-linux.php
support.filecatalyst.com/index.php?/Knowledgebase/Article/View/210/0/starting-tomcat-as-a-linux-service

tomcat加入服务并设置自启动在另一篇:http://www.yunvn.com/thread-16975-1-1.html

oracle数据库安装见:http://www.yunvn.com/thread-16974-1-1.html
1、编辑/etc/oradb文件,将每个数据库实例的重启标志由N都设置为Y:
su root  
gedit /etc/oratab  

修改后如下:
# The first and second fields are the system identifier and home  
# directory of the database respectively.  The third filed indicates  
# to the dbstart utility that the database should , "Y", or should not,  
# "N", be brought up at system boot time.  
#  
# Multiple entries with the same $ORACLE_SID are not allowed.  
#  
#  
sunlight:/home/oracle/product/11.2/db_1:Y  

2、新建/etc/init.d/oracle文件,并添加如下配置:

su root:  
gedit /etc/init.d/oracle                  
添加如下内容:
#!/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为在linux中安装oracle数据库时建立的属于dba组的用户名oracle,而非登陆oracle数据库时的用户名  
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  

3、修改2中oracle文件的权限:
su root  
[iyunv@JTWF Desktop]# chmod 750 /etc/init.d/oracle  

4、设置oracle服务的运行级别,及设置自启动:
[iyunv@JTWF Desktop]# chkconfig --add oracle  
[iyunv@JTWF Desktop]#  

5、创建startup.sh与shutdown.sh脚本,并修改隶属用户及组(位于/home/oracle/scripts)
# mkdir -p /home/oracle/scripts  
# chown oracle.oinstall /home/oracle/scripts  
[iyunv@JTWF Desktop]# chown oracle.dba /home/oracle/scripts  


/home/oracle/scripts/startup.sh脚本内容如下:
#!/bin/bash  

export TMP=/tmp  
export TMPDIR=$TMP  
export PATH=/usr/sbin:/usr/local/bin:$PATH  
export ORACLE_HOSTNAME=JTWF  
#export ORACLE_UNQNAME=db12c  

export ORACLE_SID=sunlight  
ORAENV_ASK=NO  
. oraenv  
ORAENV_ASK=YES  

# Start Listener  
lsnrctl start  

# Start Database  
sqlplus / as sysdba << EOF  
STARTUP;  
EXIT;  
EOF  



/home/oracle/scripts/shutdown.sh脚本内容如下:
#!/bin/bash  

export TMP=/tmp  
export TMPDIR=$TMP  
export PATH=/usr/sbin:/usr/local/bin:$PATH  
export ORACLE_HOSTNAME=JTWF  
#export ORACLE_UNQNAME=db12c  

export ORACLE_SID=sunlight  
ORAENV_ASK=NO  
. oraenv  
ORAENV_ASK=YES  

# Stop Database  
sqlplus / as sysdba << EOF  
SHUTDOWN IMMEDIATE;  
EXIT;  
EOF  

说明:(1)、#export ORACLE_UNQNAME=db12c该项配置有无均可
          (2)、ORACLE_HOSTNAME在默认安装完Oracle数据库后,默认为localhost,最好能修改ip地址到机器名的映射,具体见:http://www.yunvn.com/thread-16950-1-1.html

          (3)、ORACLE_SID在Oracle数据库时配置环境变量时已配置。


6、修改上述两个脚本的权限及所有者:
[iyunv@JTWF admin]# chmod u+x /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh  
[iyunv@JTWF admin]#  
chown oracle.dba /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh  
7、测试使用服务启动、关闭Oracle

su root  
# service oracle start  
# service oracle stop  
说明:(1)、安装完Oracle数据库软件、并创建数据库后,oracle数据库默认已经启动,测试时可先stop,再start
           (2)、启动日志在/etc/init.d/oracle文件中已有配置:/home/oracle/scripts/startup_shutdown.log

           (3)、service oracle中的oracle和/etc/init.d/oracle及及chkconfig --add oracle三者是一致的。


            (4)、注意:若是没执行6步骤,在在/home/oracle/scripts/startup_shutdown.log日志里会报如下错误:
bash: /home/oracle/scripts/startup.sh: Permission denied  
bash: /home/oracle/scripts/startup.sh: Permission denied  
另外可以执行reboot命令,等待机器重启后,使用sqlplus命令连接oracle即可判断oracle是否自动重启
su root  

reboot  

重启后:
source /home/oracle/.bash_profile   // 若是sqlplus命令提示不存在,则需手动使环境变量生效,若提示,则该命令不必执行。  

sqlplus its/oracle@orcl             // 能连接进入oracle数据库则说明设置成功  

8、设置linux系统重启时,oracle先自启动,tomcat后自启动:

思考方案:
1、在oracle启动脚本里,执行启动tomcat的命令(tomcat不必设置自启动),但是oracle脚本里已经su oracle,而tomcat是root用户安装的,无执行权限;将tomcat安装目录改为oracle用户所有,则感觉不妥,弃之。  

2、在tomcat的自启动脚本里添加循环,查看oracle进程是否存在,存在则启动tomcat,一定时间内仍然没有oracle进程,则循环结束,亦不启动tomcat;此种感觉麻烦,且对shell脚本不熟悉,弃之。  

3、设置oracle与tomcat自启动脚本里的启动与停止的优先级,可行。  

8.1、对/etc/init.d/oracle与/etc/init.d/tomcat文件的运行级说明:

http://blog.iyunv.com/zxnlmj/article/details/22933477中的tomcat配置文件/etc/init.d/tomcat中有这么两行注释chkconfig、description如下:
#!/bin/bash   
# This is the init script for starting up the   
#  Jakarta Tomcat server   
#   
# chkconfig: 345 91 10   
# description: Starts and stops the Tomcat daemon.   
#   
oracle运行级文件的配置如下:
#!/bin/sh  
# chkconfig: 345 99 10  
# description: Oracle auto start-stop script.  

若是tomcat的运行级文件无这两行注释,在执行chkconfig --add tomcat据说会报错。

其中chkconfig一行说明tomcat在系统运行级别为345时自启动,启动优先权为91,停止优先权为10,优先权越小,表示越早启动,越早关闭。

oracle运行级文件类似。
对linux系统服务的执行等级说明如下:
--level<等级代号>  指定读系统服务要在哪一个执行等级中开启或关毕。  
    等级0表示:表示关机  
    等级1表示:单用户模式  
    等级2表示:无网络连接的多用户命令行模式  
    等级3表示:有网络连接的多用户命令行模式  
    等级4表示:不可用  
    等级5表示:带图形界面的多用户模式  
    等级6表示:重新启动  

8.2、设置oracle与tomcat的启动与停止优先权
既然知道了运行优先权,则可设置oracle与tomca启动停止优先权,让系统启动时,oracle先启动,tomcat后启动,系统关闭时,tomcat先关闭,oracle后关闭。


su root  
gedit /etc/init.d/oracle  
将chkconfig一行改为:
# chkconfig: 345 98 11  
修改tomcat运行级文件:
su root  
gedit /etc/init.d/tomcat  
将chkconfig一行改为:


# chkconfig: 345 99 10  

8.3设置完毕,测试:
su root  

reboot  

重启后,访问tomcat服务即可,看能否访问(前提是tomcat应用中连接oracle数据库了)。

当然,要是tomcat部署的应用中没有连接数据库,也不必如此配置了。

over!



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-16976-1-1.html 上篇帖子: Ubuntu12.04配置NVIDIA cuda5.5经验帖 下篇帖子: Linux内核模块程序加载方法 linux
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表