Home Database Mysql Tutorial Oracle设置(1)设置Oracle数据库为Linux系统服务

Oracle设置(1)设置Oracle数据库为Linux系统服务

Jun 07, 2016 pm 03:30 PM
linux oracle database Serve system set up

将Oracle数据库设为Linux系统服务,并使其能随系统启动和关闭数据库。 1. vi /etc/oratab 将最后一行改为Y. 只有改为Y,Oracle自带的dbstart与dbshut才能起作用。 如: xcldb:/u01/app/oracle/product/11.2.0/db_1:Y 2. 启动脚本文件 vi /etc/rc.d/init.d/orac

将Oracle数据库设为Linux系统服务,并使其能随系统启动和关闭数据库。

1. vi /etc/oratab

   将最后一行改为Y. 只有改为Y,Oracle自带的dbstart与dbshut才能起作用。

   如:

    xcldb:/u01/app/oracle/product/11.2.0/db_1:Y


2. 启动脚本文件

  vi /etc/rc.d/init.d/oracle

#!/bin/bash
  #chkconfig: 2345 20 80
  #description: Oracle dbstart/dbshut
  #/etc/rc.d/init.d/oracle
  export ORACLE_BASE=/u01/app/oracle
  export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1
  ORACLE_OWNER=oracle
  LOGFILE=/var/log/oracle.log
  DATE=`date +%Y-%m-%d`
  echo "################################">>${LOGFILE}
  echo "## Run Oracle "${DATE} >> ${LOGFILE}
  if [! -f ${ORACLE_HOME}"/bin/dbstart" ] || [ ! -f ${ORACLE_HOME}"/bin/dbshut" ]; then
   echo "ERROR: Missing the script file "${ORACLE_HOME}"/bin/dbstart or "${ORACLE_HOME}"/bin/dbshut!">>${LOGFILE}
   echo "################################">>${LOGFILE}
   exit
  fi
  start(){
     touch /var/lock/subsys/oracle
      echo "###Startup oracle....."
   su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/lsnrctl start"
   su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/dbstart "${ORACLE_HOME}
   echo "###Done"
   #echo "###Run database control......"
   #su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/emctl start dbconsole"
   echo "###Done"
   echo "###startup oracle successful....."
  }
  stop(){
     #echo "###Stop database control......"
   #su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/emctl stop dbconsole"
   echo "###Done"
     echo "###Shutdown oracle------"
   su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/lsnrctl stop"
   su - ${ORACLE_OWNER} -c ${ORACLE_HOME}"/bin/dbshut "${ORACLE_HOME}
   echo "###Done"
   rm -f /var/lock/subsys/oracle
   echo "###Shutdown oracle successful-------"
  }
 
  case "$1" in
  'start')
          start >> ${LOGFILE}
  ;;
  'stop')
          stop >> ${LOGFILE}
  ;;
  'restart')
  stop >> ${LOGFILE}
  start >> ${LOGFILE}
 ;;
  *)
  echo "Usage:`basename $0` start|stop|restart"
   exit 1
  esac
  echo "###Finished.">>${LOGFILE}
  echo "################################">>${LOGFILE}
  exit 0
Copy after login

3. 将脚本设置为可执行

  chmod a+x /etc/rc.d/init.d/oracle

  授权后,可手工用下面命令测试前面脚本的正确性:

   a. 启动

    /etc/rc.d/init.d/oracle start

   b. 停止

    /etc/rc.d/init.d/oracle stop

   c. 重启

    /etc/rc.d/init.d/oracle restart

4. 手工添加服务

 a.手工添加到chkconfig

    chkconfig --add /etc/rc.d/init.d/oracle

    b.查看oracle服务的开机启动级别

     chkconfig --list oracle 或

     chkconfig | grep oracle

    #c.修改oracle服务的开机启动级别

    #chkconfig --level 24 oracle off

    #chkconfig --level 35 oracle on

   注意:

     如果在启动脚本前不加下面两行,会出现"服务不支持 chkconfig"

  #chkconfig: 2345 20 80

    #description: Oracle dbstart/dbshut

5. 手工测试服务

  service oracle start

  service oracle stop

  service oracle restart

6.建立连接

  a.关机执行

  ln -s /etc/init.d/oracle /etc/rc.d/rc0.d/K01oracle

  b.重启执行

  ln -s /etc/init.d/oracle /etc/rc.d/rc6.d/K01oracle

  c.开机执行(Oracle10g以后能自启动了,可以省掉这步)

  ln -s /etc/init.d/oracle /etc/rc.d/rc3.d/S99oracle

  ln -s /etc/init.d/oracle /etc/rc.d/rc5.d/S99oracle

7.重启测试下

  reboot

  cat /var/log/oracle.log

 

备注:

  脚本中可以看到,start与stop时,弄了个/var/lock/subsys/oracle。

如果不增加这个文件的处理,在系统关闭时,你会发现stop并没有执行。

原因可以看看>


MAIL: xcl_168@aliyun.com

BLOG: http://blog.csdn.net/xcl168


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL: Structured Data and Relational Databases MySQL: Structured Data and Relational Databases Apr 18, 2025 am 12:22 AM

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

git software installation git software installation Apr 17, 2025 am 11:57 AM

Installing Git software includes the following steps: Download the installation package and run the installation package to verify the installation configuration Git installation Git Bash (Windows only)

MySQL: Key Features and Capabilities Explained MySQL: Key Features and Capabilities Explained Apr 18, 2025 am 12:17 AM

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

How to set important Git configuration global properties How to set important Git configuration global properties Apr 17, 2025 pm 12:21 PM

There are many ways to customize a development environment, but the global Git configuration file is one that is most likely to be used for custom settings such as usernames, emails, preferred text editors, and remote branches. Here are the key things you need to know about global Git configuration files.

See all articles