In linux, configure oracle11gR2 and tomcat to start successively

Source: Internet
Author: User
Tags oracle database installation stop script
Reference self (trial in person and slightly modified): http: wwworacle-basecomarticleslinuxau

Refer to self (test in person and make some modifications ):

Http://www.oracle-base.com/articles/linux/automating-database-startup-and-shutdown-on-linux.php

Support.file1_st.com/index.php? /Knowledgebase/Article/View/210/0/starting-tomcat-as-a-linux-service

Tomcat joins the service and sets self-starting in another article: http://blog.csdn.net/zxnlmj/article/details/22933477

Oracle database installation see http://blog.csdn.net/zxnlmj/article/details/22826149

1. edit the/etc/oradb file and set the restart flag of each database instance from N to Y:

su rootgedit /etc/oratab
The modification is as follows:
# 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. create the/etc/init. d/oracle file and add the following configuration:

su root:gedit /etc/init.d/oracle                

Add the following content:

#! /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 is the username of the dba group created during oracle database installation in linux, rather than the username ORA_OWNER = oraclecase "$1" in 'start' when logging on to the oracle database ') # 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. modify the permissions of oracle files in 2:
su root[root@JTWF Desktop]# chmod 750 /etc/init.d/oracle
4. set the oracle service running level and set auto-start:
[root@JTWF Desktop]# chkconfig --add oracle[root@JTWF Desktop]#
5. create the startup. sh and shutdown. sh scripts and modify the user and group (in/home/oracle/scripts)
# Mkdir-p/home/oracle/scripts # chown oracle. oinstall/home/oracle/scripts [root @ JTWF Desktop] # chown oracle. dba/home/oracle/scripts/startup. the sh script content is as follows:
#!/bin/bashexport TMP=/tmpexport TMPDIR=$TMPexport PATH=/usr/sbin:/usr/local/bin:$PATHexport ORACLE_HOSTNAME=JTWF#export ORACLE_UNQNAME=db12cexport ORACLE_SID=sunlightORAENV_ASK=NO. oraenvORAENV_ASK=YES# Start Listenerlsnrctl start# Start Databasesqlplus / as sysdba << EOFSTARTUP;EXIT;EOF
The script content of/home/oracle/scripts/shutdown. sh is as follows:
#!/bin/bashexport TMP=/tmpexport TMPDIR=$TMPexport PATH=/usr/sbin:/usr/local/bin:$PATHexport ORACLE_HOSTNAME=JTWF#export ORACLE_UNQNAME=db12cexport ORACLE_SID=sunlightORAENV_ASK=NO. oraenvORAENV_ASK=YES# Stop Databasesqlplus / as sysdba << EOFSHUTDOWN IMMEDIATE;EXIT;EOF
Note: (1), # export ORACLE_UNQNAME = db12c. can this configuration be used?

(2), ORACLE_HOSTNAME after the default installation of the Oracle database, the default is localhost, it is best to modify the IP address to the machine name ING, see: http://blog.csdn.net/zxnlmj/article/details/23097387

(3) ORACLE_SID is configured when the environment variable is configured in the Oracle database.

6. modify the permissions and owner of the preceding two scripts:

[root@JTWF admin]# chmod u+x /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh[root@JTWF admin]#chown oracle.dba /home/oracle/scripts/startup.sh /home/oracle/scripts/shutdown.sh

7. start and close Oracle

su root# service oracle start# service oracle stop
Note: (1) after the Oracle database software is installed and the database is created, the oracle database is started by default. you can stop the database before starting the test.

(2) the startup log has been configured in the/etc/init. d/oracle File:/home/oracle/scripts/startup_shutdown.log

(3) oracle in service oracle and/etc/init. d/oracle and chkconfig -- add oracle are consistent.

(4) Note: If step 6 is not executed, the following error will be reported in the/home/oracle/scripts/startup_shutdown.log:

bash: /home/oracle/scripts/startup.sh: Permission deniedbash: /home/oracle/scripts/startup.sh: Permission denied

In addition, you can run the reboot command. after the machine restarts, use the sqlplus command to connect to oracle to determine whether oracle is automatically restarted.

su rootreboot

After restart:

Source/home/oracle/. bash_profile // if the sqlplus command prompts that the environment variable does not exist, you need to manually make the environment variable take effect. if the prompt is displayed, this command does not have to be executed. Sqlplus its/oracle @ orcl // If you can connect to the oracle database, the setting is successful.

8. when the linux system is set to restart, oracle is started first and tomcat is started later:

Solution:

1. execute the command to start tomcat in the oracle startup script (tomcat does not have to be set to self-start), but the oracle script already contains su oracle, while tomcat is installed by the root user and has no execution permission; changing the tomcat installation directory to all oracle users makes it inappropriate to discard it. 2. add a loop in tomcat's self-starting script to check whether the oracle process exists. if the oracle process exists, start tomcat. if the oracle process still does not exist within a certain period of time, the loop ends and tomcat is not started; this is troublesome and unfamiliar with shell scripts. 3. it is feasible to set the priority of start and stop in oracle and tomcat self-start scripts.

8.1 run-level descriptions of/etc/init. d/oracle and/etc/init. d/tomcat files:

In:

#!/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.  #  

The configuration of the oracle runtime file is as follows:

#!/bin/sh# chkconfig: 345 99 10# description: Oracle auto start-stop script.

If the two lines of comments are not displayed in the tomcat running-level file, an error is reported when chkconfig -- add tomcat is executed.

The chkconfig line indicates that tomcat is automatically started when the system running level is 345, the startup priority is 91, and the stop priority is 10. the smaller the priority, the earlier the startup, the earlier the shutdown.

Oracle running-level files are similar.

The implementation levels of linux system services are described as follows:

-- Level
 <等级代号>
  
Specify the execution level of the Read system service. Level 0: Shutdown Level 1: Single user mode Level 2: Multi-user command line mode without network connection Level 3: multi-user command line mode with network connection Level 4: unavailable Level 5: Multi-user mode with graphic interface level 6: Restart
 
8.2 set priority for starting and stopping oracle and tomcat

Now that you know the running priority, you can set the priority for starting and stopping oracle and PostgreSQL. when the system is started, oracle is started, tomcat is started, and tomcat is disabled when the system is disabled, close oracle later.

su rootgedit /etc/init.d/oracle
Change the chkconfig line:
# chkconfig: 345 98 11

Modify tomcat runtime files:

su rootgedit /etc/init.d/tomcat

Change the chkconfig line:

# chkconfig: 345 99 10
8.3 The settings are complete. test:
su rootreboot

After the restart, you can access the tomcat service to see if it can be accessed (provided that the tomcat application is connected to the oracle database ).

Of course, you do not need to configure it if the tomcat application is not connected to the database.

Over!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.