Oracle Database,又名Oracle RDBMS,或簡稱Oracle。是甲骨文公司的一款關系數據庫管理系統。它是在數據庫領域一直處於領先地位的產品。可以說Oracle數據庫系統是目前世界上流行的關系數據庫管理系統,系統可移植性好、使用方便、功能強,適用於各類大、中、小、微機環境。它是一種高效率、可靠性好的、適應高吞吐量的數據庫方案。
1、部署環境要求
(1)操作系統版本:CentOS 7.x(最小化安裝)
(2)最小內存容量:4GB
(3)最小CPU核心數:2核心
(4)最小磁盤空間:50GB
(5)磁盤分區建議:500GB磁盤空間為例
/:50GB(根分區)
/boot:500MB
/home:50GB
swap:物理內存小於4GB時,swap分配值為物理內存2倍,物理內存大於4GB時,swap分配值為物理內存1.5倍
/data:剩余全部空間
2、部署軟件准備
Oracle Database SoftPack:linux.x64_11gR2_database_1of2.zip
Oracle Database SoftPack:linux.x64_11gR2_database_2of2.zip
3、網絡參數配置
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens33 UUID=8586e405-4459-42e2-ac9f-def02881736d DEVICE=ens33 ONBOOT=yes MACADDR=preserve IPADDR=10.10.10.133 PREFIX=24 GATEWAY=10.10.10.10 DNS1=114.114.114.114 IPV6_PRIVACY=no ZONE=public
4、系統軟件安裝
[root@localhost ~]# yum -y install vim net-tools tree unzip lrzsz
5、系統安全配置
(1)關閉SELINUX安全訪問控制
[root@localhost ~]# vim /etc/selinux/config # This file controls the state of SELinux on the system. # SELINUX= can take one of these three values: # enforcing - SELinux security policy is enforced. # permissive - SELinux prints warnings instead of enforcing. # disabled - No SELinux policy is loaded. # SELINUX=enforcing //注釋掉此處 SELINUX=disabled //新增此處,並將SELINUX狀態設置關閉狀態disabled # SELINUXTYPE= can take one of these two values: # targeted - Targeted processes are protected, # mls - Multi Level Security protection. SELINUXTYPE=targeted
(2)配置防火牆安全規則
[root@localhost ~]# systemctl status firewalld.service //查看防火牆運行狀態 ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since 五 2019-08-30 22:58:53 CST; 8h ago Docs: man:firewalld(1) Main PID: 841 (firewalld) CGroup: /system.slice/firewalld.service └─841 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid 8月 30 22:58:52 oracleserver.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon... 8月 30 22:58:53 oracleserver.localdomain systemd[1]: Started firewalld - dynamic firewall daemon. [root@localhost ~]# firewall-cmd --zone=public --add-port=1521/tcp --permanent //開放1521端口 success [root@localhost ~]# firewall-cmd --zone=public --add-port=1158/tcp --permanent //開放1158端口 success [root@localhost ~]# firewall-cmd --zone=public --add-port=22/tcp --permanent //開放22端口 success [root@localhost ~]# firewall-cmd --reload //重啟載入防火牆配置 success [root@localhost ~]# firewall-cmd --zone=public --list-ports //查看已開放端口 22/tcp 1158/tcp 1521/tcp
6、安裝依賴軟件
32位依賴軟件: [root@localhost ~]# yum -y install binutils compat-libcap1 compat-libstdc++-33 \ compat-libstdc++-33*i686 compat-libstdc++-33*.devel \ compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ \ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio \ libaio*.i686 libaio-devel libaio-devel*.devel libgcc \ libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel \ libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 \ make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686 64位依賴軟件: [root@localhost ~]# yum -y install binutils-2.* compat-libstdc++-33* elfutils-libelf-0.* \ elfutils-libelf-devel-* gcc-4.* gcc-c++-4.* glibc-2.* glibc-common-2.* \ glibc-devel-2.* glibc-headers-2.* ksh-2* libaio-0.* libaio-devel-0.* \ libgcc-4.* libstdc++-4.* libstdc++- devel-4.* make-3.* sysstat-7.* \ unixODBC-2.* unixODBC-devel-2.* pdksh* 檢查依賴軟件: [root@localhost ~]# rpm -q binutils compat-libcap1 compat-libstdc++-33 \ compat-libstdc++-33*i686 compat-libstdc++-33*.devel \ compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ \ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio \ libaio*.i686 libaio-devel libaio-devel*.devel libgcc \ libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel \ libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 \ make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686 執行安裝更新: [root@localhost ~]# yum update
7、部署用戶配置
(1)創建部署用戶
[root@localhost ~]# groupadd oinstall //創建oinstall用戶組 [root@localhost ~]# groupadd dba //創建dba用戶組 [root@localhost ~]# useradd -g oinstall -G dba oracle //創建oracle用戶並將用戶加入到oinstall、dba兩個用戶組 [root@localhost ~]# passwd oracle //設置oracle用戶密碼 更改用戶 oracle 的密碼 。 新的 密碼: 重新輸入新的 密碼: passwd: 所有的身份驗證令牌已經成功更新。
(2)創建部署目錄
[root@localhost ~]# mkdir -p /oracle/app/product/11.2.0/dbhome_1 [root@localhost ~]# mkdir -p /oracle/app/oradata [root@localhost ~]# mkdir -p /oracle/flash_recovery_area [root@localhost ~]# mkdir -p /oracle/oraInventory [root@localhost ~]# mkdir -p /oracle/response [root@localhost ~]# mkdir -p /software [root@localhost ~]# chown oracle:oinstall -R /oracle/ [root@localhost ~]# chown oracle:oinstall -R /software/ [root@localhost ~]# chmod -R 755 /oracle/ [root@localhost ~]# chmod -R 755 /software/
8、配置部署參數
(1)配置系統主機參數
[root@localhost ~]# hostnamectl set-hostname oracleserver.localdomain //修改主機名稱 [root@localhost ~]# vim /etc/hosts //配置主機網絡地址與主機名稱映射記錄 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.10.10.133 oracleserver oracleserver.localdomain [root@oracleserver ~]# vim /etc/redhat-release //配置系統標識參數 #CentOS Linux release 7.6.1810 (Core) Red Hat Enterprise Linux Server release 7.3 (Maipo) [root@localhost ~]# reboot //重啟操作系統
(2)配置系統內核參數
[root@oracleserver ~]# vim /etc/sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). #Oracle Install Parameter //添加下面內核參數 fs.file-max = 6815744 fs.aio-max-nr = 1048576 kernel.shmall = 2097152 kernel.shmmax = 2147483648 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 4194304 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576 [root@oracleserver ~]# /sbin/sysctl -p //更新內核參數,等效命令 [root@oracleserver ~]# /sysctl -p //更新內核參數,等效命令 fs.file-max = 6815744 fs.aio-max-nr = 1048576 kernel.shmall = 2097152 kernel.shmmax = 2147483648 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 4194304 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576
(3)配置登錄身份認證
[root@oracleserver ~]# vim /etc/pam.d/login #%PAM-1.0 auth [user_unknown=ignore success=ok ignore=ignore default=bad] pam_securetty.so auth substack system-auth auth include postlogin account required pam_nologin.so account include system-auth password include system-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so session optional pam_console.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open session required pam_namespace.so session optional pam_keyinit.so force revoke session include system-auth session include postlogin -session optional pam_ck_connector.so #Oracle Install Parameter //添加下面Oracle安裝參數 session required pam_limits.so session required /lib64/security/pam_limits.so
(4)配置資源限制參數
[root@oracleserver ~]# vim /etc/profile # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you # are doing. It's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates. pathmunge () { case ":${PATH}:" in *:"$1":*) ;; *) if [ "$2" = "after" ] ; then PATH=$PATH:$1 else PATH=$1:$PATH fi esac } if [ -x /usr/bin/id ]; then if [ -z "$EUID" ]; then # ksh workaround EUID=`/usr/bin/id -u` UID=`/usr/bin/id -ru` fi USER="`/usr/bin/id -un`" LOGNAME=$USER MAIL="/var/spool/mail/$USER" fi # Path manipulation if [ "$EUID" = "0" ]; then pathmunge /usr/sbin pathmunge /usr/local/sbin else pathmunge /usr/local/sbin after pathmunge /usr/sbin after fi HOSTNAME=`/usr/bin/hostname 2>/dev/null` HISTSIZE=1000 if [ "$HISTCONTROL" = "ignorespace" ] ; then export HISTCONTROL=ignoreboth else export HISTCONTROL=ignoredups fi export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL # By default, we want umask to get set. This sets it for login shell # Current threshold for system reserved uid/gids is 200 # You could check uidgid reservation validity in # /usr/share/doc/setup-*/uidgid file if [ $UID -gt 199 ] && [ "`/usr/bin/id -gn`" = "`/usr/bin/id -un`" ]; then umask 002 else umask 022 fi for i in /etc/profile.d/*.sh /etc/profile.d/sh.local ; do if [ -r "$i" ]; then if [ "${-#*i}" != "$-" ]; then . "$i" else . "$i" >/dev/null fi fi done unset i unset -f pathmunge #Oracle Install Parameter //添加下面Oracle安裝參數 if [ $USER = "oracle" ]; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi fi [root@oracleserver ~]# source /etc/profile //使參數配置生效
[root@oracleserver ~]# cat /etc/security/limits.conf # /etc/security/limits.conf # #This file sets the resource limits for the users logged in via PAM. #It does not affect resource limits of the system services. # #Also note that configuration files in /etc/security/limits.d directory, #which are read in alphabetical order, override the settings in this #file in case the domain is the same or more specific. #That means for example that setting a limit for wildcard domain here #can be overriden with a wildcard setting in a config file in the #subdirectory, but a user specific setting here can be overriden only #with a user specific setting in the subdirectory. # #Each line describes a limit for a user in the form: # #<domain> <type> <item> <value> # #Where: #<domain> can be: # - a user name # - a group name, with @group syntax # - the wildcard *, for default entry # - the wildcard %, can be also used with %group syntax, # for maxlogin limit # #<type> can have the two values: # - "soft" for enforcing the soft limits # - "hard" for enforcing hard limits # #<item> can be one of the following: # - core - limits the core file size (KB) # - data - max data size (KB) # - fsize - maximum filesize (KB) # - memlock - max locked-in-memory address space (KB) # - nofile - max number of open file descriptors # - rss - max resident set size (KB) # - stack - max stack size (KB) # - cpu - max CPU time (MIN) # - nproc - max number of processes # - as - address space limit (KB) # - maxlogins - max number of logins for this user # - maxsyslogins - max number of logins on the system # - priority - the priority to run user process with # - locks - max number of file locks the user can hold # - sigpending - max number of pending signals # - msgqueue - max memory used by POSIX message queues (bytes) # - nice - max nice priority allowed to raise to values: [-20, 19] # - rtprio - max realtime priority # #<domain> <type> <item> <value> # #* soft core 0 #* hard rss 10000 #@student hard nproc 20 #@faculty soft nproc 20 #@faculty hard nproc 50 #ftp hard nproc 0 #@student - maxlogins 4 #Oracle Install Parameter //添加下面Oracle安裝參數 oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 # End of file
(5)配置內存分配參數
[root@oracleserver ~]# cat /sys/kernel/mm/transparent_hugepage/enabled //查詢THP狀態 always [root@oracleserver ~]# echo never > /sys/kernel/mm/transparent_hugepage/enabled //關閉THP延遲分配內存機制 [root@oracleserver ~]# cat /sys/kernel/mm/transparent_hugepage/enabled //查詢THP狀態 always madvise [never]
(6)配置數據庫環境變量
[root@oracleserver ~]# vim /home/oracle/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/.local/bin:$HOME/bin export PATH #Oracle Install Parameter //添加下面Oracle安裝參數 umask 022 export ORACLE_BASE=/oracle/app export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1 export ORACLE_SID=orcl export ORACLE_UNQNAME=orcl export NLS_LANG=.AL32UTF8 export PATH=$ORACLE_HOME/bin:$PATH:$ORACLE_HOME/lib64 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib export CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib export TNS_ADMIN=/oracle/app/product/11.2.0/dbhome_1/network/admin export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS" [root@oracleserver ~]# source /home/oracle/.bash_profile //使參數配置生效 [root@oracleserver ~]# reboot //重啟操作系統
9、上傳數據庫軟件
[root@oracleserver ~]# cd /software/ [root@oracleserver software]# rz [root@oracleserver software]# ll 總用量 2295592 -rw-r--r-- 1 oracle oinstall 1239269270 8月 29 11:44 Oracle.11g.R2.DataBase.Linux.x64.11.2.0.1.0.1of2.zip -rw-r--r-- 1 oracle oinstall 1111416131 8月 29 11:44 Oracle.11g.R2.DataBase.Linux.x64.11.2.0.1.0.2of2.zip #靜默解壓文件 [root@oracleserver software]# unzip -q Oracle.11g.R2.DataBase.Linux.x64.11.2.0.1.0.1of2.zip -d /software [root@oracleserver software]# unzip -q Oracle.11g.R2.DataBase.Linux.x64.11.2.0.1.0.2of2.zip -d /software [root@oracleserver software]# ll 總用量 2295592 drwxr-xr-x 8 oracle oinstall 128 8月 21 2009 database -rw-r--r-- 1 oracle oinstall 1239269270 8月 29 11:44 Oracle.11g.R2.DataBase.Linux.x64.11.2.0.1.0.1of2.zip -rw-r--r-- 1 oracle oinstall 1111416131 8月 29 11:44 Oracle.11g.R2.DataBase.Linux.x64.11.2.0.1.0.2of2.zip
10、配置數據庫響應文件
[root@oracleserver software]# cp /software/database/response/db_install.rsp /oracle/response/ //等效命令 [root@oracleserver software]# cp /software/database/response/* /oracle/response/ //等效命令 [root@oracleserver software]# vim /oracle/response/db_install.rsp #################################################################### ## Copyright(c) Oracle Corporation 1998,2008. All rights reserved.## ## ## ## Specify values for the variables listed below to customize ## ## your installation. ## ## ## ## Each variable is associated with a comment. The comment ## ## can help to populate the variables with the appropriate ## ## values. ## ## ## ## IMPORTANT NOTE: This file contains plain text passwords and ## ## should be secured to have read permission only by oracle user ## ## or db administrator who owns this installation. ## ## ## #################################################################### #------------------------------------------------------------------------------ # Do not change the following system generated value. #------------------------------------------------------------------------------ #標注響應文件版本 oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0 #------------------------------------------------------------------------------ # Specify the installation option. # It can be one of the following: # 1. INSTALL_DB_SWONLY 只裝數據庫軟件 # 2. INSTALL_DB_AND_CONFIG 安裝數據庫軟件並建庫 # 3. UPGRADE_DB 升級數據庫 #------------------------------------------------------------------------------- oracle.install.option=INSTALL_DB_AND_CONFIG #------------------------------------------------------------------------------- # Specify the hostname of the system as set during the install. It can be used # to force the installation to use an alternative hostname rather than using the # first hostname found on the system. (e.g., for systems with multiple hostnames # and network interfaces) #------------------------------------------------------------------------------- #指定操作系統主機名 ORACLE_HOSTNAME=oracleserver #------------------------------------------------------------------------------- # Specify the Unix group to be set for the inventory directory. #------------------------------------------------------------------------------- #指定產品清單oraInventory目錄所有者,通常會是oinstall或者dba組 UNIX_GROUP_NAME=oinstall #------------------------------------------------------------------------------- # Specify the location which holds the inventory files. #------------------------------------------------------------------------------- #指定產品清單oraInventory目錄路徑,需要建立在App目錄外面 INVENTORY_LOCATION=/oracle/oraInventory #------------------------------------------------------------------------------- # Specify the languages in which the components will be installed. # # en : English ja : Japanese # fr : French ko : Korean # ar : Arabic es : Latin American Spanish # bn : Bengali lv : Latvian # pt_BR: Brazilian Portuguese lt : Lithuanian # bg : Bulgarian ms : Malay # fr_CA: Canadian French es_MX: Mexican Spanish # ca : Catalan no : Norwegian # hr : Croatian pl : Polish # cs : Czech pt : Portuguese # da : Danish ro : Romanian # nl : Dutch ru : Russian # ar_EG: Egyptian zh_CN: Simplified Chinese # en_GB: English (Great Britain) sk : Slovak # et : Estonian sl : Slovenian # fi : Finnish es_ES: Spanish # de : German sv : Swedish # el : Greek th : Thai # iw : Hebrew zh_TW: Traditional Chinese # hu : Hungarian tr : Turkish # is : Icelandic uk : Ukrainian # in : Indonesian vi : Vietnamese # it : Italian # # Example : SELECTED_LANGUAGES=en,fr,ja #------------------------------------------------------------------------------ #指定數據庫語言,多個直接用逗號隔開 SELECTED_LANGUAGES=en,zh_CN #------------------------------------------------------------------------------ # Specify the complete path of the Oracle Home. #------------------------------------------------------------------------------ #設置ORALCE_HOME的路徑 ORACLE_HOME=/oracle/app/product/11.2.0/dbhome_1 #------------------------------------------------------------------------------ # Specify the complete path of the Oracle Base. #------------------------------------------------------------------------------ #設置ORACLE_BASE的路徑 ORACLE_BASE=/oracle/app #------------------------------------------------------------------------------ # Specify the installation edition of the component. # # The value should contain only one of these choices. # EE : Enterprise Edition 企業版 # SE : Standard Edition 標准版 # SEONE : Standard Edition One 標准版1 # PE : Personal Edition (WINDOWS ONLY) 個人版 #------------------------------------------------------------------------------ #指定數據庫版本 oracle.install.db.InstallEdition=EE #------------------------------------------------------------------------------ # This variable is used to enable or disable custom install. # # true : Components mentioned as part of 'customComponents' property # are considered for install. # false : Value for 'customComponents' is not considered. #------------------------------------------------------------------------------ #是否自定義Oracle的組件,如果選擇false,則會使用默認的組件。 #是否自定義Oracle的組件,如果選擇true,則需要自己選擇組件。 oracle.install.db.isCustomInstall=false #------------------------------------------------------------------------------ # This variable is considered only if 'IsCustomInstall' is set to true. # # Description: List of Enterprise Edition Options you would like to install. # # The following choices are available. You may specify any # combination of these choices. The components you choose should # be specified in the form "internal-component-name:version" # Below is a list of components you may specify to install. # # oracle.rdbms.partitioning:11.2.0.1.0 - Oracle Partitioning # oracle.rdbms.dm:11.2.0.1.0 - Oracle Data Mining # oracle.rdbms.dv:11.2.0.1.0 - Oracle Database Vault # oracle.rdbms.lbac:11.2.0.1.0 - Oracle Label Security # oracle.rdbms.rat:11.2.0.1.0 - Oracle Real Application Testing # oracle.oraolap:11.2.0.1.0 - Oracle OLAP #------------------------------------------------------------------------------ oracle.install.db.customComponents=oracle.server:11.2.0.1.0,oracle.sysman.ccr:10.2.7.0.0,oracle.xdk:11.2.0.1.0,oracle.rdbms.oci:11.2.0.1.0,oracle.network:11.2.0.1.0,oracle.network.listener:11.2.0.1.0,oracle.rdbms:11.2.0.1.0,oracle.options:11.2.0.1.0,oracle.rdbms.partitioning:11.2.0.1.0,oracle.oraolap:11.2.0.1.0,oracle.rdbms.dm:11.2.0.1.0,oracle.rdbms.dv:11.2.0.1.0,orcle.rdbms.lbac:11.2.0.1.0,oracle.rdbms.rat:11.2.0.1.0 ############################################################################### # # # PRIVILEGED OPERATING SYSTEM GROUPS # # ------------------------------------------ # # Provide values for the OS groups to which OSDBA and OSOPER privileges # # needs to be granted. If the install is being performed as a member of the # # group "dba", then that will be used unless specified otherwise below. # # # ############################################################################### #------------------------------------------------------------------------------ # The DBA_GROUP is the OS group which is to be granted OSDBA privileges. #------------------------------------------------------------------------------ #指定擁有OSDBA權限的用戶組,通常會是dba組 oracle.install.db.DBA_GROUP=dba #------------------------------------------------------------------------------ # The OPER_GROUP is the OS group which is to be granted OSOPER privileges. #------------------------------------------------------------------------------ 指定擁有OSOPER權限的用戶組,通常會是oinstall組 oracle.install.db.OPER_GROUP=oinstall #------------------------------------------------------------------------------ # Specify the cluster node names selected during the installation. #------------------------------------------------------------------------------ #指定RAC安裝節點 oracle.install.db.CLUSTER_NODES= #------------------------------------------------------------------------------ # Specify the type of database to create. # It can be one of the following: # - GENERAL_PURPOSE/TRANSACTION_PROCESSING 一般用途/事物處理 # - DATA_WAREHOUSE 數據倉庫 #------------------------------------------------------------------------------ #指定數據庫用途類型 oracle.install.db.config.starterdb.type=DATA_WAREHOUSE #------------------------------------------------------------------------------ # Specify the Starter Database Global Database Name. #------------------------------------------------------------------------------ #指定GlobalName oracle.install.db.config.starterdb.globalDBName=orcl #------------------------------------------------------------------------------ # Specify the Starter Database SID. #------------------------------------------------------------------------------ #指定SIDName oracle.install.db.config.starterdb.SID=orcl #------------------------------------------------------------------------------ # Specify the Starter Database character set. # # It can be one of the following: # AL32UTF8, WE8ISO8859P15, WE8MSWIN1252, EE8ISO8859P2, # EE8MSWIN1250, NE8ISO8859P10, NEE8ISO8859P4, BLT8MSWIN1257, # BLT8ISO8859P13, CL8ISO8859P5, CL8MSWIN1251, AR8ISO8859P6, # AR8MSWIN1256, EL8ISO8859P7, EL8MSWIN1253, IW8ISO8859P8, # IW8MSWIN1255, JA16EUC, JA16EUCTILDE, JA16SJIS, JA16SJISTILDE, # KO16MSWIN949, ZHS16GBK, TH8TISASCII, ZHT32EUC, ZHT16MSWIN950, # ZHT16HKSCS, WE8ISO8859P9, TR8MSWIN1254, VN8MSWIN1258 #------------------------------------------------------------------------------ #指定數據庫默認字符集 oracle.install.db.config.starterdb.characterSet=AL32UTF8 #------------------------------------------------------------------------------ # This variable should be set to true if Automatic Memory Management # in Database is desired. # If Automatic Memory Management is not desired, and memory allocation # is to be done manually, then set it to false. #------------------------------------------------------------------------------ #開啟數據庫自動內存管理 oracle.install.db.config.starterdb.memoryOption=true #------------------------------------------------------------------------------ # Specify the total memory allocation for the database. Value(in MB) should be # at least 256 MB, and should not exceed the total physical memory available # on the system. # Example: oracle.install.db.config.starterdb.memoryLimit=512 #------------------------------------------------------------------------------ #指定自動內存容量大小 oracle.install.db.config.starterdb.memoryLimit=512 #------------------------------------------------------------------------------ # This variable controls whether to load Example Schemas onto the starter # database or not. #------------------------------------------------------------------------------ #是否載入模板示例 oracle.install.db.config.starterdb.installExampleSchemas=false #------------------------------------------------------------------------------ # This variable includes enabling audit settings, configuring password profiles # and revoking some grants to public. These settings are provided by default. # These settings may also be disabled. #------------------------------------------------------------------------------ #是否啟用安全設置 oracle.install.db.config.starterdb.enableSecuritySettings=true ############################################################################### # # # Passwords can be supplied for the following four schemas in the # # starter database: # # SYS # # SYSTEM # # SYSMAN (used by Enterprise Manager) # # DBSNMP (used by Enterprise Manager) # # # # Same password can be used for all accounts (not recommended) # # or different passwords for each account can be provided (recommended) # # # ############################################################################### #------------------------------------------------------------------------------ # This variable holds the password that is to be used for all schemas in the # starter database. #------------------------------------------------------------------------------- #設置數據用所有用戶使用同一個密碼 oracle.install.db.config.starterdb.password.ALL=iTouch123 #------------------------------------------------------------------------------- # Specify the SYS password for the starter database. #------------------------------------------------------------------------------- #設置sys用戶密碼 oracle.install.db.config.starterdb.password.SYS= #------------------------------------------------------------------------------- # Specify the SYSTEM password for the starter database. #------------------------------------------------------------------------------- #設置system用戶密碼 oracle.install.db.config.starterdb.password.SYSTEM= #------------------------------------------------------------------------------- # Specify the SYSMAN password for the starter database. #------------------------------------------------------------------------------- #設置sysman用戶密碼 oracle.install.db.config.starterdb.password.SYSMAN= #------------------------------------------------------------------------------- # Specify the DBSNMP password for the starter database. #------------------------------------------------------------------------------- #設置dbsnmp用戶密碼 oracle.install.db.config.starterdb.password.DBSNMP= #------------------------------------------------------------------------------- # Specify the management option to be selected for the starter database. # It can be one of the following: # 1. GRID_CONTROL 遠程管理工具 # 2. DB_CONTROL 本地管理工具 #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.control=DB_CONTROL #------------------------------------------------------------------------------- # Specify the Management Service to use if Grid Control is selected to manage # the database. #------------------------------------------------------------------------------- #GRID_CONTROL需要設定gridcontrol的遠程路徑URL oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL= #------------------------------------------------------------------------------- # This variable indicates whether to receive email notification for critical # alerts when using DB control. #------------------------------------------------------------------------------- #是否啟用Email郵件通知數據庫異常警告信息 oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false #------------------------------------------------------------------------------- # Specify the email address to which the notifications are to be sent. #------------------------------------------------------------------------------- #設置Email郵件通知接收地址 oracle.install.db.config.starterdb.dbcontrol.emailAddress= #------------------------------------------------------------------------------- # Specify the SMTP server used for email notifications. #------------------------------------------------------------------------------- #設置Email郵件發送SMTP服務器 oracle.install.db.config.starterdb.dbcontrol.SMTPServer= ############################################################################### # # # SPECIFY BACKUP AND RECOVERY OPTIONS # # ------------------------------------ # # Out-of-box backup and recovery options for the database can be mentioned # # using the entries below. # # # ############################################################################### #------------------------------------------------------------------------------ # This variable is to be set to false if automated backup is not required. Else # this can be set to true. #------------------------------------------------------------------------------ #是否自動備份數據庫 oracle.install.db.config.starterdb.automatedBackup.enable=false #------------------------------------------------------------------------------ # Regardless of the type of storage that is chosen for backup and recovery, if # automated backups are enabled, a job will be scheduled to run daily at # 2:00 AM to backup the database. This job will run as the operating system # user that is specified in this variable. #------------------------------------------------------------------------------ #自動備份會啟動一個JOB,指定啟動JOB的OSsuer的UID oracle.install.db.config.starterdb.automatedBackup.osuid= #------------------------------------------------------------------------------- # Regardless of the type of storage that is chosen for backup and recovery, if # automated backups are enabled, a job will be scheduled to run daily at # 2:00 AM to backup the database. This job will run as the operating system user # specified by the above entry. The following entry stores the password for the # above operating system user. #------------------------------------------------------------------------------- #自動備份會開啟一個job,需要指定OSUser的pwd oracle.install.db.config.starterdb.automatedBackup.ospwd= #------------------------------------------------------------------------------- # Specify the type of storage to use for the database. # It can be one of the following: # - FILE_SYSTEM_STORAGE # - ASM_STORAGE #------------------------------------------------------------------------------ #自動備份指定使用FILE_SYSTEM_STORAGE存放數據庫文件還是使用ASM存放數據庫文件 oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE #------------------------------------------------------------------------------- # Specify the database file location which is a directory for datafiles, control # files, redo logs. # # Applicable only when oracle.install.db.config.starterdb.storage=FILE_SYSTEM #------------------------------------------------------------------------------- #使用文件系統存放數據庫文件才需要指定數據文件、控制文件、Redo log的存放目錄 oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/oracle/oradata #------------------------------------------------------------------------------- # Specify the backup and recovery location. # # Applicable only when oracle.install.db.config.starterdb.storage=FILE_SYSTEM #------------------------------------------------------------------------------- #使用文件系統存放數據庫文件才需要指定備份恢復目錄 oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/oracle/flash_recovery_area #------------------------------------------------------------------------------- # Specify the existing ASM disk groups to be used for storage. # # Applicable only when oracle.install.db.config.starterdb.storage=ASM #------------------------------------------------------------------------------- #使用ASM存放數據庫文件才需要指定存放的磁盤組 oracle.install.db.config.asm.diskGroup= #------------------------------------------------------------------------------- # Specify the password for ASMSNMP user of the ASM instance. # # Applicable only when oracle.install.db.config.starterdb.storage=ASM_SYSTEM #------------------------------------------------------------------------------- #使用ASM存放數據庫文件才需要指定ASM實例密碼 oracle.install.db.config.asm.ASMSNMPPassword= #------------------------------------------------------------------------------ # Specify the My Oracle Support Account Username. # # Example : MYORACLESUPPORT_USERNAME=metalink #------------------------------------------------------------------------------ #指定metalink賬戶用戶名 MYORACLESUPPORT_USERNAME= #------------------------------------------------------------------------------ # Specify the My Oracle Support Account Username password. # # Example : MYORACLESUPPORT_PASSWORD=password #------------------------------------------------------------------------------ #指定metalink賬戶密碼 MYORACLESUPPORT_PASSWORD= #------------------------------------------------------------------------------ # Specify whether to enable the user to set the password for # My Oracle Support credentials. The value can be either true or false. # If left blank it will be assumed to be false. # # Example : SECURITY_UPDATES_VIA_MYORACLESUPPORT=true #------------------------------------------------------------------------------ #用戶是否可以設置metalink密碼 SECURITY_UPDATES_VIA_MYORACLESUPPORT= #------------------------------------------------------------------------------ # Specify whether user wants to give any proxy details for connection. # The value can be either true or false. If left blank it will be assumed # to be false. # # Example : DECLINE_SECURITY_UPDATES=false #------------------------------------------------------------------------------ # False表示不需要設置安全更新,注意,在11.2的靜默安裝中疑似有一個BUG # Response File中必須指定為true,否則會提示錯誤,不管是否正確填寫了郵件地址 DECLINE_SECURITY_UPDATES=true #------------------------------------------------------------------------------ # Specify the Proxy server name. Length should be greater than zero. # # Example : PROXY_HOST=proxy.domain.com #------------------------------------------------------------------------------ #代理服務器名 PROXY_HOST= #------------------------------------------------------------------------------ # Specify the proxy port number. Should be Numeric and atleast 2 chars. # # Example : PROXY_PORT=25 #------------------------------------------------------------------------------ #代理服務器端口 PROXY_PORT= #------------------------------------------------------------------------------ # Specify the proxy user name. Leave PROXY_USER and PROXY_PWD # blank if your proxy server requires no authentication. # # Example : PROXY_USER=username #------------------------------------------------------------------------------ #代理服務器用戶名 PROXY_USER= #------------------------------------------------------------------------------ # Specify the proxy password. Leave PROXY_USER and PROXY_PWD # blank if your proxy server requires no authentication. # # Example : PROXY_PWD=password #------------------------------------------------------------------------------ #代理服務器密碼 PROXY_PWD=
11、安裝數據庫軟件
[root@oracleserver ~]# su - oracle 上一次登錄:六 8月 31 10:40:29 CST 2019pts/1 上 [oracle@oracleserver ~]$ cd /software/database/ #屏蔽異常信息,無警告信息 [oracle@oracleserver ~]$ ./runInstaller -silent -ignorePrereq -responseFile /oracle/response/db_install.rsp #屏蔽部分異常信息,會有警告,可忽略 [oracle@oracleserver ~]$ ./runInstaller -silent -ignoreSysPrereqs -responseFile /oracle/response/db_install.rsp >>>>>> 正在啟動 Oracle Universal Installer... 檢查臨時空間: 必須大於 120 MB。 實際為 38740 MB 通過 檢查交換空間: 必須大於 150 MB。 實際為 4095 MB 通過 准備從以下地址啟動 Oracle Universal Installer /tmp/OraInstall2019-04-16_03-41-22PM. 請稍候...[oracle@jetflow136 database]$ 可以在以下位置找到本次安裝會話的日志: /home/oracle/tools/oraInventory/logs/installActions2019-04-16_03-41-22PM.log 安裝結束后會打印如下信息: 以下配置腳本需要以 "root" 用戶的身份執行。 #!/bin/sh #要運行的 Root 腳本 /oracle/oraInventory/orainstRoot.sh /oracle/app/product/11.2.0/dbhome_1/root.sh 要執行配置腳本, 請執行以下操作: 1. 打開一個終端窗口 2. 以 "root" 身份登錄 3. 運行腳本 4. 返回此窗口並按 "Enter" 鍵繼續 Successfully Setup Software. <<<<<< @ 注意:如果需要查詢安裝過程日志,請重新開個終端,使用命令:tailf /home/oracle/tools/oraInventory/logs/installActions2019-04-16_03-41-22PM.log 打印日志。 @ 告警:只要不會導致程序退出,即可忽略一些警告異常。 #重新打開一個xshell終端窗口,使用root用戶執行腳本 [root@oracleserver ~]# /oracle/oraInventory/orainstRoot.sh [root@oracleserver ~]# /oracle/app/product/11.2.0/dbhome_1/root.sh
12、設置數據庫開啟啟動
[root@oracleserver ~]# vim /etc/oratab # # This file is used by ORACLE utilities. It is created by root.sh # and updated by the Database Configuration Assistant when creating # a database. # A colon, ':', is used as the field terminator. A new line terminates # the entry. Lines beginning with a pound sign, '#', are comments. # # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:<N|Y>: # # 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. # # #orcl:/oracle/app/product/11.2.0/dbhome_1:N //注釋此處 orcl:/oracle/app/product/11.2.0/dbhome_1:Y //添加此處
[root@oracleserver ~]# vim /oracle/app/product/11.2.0/dbhome_1/bin/dbstart #!/bin/sh # # $Id: dbstart.sh 22-may-2008.05:05:45 arogers Exp $ # Copyright (c) 1991, 2008, Oracle. All rights reserved. # ################################### # # usage: dbstart $ORACLE_HOME # # This script is used to start ORACLE from /etc/rc(.local). # It should ONLY be executed as part of the system boot procedure. # # This script will start all databases listed in the oratab file # whose third field is a "Y". If the third field is set to "Y" and # there is no ORACLE_SID for an entry (the first field is a *), # then this script will ignore that entry. # # This script requires that ASM ORACLE_SID's start with a +, and # that non-ASM instance ORACLE_SID's do not start with a +. # # If ASM instances are to be started with this script, it cannot # be used inside an rc*.d directory, and should be invoked from # rc.local only. Otherwise, the CSS service may not be available # yet, and this script will block init from completing the boot # cycle. # # If you want dbstart to auto-start a single-instance database that uses # an ASM server that is auto-started by CRS (this is the default behavior # for an ASM cluster), you must change the database's ORATAB entry to use # a third field of "W" and the ASM's ORATAB entry to use a third field of "N". # These values specify that dbstart auto-starts the database only after # the ASM instance is up and running. # # Note: # Use ORACLE_TRACE=T for tracing this script. # # The progress log for each instance bringup plus Error and Warning message[s] # are logged in file $ORACLE_HOME/startup.log. The error messages related to # instance bringup are also logged to syslog (system log module). # The Listener log is located at $ORACLE_HOME_LISTNER/listener.log # # On all UNIX platforms except SOLARIS # ORATAB=/etc/oratab # # To configure, update ORATAB with Instances that need to be started up # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:<N|Y|W>: # An example entry: # main:/usr/lib/oracle/emagent_10g:Y # # Overall algorithm: # 1) Bring up all ASM instances with 'Y' entry in status field in oratab entry # 2) Bring up all Database instances with 'Y' entry in status field in # oratab entry # 3) If there are Database instances with 'W' entry in status field # then # iterate over all ASM instances (irrespective of 'Y' or 'N') AND # wait for all of them to be started # fi # 4) Bring up all Database instances with 'W' entry in status field in # oratab entry # ##################################### LOGMSG="logger -puser.alert -s " trap 'exit' 1 2 3 # for script tracing case $ORACLE_TRACE in T) set -x ;; esac # Set path if path not set (if called from /etc/rc) SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ; export PATH SAVE_LLP=$LD_LIBRARY_PATH # First argument is used to bring up Oracle Net Listener #ORACLE_HOME_LISTNER=$1 //注釋此處 ORACLE_HOME_LISTNER=$ORACLE_HOME //添加此處 if [ ! $ORACLE_HOME_LISTNER ] ; then echo "ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener" echo "Usage: $0 ORACLE_HOME" else LOG=$ORACLE_HOME_LISTNER/listener.log # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to # a different ORACLE_HOME for each entry in the oratab. export ORACLE_HOME=$ORACLE_HOME_LISTNER # Start Oracle Net Listener if [ -x $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then echo "$0: Starting Oracle Net Listener" >> $LOG 2>&1 $ORACLE_HOME_LISTNER/bin/lsnrctl start >> $LOG 2>&1 & VER10LIST=`$ORACLE_HOME_LISTNER/bin/lsnrctl version | grep "LSNRCTL for " | cut -d' ' -f5 | cut -d'.' -f1` export VER10LIST else echo "Failed to auto-start Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr" fi fi # Set this in accordance with the platform ORATAB=/etc/oratab if [ ! $ORATAB ] ; then echo "$ORATAB not found" exit 1; fi # Checks Version Mismatch between Listener and Database Instance. # A version 10 listener is required for an Oracle Database 10g database. # Previous versions of the listener are not supported for use with an Oracle # Database 10g database. However, it is possible to use a version 10 listener # with previous versions of the Oracle database. checkversionmismatch() { if [ $VER10LIST ] ; then VER10INST=`sqlplus -V | grep "Release " | cut -d' ' -f3 | cut -d'.' -f1` if [ $VER10LIST -lt $VER10INST ] ; then $LOGMSG "Listener version $VER10LIST NOT supported with Database version $VER10INST" $LOGMSG "Restart Oracle Net Listener using an alternate ORACLE_HOME_LISTNER:" $LOGMSG "lsnrctl start" fi fi } # Starts a Database Instance startinst() { # Called programs use same database ID export ORACLE_SID # Put $ORACLE_HOME/bin into PATH and export. PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH # add for bug # 652997 LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora SPFILE=${ORACLE_HOME}/dbs/spfile${ORACLE_SID}.ora SPFILE1=${ORACLE_HOME}/dbs/spfile.ora echo "" echo "$0: Starting up database \"$ORACLE_SID\"" date echo "" checkversionmismatch # See if it is a V6 or V7 database VERSION=undef if [ -f $ORACLE_HOME/bin/sqldba ] ; then SQLDBA=sqldba VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk ' /SQL\*DBA: (Release|Version)/ {split($3, V, ".") ; print V[1]}'` case $VERSION in "6") ;; *) VERSION="internal" ;; esac else if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then SQLDBA=svrmgrl VERSION="internal" else SQLDBA="sqlplus /nolog" fi fi STATUS=1 if [ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.dbf ] ; then STATUS="-1" fi if [ -f $ORACLE_HOME/dbs/sgadef${ORACLE_SID}.ora ] ; then STATUS="-1" fi pmon=`ps -ef | grep -w "ora_pmon_$ORACLE_SID" | grep -v grep` if [ "$pmon" != "" ] ; then STATUS="-1" $LOGMSG "Warning: ${INST} \"${ORACLE_SID}\" already started." fi if [ $STATUS -eq -1 ] ; then $LOGMSG "Warning: ${INST} \"${ORACLE_SID}\" possibly left running when system went down (system crash?)." $LOGMSG "Action: Notify Database Administrator." case $VERSION in "6") sqldba "command=shutdown abort" ;; "internal") $SQLDBA $args <<EOF connect internal shutdown abort EOF ;; *) $SQLDBA $args <<EOF connect / as sysdba shutdown abort quit EOF ;; esac if [ $? -eq 0 ] ; then STATUS=1 else $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOT started." fi fi if [ $STATUS -eq 1 ] ; then if [ -e $SPFILE -o -e $SPFILE1 -o -e $PFILE ] ; then case $VERSION in "6") sqldba command=startup ;; "internal") $SQLDBA <<EOF connect internal startup EOF ;; *) $SQLDBA <<EOF connect / as sysdba startup quit EOF ;; esac if [ $? -eq 0 ] ; then echo "" echo "$0: ${INST} \"${ORACLE_SID}\" warm started." else $LOGMSG "" $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOT started." fi else $LOGMSG "" $LOGMSG "No init file found for ${INST} \"${ORACLE_SID}\"." $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOT started." fi fi } # Starts an ASM Instance startasminst() { # Called programs use same database ID export ORACLE_SID ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` # Called scripts use same home directory export ORACLE_HOME # For ASM instances, we have a dependency on the CSS service. # Wait here for it to become available before instance startup. # Is the 10g install intact? Are all necessary binaries present? if [ ! -x $ORACLE_HOME/bin/crsctl ]; then $LOGMSG "$ORACLE_HOME/bin/crsctl not found when attempting to start" $LOGMSG " ASM instance $ORACLE_SID." else COUNT=0 $ORACLE_HOME/bin/crsctl check css RC=$? while [ "$RC" != "0" ]; do COUNT=`expr $COUNT + 1` if [ $COUNT = 15 ] ; then # 15 tries with 20 sec interval => 5 minutes timeout $LOGMSG "Timed out waiting to start ASM instance $ORACLE_SID" $LOGMSG " CSS service is NOT available." exit $COUNT fi $LOGMSG "Waiting for Oracle CSS service to be available before starting " $LOGMSG " ASM instance $ORACLE_SID. Wait $COUNT." sleep 20 $ORACLE_HOME/bin/crsctl check css RC=$? done fi startinst } # Start of dbstartup script # # Loop for every entry in oratab file and and try to start # that ORACLE. # # ASM instances need to be started before 'Database instances' # ASM instance is identified with '+' prefix in ORACLE_SID # Following loop brings up ASM instance[s] cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # same as NULL SID - ignore this entry ORACLE_SID="" continue fi # Proceed only if last field is 'Y'. if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then # If ASM instances if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then INST="ASM instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` # Called scripts use same home directory export ORACLE_HOME # file for logging script's output LOG=$ORACLE_HOME/startup.log touch $LOG chmod a+r $LOG echo "Processing $INST \"$ORACLE_SID\": log file $ORACLE_HOME/startup.log" startasminst >> $LOG 2>&1 fi fi ;; esac done # exit if there was any trouble bringing up ASM instance[s] if [ "$?" != "0" ] ; then exit 2 fi # # Following loop brings up 'Database instances' # cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # same as NULL SID - ignore this entry ORACLE_SID="" continue fi # Proceed only if last field is 'Y'. if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then # If non-ASM instances if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then INST="Database instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` # Called scripts use same home directory export ORACLE_HOME # file for logging script's output LOG=$ORACLE_HOME/startup.log touch $LOG chmod a+r $LOG echo "Processing $INST \"$ORACLE_SID\": log file $ORACLE_HOME/startup.log" startinst >> $LOG 2>&1 fi fi ;; esac done # # Following loop brings up 'Database instances' that have wait state 'W' # cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # same as NULL SID - ignore this entry ORACLE_SID="" continue fi # Proceed only if last field is 'W'. if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then W_ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` # DB instances with 'W' (wait state) have a dependency on ASM instances via CRS. # Wait here for 'all' ASM instances to become available. cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # same as NULL SID - ignore this entry ORACLE_SID="" continue fi if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then INST="ASM instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` if [ -x $ORACLE_HOME/bin/srvctl ] ; then COUNT=0 NODE=`olsnodes -l` RNODE=`srvctl status asm -n $NODE | grep "$ORACLE_SID is running"` RC=$? while [ "$RC" != "0" ]; # wait until this comes up! do COUNT=$((COUNT+1)) if [ $COUNT = 5 ] ; then # 5 tries with 60 sec interval => 5 minutes timeout $LOGMSG "Error: Timed out waiting on CRS to start ASM instance $ORACLE_SID" exit $COUNT fi $LOGMSG "Waiting for Oracle CRS service to start ASM instance $ORACLE_SID" $LOGMSG "Wait $COUNT." sleep 60 RNODE=`srvctl status asm -n $NODE | grep "$ORACLE_SID is running"` RC=$? done else $LOGMSG "Error: \"${W_ORACLE_SID}\" has dependency on ASM instance \"${ORACLE_SID}\"" $LOGMSG "Error: Need $ORACLE_HOME/bin/srvctl to check this dependency" fi fi # asm instance ;; esac done # innner while fi ;; esac done # outer while # by now all the ASM instances have come up and we can proceed to bring up # DB instance with 'W' wait status cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # same as NULL SID - ignore this entry ORACLE_SID="" continue fi # Proceed only if last field is 'W'. if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then INST="Database instance" if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then $LOGMSG "Error: ${INST} \"${ORACLE_SID}\" NOT started" $LOGMSG "Error: incorrect usage: 'W' not allowed for ASM instances" continue fi ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` # Called scripts use same home directory export ORACLE_HOME # file for logging script's output LOG=$ORACLE_HOME/startup.log touch $LOG chmod a+r $LOG echo "Processing $INST \"$ORACLE_SID\": log file $ORACLE_HOME/startup.log" startinst >> $LOG 2>&1 fi ;; esac done
[root@oracleserver ~]# vim /oracle/app/product/11.2.0/dbhome_1/bin/dbshut #!/bin/sh # # $Id: dbshut.sh 22-may-2008.05:19:31 arogers Exp $ # Copyright (c) 1991, 2008, Oracle. All rights reserved. # ################################### # # usage: dbshut $ORACLE_HOME # # This script is used to shutdown ORACLE from /etc/rc(.local). # It should ONLY be executed as part of the system boot procedure. # # This script will shutdown all databases listed in the oratab file # whose third field is a "Y" or "W". If the third field is set to "Y" and # there is no ORACLE_SID for an entry (the first field is a *), # then this script will ignore that entry. # # This script requires that ASM ORACLE_SID's start with a +, and # that non-ASM instance ORACLE_SID's do not start with a +. # # Note: # Use ORACLE_TRACE=T for tracing this script. # Oracle Net Listener is also shutdown using this script. # # The progress log for each instance shutdown is logged in file # $ORACLE_HOME/shutdown.log. # # On all UNIX platforms except SOLARIS # ORATAB=/etc/oratab # # To configure, update ORATAB with Instances that need to be shutdown # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:<N|Y>: # An example entry: # main:/usr/lib/oracle/emagent_10g:Y # ##################################### trap 'exit' 1 2 3 case $ORACLE_TRACE in T) set -x ;; esac # Set path if path not set (if called from /etc/rc) SAVE_PATH=/bin:/usr/bin:/etc:${PATH} ; export PATH SAVE_LLP=$LD_LIBRARY_PATH # The this to bring down Oracle Net Listener #ORACLE_HOME_LISTNER=$1 //注釋此處 ORACLE_HOME_LISTNER=$ORACLE_HOME //添加此處 if [ ! $ORACLE_HOME_LISTNER ] ; then echo "ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener" echo "Usage: $0 ORACLE_HOME" else LOG=$ORACLE_HOME_LISTNER/listener.log # Set the ORACLE_HOME for the Oracle Net Listener, it gets reset to # a different ORACLE_HOME for each entry in the oratab. export ORACLE_HOME=$ORACLE_HOME_LISTNER # Stop Oracle Net Listener if [ -f $ORACLE_HOME_LISTNER/bin/tnslsnr ] ; then echo "$0: Stoping Oracle Net Listener" >> $LOG 2>&1 $ORACLE_HOME_LISTNER/bin/lsnrctl stop >> $LOG 2>&1 & else echo "Failed to auto-stop Oracle Net Listener using $ORACLE_HOME_LISTNER/bin/tnslsnr" fi fi # Set this in accordance with the platform ORATAB=/etc/oratab if [ ! $ORATAB ] ; then echo "$ORATAB not found" exit 1; fi # Stops an instance stopinst() { ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then ORACLE_SID="" fi # Called programs use same database ID export ORACLE_SID ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` # Called scripts use same home directory export ORACLE_HOME # Put $ORACLE_HOME/bin into PATH and export. PATH=$ORACLE_HOME/bin:${SAVE_PATH} ; export PATH # add for bug 652997 LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${SAVE_LLP} ; export LD_LIBRARY_PATH PFILE=${ORACLE_HOME}/dbs/init${ORACLE_SID}.ora # See if it is a V6 or V7 database VERSION=undef if [ -f $ORACLE_HOME/bin/sqldba ] ; then SQLDBA=sqldba VERSION=`$ORACLE_HOME/bin/sqldba command=exit | awk ' /SQL\*DBA: (Release|Version)/ {split($3, V, ".") ; print V[1]}'` case $VERSION in "6") ;; *) VERSION="internal" ;; esac else if [ -f $ORACLE_HOME/bin/svrmgrl ] ; then SQLDBA=svrmgrl VERSION="internal" else SQLDBA="sqlplus /nolog" fi fi case $VERSION in "6") sqldba command=shutdown ;; "internal") $SQLDBA <<EOF connect internal shutdown immediate EOF ;; *) $SQLDBA <<EOF connect / as sysdba shutdown immediate quit EOF ;; esac if test $? -eq 0 ; then echo "${INST} \"${ORACLE_SID}\" shut down." else echo "${INST} \"${ORACLE_SID}\" not shut down." fi } # # Loop for every entry in oratab file and and try to shut down # that ORACLE # # Following loop shuts down 'Database Instance[s]' with 'Y' entry cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # NULL SID - ignore ORACLE_SID="" continue fi # Proceed only if last field is 'Y' or 'W' if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then INST="Database instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` LOG=$ORACLE_HOME/shutdown.log echo "Processing $INST \"$ORACLE_SID\": log file $LOG" stopinst >> $LOG 2>&1 fi fi ;; esac done # # Following loop shuts down 'Database Instance[s]' with 'W' entry # cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # NULL SID - ignore ORACLE_SID="" continue fi # Proceed only if last field is 'Y' or 'W' if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "W" ] ; then if [ `echo $ORACLE_SID | cut -b 1` != '+' ]; then INST="Database instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` LOG=$ORACLE_HOME/shutdown.log echo "Processing $INST \"$ORACLE_SID\": log file $LOG" stopinst >> $LOG 2>&1 fi fi ;; esac done # # Following loop shuts down 'ASM Instance[s]' # cat $ORATAB | while read LINE do case $LINE in \#*) ;; #comment-line in oratab *) ORACLE_SID=`echo $LINE | awk -F: '{print $1}' -` if [ "$ORACLE_SID" = '*' ] ; then # NULL SID - ignore ORACLE_SID="" continue fi # Proceed only if last field is 'Y'. # Entries whose last field is not Y or N are not DB entry, ignore them. if [ "`echo $LINE | awk -F: '{print $NF}' -`" = "Y" ] ; then if [ `echo $ORACLE_SID | cut -b 1` = '+' ]; then INST="ASM instance" ORACLE_HOME=`echo $LINE | awk -F: '{print $2}' -` LOG=$ORACLE_HOME/shutdown.log echo "Processing $INST \"$ORACLE_SID\": log file $LOG" stopinst >> $LOG 2>&1 fi fi ;; esac done
[root@oracleserver ~]# vim /etc/rc.d/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own systemd services or udev rules # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local su oracle -lc "/oracle/app/product/11.2.0/dbhome_1/bin/lsnrctl start" //添加此處 su oracle -lc "/oracle/app/product/11.2.0/dbhome_1/bin/dbstart" //添加此處 #開機啟動文件執行權限授權 [root@oracleserver ~]# ls -l /etc/rc.d/rc.local -rw-r--r-- 1 775 root 607 8月 31 13:51 /etc/rc.d/rc.local [root@oracleserver ~]# chmod +x /etc/rc.d/rc.local [root@oracleserver ~]# ls -l /etc/rc.d/rc.local -rwxr-xr-x 1 775 root 607 8月 31 13:51 /etc/rc.d/rc.local
13、數據庫常用操作
(1)數據庫實例啟動
[oracle@oracleserver ~]$ sqlplus /nolog SQL> connect / as sysdba SQL> startup (默認安裝后自啟動) SQL> startup force (強制啟動) ORACLE instance started. Total System Global Area 534462464 bytes Fixed Size 2215064 bytes Variable Size 360711016 bytes Database Buffers 159383552 bytes Redo Buffers 12152832 bytes Database mounted. Database opened. #查詢數據庫啟動狀態 SQL> select status from v$instance; STATUS ------------ OPEN
(2)數據庫實例停止
[oracle@oracleserver ~]$ sqlplus /nolog SQL> connect / as sysoper SQL> shutdown immediate; Database closed. Database dismounted. ORACLE instance shut down.
(3)配置數據庫監聽
#監聽配置文件路徑設置 [oracle@oracleserver ~]$ vim /etc/oratab # # This file is used by ORACLE utilities. It is created by root.sh # and updated by the Database Configuration Assistant when creating # a database. # A colon, ':', is used as the field terminator. A new line terminates # the entry. Lines beginning with a pound sign, '#', are comments. # # Entries are of the form: # $ORACLE_SID:$ORACLE_HOME:<N|Y>: # # 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. # # orcl:/oracle/app/product/11.2.0/dbhome_1:N #配置數據庫監聽端口 [oracle@oracleserver ~]$ cat /oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora # listener.ora Network Configuration File: /oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /oracle/app
[oracle@oracleserver ~]$ lsnrctl stop //停止數據庫監聽服務 [oracle@oracleserver ~]$ lsnrctl start //啟動數據庫監聽服務(啟動后等待5秒再檢查) [oracle@oracleserver ~]$ lsnrctl status //查詢數據庫監聽服務狀態 LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 31-AUG-2019 11:02:53 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 30-AUG-2019 23:48:25 Uptime 0 days 11 hr. 14 min. 28 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /oracle/app/product/11.2.0/dbhome_1/network/admin/listener.ora Listener Log File /oracle/app/diag/tnslsnr/oracleserver/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))) Services Summary... Service "orcl" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... Service "orclXDB" has 1 instance(s). Instance "orcl", status READY, has 1 handler(s) for this service... The command completed successfully