2种方式安装Oracle
A.容器安装
B.宿主机安装
系统环境:
[root@oracle12c216 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@oracle12c216 ~]# uname -r
5.4.127-1.el7.elrepo.x86_64
方式一,宿主机安装
1.安装前的准备!!!
yum install -y binutils compat-libcap1 gcc gcc-c++ glibc glibc-devel glibc-headers ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC zlib-devel unzip unixODBC-devel compat-libstdc++-33
2.创建用户、组并且设置密码
[root@oracle12c216 ~]# groupadd oinstall [root@oracle12c216 ~]# groupadd dba [root@oracle12c216 ~]# useradd -m -g oinstall -G dba oracle [root@oracle12c216 ~]# passwd oracle 更改用户 oracle 的密码 。 新的 密码: 重新输入新的 密码: passwd:所有的身份验证令牌已经成功更新。 或者用下面的命令: groupadd oinstall groupadd dba /usr/sbin/useradd -d /home/oracle -g oinstall -G dba oracle && passwd -l oracle
3.配置系统内核参数
cat >> /usr/lib/sysctl.d/00-system.conf <<EOF fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576 EOF cat >> /etc/sysctl.conf <<EOF fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmmni = 4096 kernel.sem = 250 32000 100 128 net.ipv4.ip_local_port_range = 9000 65500 net.core.rmem_default = 262144 net.core.rmem_max = 4194304 net.core.wmem_default = 262144 net.core.wmem_max = 1048576 EOF sysctl -p
4.修改系统资源限制
cat >> /etc/security/limits.conf <<EOF oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 oracle soft stack 10240 EOF
5. 修改登陆配置文件
cat >> /etc/pam.d/login <<EOF session required pam_limits.so EOF
6.设置Oracle用户的环境变量
cat >> /home/oracle/.bash_profile <<EOF export TMP=/tmp export TMPDIR=\$TMP export ORACLE_SID=qzing export ORACLE_BASE=/u01/oracle export ORACLE_HOME=\$ORACLE_BASE/product/12c/dbhome_1 export TNS_ADMIN=\$ORACLE_HOME/network/admin export ORACLE_TERM=xterm export PATH=/usr/sbin:\$PATH export PATH=\$ORACLE_HOME/bin:\$PATH export LD_LIBRARY_PATH=\$ORACLE_HOME/lib:/lib:/usr/lib:\$ORACLE_HOME/jdbc/lib export CLASSPATH=\$ORACLE_HOME/JRE:\$ORACLE_HOME/jlib:\$ORACLE_HOME/rdbms/jlib export NLS_LANG="AMERICAN_AMERICA.AL32UTF8" export NLS_DATE_FORMAT='yyyy/mm/dd hh24:mi:ss' umask 022 if [ $USER = "oracle" ]; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi fi EOF
7.创建相关目录
mkdir -p /u01/oracle && mkdir -p /data/oradata && mkdir -p /software cd /software unzip linuxamd64_12102_database_1of2.zip -d /software/ unzip linuxamd64_12102_database_2of2.zip -d /software/ chown -R oracle:oinstall /u01 && chmod -R 755 /u01 chown -R oracle:oinstall /data && chmod -R 755 /data #将相关的安装应答文件放在这里 [root@10-10-20-236 ~]# su - oracle 上一次登录:二 12月 7 11:14:14 CST 2021pts/0 上 [oracle@10-10-20-236 ~]$ mkdir -p /u01/oracle/qzing_rsp [oracle@10-10-20-236 ~]$ cd /u01/oracle/qzing_rsp/ [oracle@10-10-20-236 qzing_rsp]$ rz [oracle@10-10-20-236 qzing_rsp]$ tree . ├── dbca.rsp ├── db_install.rsp └── netca.rsp
配置文件详解:
1)db_install.rsp
#################################################################### ## Copyright(c) Oracle Corporation 1998,2014. 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_v12.1.0 #选择安装类型:1.只装数据库软件 2.安装数据库软件并建库 3.升级数据库 #------------------------------------------------------------------------------- # Specify the installation option. # It can be one of the following: # - INSTALL_DB_SWONLY # - INSTALL_DB_AND_CONFIG # - UPGRADE_DB #------------------------------------------------------------------------------- oracle.install.option= #设置Oracle的主机名,一般和系统的保持一致 #------------------------------------------------------------------------------- # 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= #指定oracle inventory目录的所有者,通常会是oinstall或者dba #------------------------------------------------------------------------------- # Specify the Unix group to be set for the inventory directory. #------------------------------------------------------------------------------- UNIX_GROUP_NAME= #指定产品清单oracle inventory目录的路径 #------------------------------------------------------------------------------- # Specify the location which holds the inventory files. # This is an optional parameter if installing on # Windows based Operating System. #------------------------------------------------------------------------------- INVENTORY_LOCATION= #指定数据库语言,可以选择多个,用逗号隔开.一般选择en, zh_CN(英文和简体中文) #------------------------------------------------------------------------------- # 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 # # all_langs : All languages # # Specify value as the following to select any of the languages. # Example : SELECTED_LANGUAGES=en,fr,ja # # Specify value as the following to select all the languages. # Example : SELECTED_LANGUAGES=all_langs #------------------------------------------------------------------------------- SELECTED_LANGUAGES=en #设置ORALCE_HOME的路径 #------------------------------------------------------------------------------- # Specify the complete path of the Oracle Home. #------------------------------------------------------------------------------- ORACLE_HOME= #设置ORALCE_BASE的路径 #------------------------------------------------------------------------------- # Specify the complete path of the Oracle Base. #------------------------------------------------------------------------------- ORACLE_BASE= #选择Oracle安装数据库软件的版本(企业版),不同的版本功能不同 #------------------------------------------------------------------------------- # Specify the installation edition of the component. # # The value should contain only one of these choices. # - EE : Enterprise Edition #------------------------------------------------------------------------------- oracle.install.db.InstallEdition= ############################################################################### # # # 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 value to be specified for OSDBA and OSOPER group is only for UNIX based # # Operating System. # # # ############################################################################### #指定拥有DBA用户组,通常会是dba组 #------------------------------------------------------------------------------ # The DBA_GROUP is the OS group which is to be granted OSDBA privileges. #------------------------------------------------------------------------------- oracle.install.db.DBA_GROUP= #指定oper用户组,1st是oinstall ,其余3个是dba #------------------------------------------------------------------------------ # The OPER_GROUP is the OS group which is to be granted OSOPER privileges. # The value to be specified for OSOPER group is optional. #------------------------------------------------------------------------------ oracle.install.db.OPER_GROUP= #------------------------------------------------------------------------------ # The BACKUPDBA_GROUP is the OS group which is to be granted OSBACKUPDBA privileges. #------------------------------------------------------------------------------ oracle.install.db.BACKUPDBA_GROUP= #------------------------------------------------------------------------------ # The DGDBA_GROUP is the OS group which is to be granted OSDGDBA privileges. #------------------------------------------------------------------------------ oracle.install.db.DGDBA_GROUP= #------------------------------------------------------------------------------ # The KMDBA_GROUP is the OS group which is to be granted OSKMDBA privileges. #------------------------------------------------------------------------------ oracle.install.db.KMDBA_GROUP= ############################################################################### # # # Grid Options # # # ############################################################################### #------------------------------------------------------------------------------ # Specify the type of Real Application Cluster Database # # - ADMIN_MANAGED: Admin-Managed # - POLICY_MANAGED: Policy-Managed # # If left unspecified, default will be ADMIN_MANAGED #------------------------------------------------------------------------------ oracle.install.db.rac.configurationType= #------------------------------------------------------------------------------ # Value is required only if RAC database type is ADMIN_MANAGED # # Specify the cluster node names selected during the installation. # Leaving it blank will result in install on local server only (Single Instance) # # Example : oracle.install.db.CLUSTER_NODES=node1,node2 #------------------------------------------------------------------------------ oracle.install.db.CLUSTER_NODES= #------------------------------------------------------------------------------ # This variable is used to enable or disable RAC One Node install. # # - true : Value of RAC One Node service name is used. # - false : Value of RAC One Node service name is not used. # # If left blank, it will be assumed to be false. #------------------------------------------------------------------------------ oracle.install.db.isRACOneInstall= #------------------------------------------------------------------------------ # Value is required only if oracle.install.db.isRACOneInstall is true. # # Specify the name for RAC One Node Service #------------------------------------------------------------------------------ oracle.install.db.racOneServiceName= #------------------------------------------------------------------------------ # Value is required only if RAC database type is POLICY_MANAGED # # Specify a name for the new Server pool that will be configured # Example : oracle.install.db.rac.serverpoolName=pool1 #------------------------------------------------------------------------------ oracle.install.db.rac.serverpoolName= #------------------------------------------------------------------------------ # Value is required only if RAC database type is POLICY_MANAGED # # Specify a number as cardinality for the new Server pool that will be configured # Example : oracle.install.db.rac.serverpoolCardinality=2 #------------------------------------------------------------------------------ oracle.install.db.rac.serverpoolCardinality= ############################################################################### # # # Database Configuration Options # # # ############################################################################### #------------------------------------------------------------------------------- # Specify the type of database to create. # It can be one of the following: # - GENERAL_PURPOSE # - DATA_WAREHOUSE # GENERAL_PURPOSE: A starter database designed for general purpose use or transaction-heavy applications. # DATA_WAREHOUSE : A starter database optimized for data warehousing applications. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.type= #指定GlobalName #------------------------------------------------------------------------------- # Specify the Starter Database Global Database Name. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.globalDBName= #指定的SID #------------------------------------------------------------------------------- # Specify the Starter Database SID. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.SID= #------------------------------------------------------------------------------- # Specify whether the database should be configured as a Container database. # The value can be either "true" or "false". If left blank it will be assumed # to be "false". #------------------------------------------------------------------------------- oracle.install.db.ConfigureAsContainerDB= #------------------------------------------------------------------------------- # Specify the Pluggable Database name for the pluggable database in Container Database. #------------------------------------------------------------------------------- oracle.install.db.config.PDBName= #设置字符集,一般选择AL32UTF8 #------------------------------------------------------------------------------- # Specify the Starter Database character set. # # 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= #------------------------------------------------------------------------------ # 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= #------------------------------------------------------------------------------- # 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= #------------------------------------------------------------------------------- # This variable controls whether to load Example Schemas onto # the starter database or not. # The value can be either "true" or "false". If left blank it will be assumed # to be "false". #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.installExampleSchemas= ############################################################################### # # # Passwords can be supplied for the following four schemas in the # # starter database: # # SYS # # SYSTEM # # 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= #------------------------------------------------------------------------------- # Specify the SYS password for the starter database. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.password.SYS= #------------------------------------------------------------------------------- # Specify the SYSTEM password for the starter database. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.password.SYSTEM= #------------------------------------------------------------------------------- # Specify the DBSNMP password for the starter database. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.password.DBSNMP= #------------------------------------------------------------------------------- # Specify the PDBADMIN password required for creation of Pluggable Database in the Container Database. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.password.PDBADMIN= #------------------------------------------------------------------------------- # Specify the management option to use for managing the database. # Options are: # 1. CLOUD_CONTROL - If you want to manage your database with Enterprise Manager Cloud Control along with Database Express. # 2. DEFAULT -If you want to manage your database using the default Database Express option. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.managementOption= #------------------------------------------------------------------------------- # Specify the OMS host to connect to Cloud Control. # Applicable only when oracle.install.db.config.starterdb.managementOption=CLOUD_CONTROL #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.omsHost= #------------------------------------------------------------------------------- # Specify the OMS port to connect to Cloud Control. # Applicable only when oracle.install.db.config.starterdb.managementOption=CLOUD_CONTROL #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.omsPort= #------------------------------------------------------------------------------- # Specify the EM Admin user name to use to connect to Cloud Control. # Applicable only when oracle.install.db.config.starterdb.managementOption=CLOUD_CONTROL #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.emAdminUser= #------------------------------------------------------------------------------- # Specify the EM Admin password to use to connect to Cloud Control. # Applicable only when oracle.install.db.config.starterdb.managementOption=CLOUD_CONTROL #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.emAdminPassword= ############################################################################### # # # SPECIFY RECOVERY OPTIONS # # ------------------------------------ # # Recovery options for the database can be mentioned using the entries below # # # ############################################################################### #------------------------------------------------------------------------------ # This variable is to be set to false if database recovery is not required. Else # this can be set to true. #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.enableRecovery= #------------------------------------------------------------------------------- # Specify the type of storage to use for the database. # It can be one of the following: # - FILE_SYSTEM_STORAGE # - ASM_STORAGE #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.storageType= #------------------------------------------------------------------------------- # 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_STORAGE #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.fileSystemStorage.dataLocation= #------------------------------------------------------------------------------- # Specify the recovery location. # # Applicable only when oracle.install.db.config.starterdb.storage=FILE_SYSTEM_STORAGE #------------------------------------------------------------------------------- oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation= #------------------------------------------------------------------------------- # Specify the existing ASM disk groups to be used for storage. # # Applicable only when oracle.install.db.config.starterdb.storageType=ASM_STORAGE #------------------------------------------------------------------------------- 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_STORAGE #------------------------------------------------------------------------------- oracle.install.db.config.asm.ASMSNMPPassword= #------------------------------------------------------------------------------ # Specify the My Oracle Support Account Username. # # Example : [email protected] #------------------------------------------------------------------------------ MYORACLESUPPORT_USERNAME= #------------------------------------------------------------------------------ # Specify the My Oracle Support Account Username password. # # Example : MYORACLESUPPORT_PASSWORD=password #------------------------------------------------------------------------------ MYORACLESUPPORT_PASSWORD= #安装时的安全更新检查,一般选FALSE #------------------------------------------------------------------------------ # 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 #------------------------------------------------------------------------------ SECURITY_UPDATES_VIA_MYORACLESUPPORT= #拒绝安全更新,一般选TRUE #------------------------------------------------------------------------------ # Specify whether user doesn't want to configure Security Updates. # The value for this variable should be true if you don't want to configure # Security Updates, false otherwise. # # The value can be either true or false. If left blank it will be assumed # to be false. # # Example : DECLINE_SECURITY_UPDATES=false #------------------------------------------------------------------------------ DECLINE_SECURITY_UPDATES= #------------------------------------------------------------------------------ # 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 at least 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= #------------------------------------------------------------------------------ # Specify the Oracle Support Hub URL. # # Example : COLLECTOR_SUPPORTHUB_URL=https://orasupporthub.company.com:8080/ #------------------------------------------------------------------------------ COLLECTOR_SUPPORTHUB_URL=
修改好之后的完整的配置文件:
egrep -v “^#|^$” db_install.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v12.1.0 oracle.install.option=INSTALL_DB_SWONLY ORACLE_HOSTNAME=10-10-20-236 UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/u01/oraInventory SELECTED_LANGUAGES=en ORACLE_HOME=/u01/oracle/product/12c/dbhome_1 ORACLE_BASE=/u01/oracle/ oracle.install.db.InstallEdition=EE oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=oinstall oracle.install.db.BACKUPDBA_GROUP=dba oracle.install.db.DGDBA_GROUP=dba oracle.install.db.KMDBA_GROUP=dba oracle.install.db.rac.configurationType= oracle.install.db.CLUSTER_NODES= oracle.install.db.isRACOneInstall= oracle.install.db.racOneServiceName= oracle.install.db.rac.serverpoolName= oracle.install.db.rac.serverpoolCardinality= oracle.install.db.config.starterdb.type= oracle.install.db.config.starterdb.globalDBName=qzing oracle.install.db.config.starterdb.SID=qzing oracle.install.db.ConfigureAsContainerDB= oracle.install.db.config.PDBName= oracle.install.db.config.starterdb.characterSet=AL32UTF8 oracle.install.db.config.starterdb.memoryOption= oracle.install.db.config.starterdb.memoryLimit= oracle.install.db.config.starterdb.installExampleSchemas= oracle.install.db.config.starterdb.password.ALL=qzing777 oracle.install.db.config.starterdb.password.SYS= oracle.install.db.config.starterdb.password.SYSTEM= oracle.install.db.config.starterdb.password.DBSNMP= oracle.install.db.config.starterdb.password.PDBADMIN= oracle.install.db.config.starterdb.managementOption= oracle.install.db.config.starterdb.omsHost= oracle.install.db.config.starterdb.omsPort= oracle.install.db.config.starterdb.emAdminUser= oracle.install.db.config.starterdb.emAdminPassword= oracle.install.db.config.starterdb.enableRecovery= oracle.install.db.config.starterdb.storageType= oracle.install.db.config.starterdb.fileSystemStorage.dataLocation= oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation= oracle.install.db.config.asm.diskGroup= oracle.install.db.config.asm.ASMSNMPPassword= MYORACLESUPPORT_USERNAME= MYORACLESUPPORT_PASSWORD= SECURITY_UPDATES_VIA_MYORACLESUPPORT= DECLINE_SECURITY_UPDATES=true PROXY_HOST= PROXY_PORT= PROXY_USER= PROXY_PWD= COLLECTOR_SUPPORTHUB_URL=
修改后的完整的dbca.rsp配置文件
[oracle@10-10-20-236 rsp]$ egrep -v '^#|^$' dbca.rsp [GENERAL] RESPONSEFILE_VERSION = "12.1.0" OPERATION_TYPE = "createDatabase" [CREATEDATABASE] GDBNAME = "qzing" SID = "qzing" TEMPLATENAME = "General_Purpose.dbc" SYSPASSWORD = "qzing777" SYSTEMPASSWORD = "qzing777" DATAFILEDESTINATION =/data/oradata CHARACTERSET = "AL32UTF8" NATIONALCHARACTERSET= "UTF8" TOTALMEMORY = "4096" [createTemplateFromDB] SOURCEDB = "myhost:1521:orcl" SYSDBAUSERNAME = "system" TEMPLATENAME = "My Copy TEMPLATE" [createCloneTemplate] SOURCEDB = "orcl" TEMPLATENAME = "My Clone TEMPLATE" [DELETEDATABASE] SOURCEDB = "orcl" [generateScripts] TEMPLATENAME = "New Database" GDBNAME = "orcl12.us.oracle.com" [CONFIGUREDATABASE] [ADDINSTANCE] DB_UNIQUE_NAME = "orcl12c.us.oracle.com" NODENAME= SYSDBAUSERNAME = "sys" [DELETEINSTANCE] DB_UNIQUE_NAME = "orcl12c.us.oracle.com" INSTANCENAME = "orcl12c" SYSDBAUSERNAME = "sys" [CREATEPLUGGABLEDATABASE] SOURCEDB = "orcl" PDBNAME = "PDB1" [UNPLUGDATABASE] SOURCEDB = "orcl" PDBNAME = "PDB1" ARCHIVETYPE = "TAR" [DELETEPLUGGABLEDATABASE] SOURCEDB = "orcl" PDBNAME = "PDB1" [CONFIGUREPLUGGABLEDATABASE] SOURCEDB = "orcl" PDBNAME = "PDB1"
netca.rsp默认可以不用修改
8.安装数据库
#安装数据库
[oracle@10-10-20-236 database]$ whoami oracle [oracle@10-10-20-236 database]$ pwd /software/database [oracle@10-10-20-236 database]$ ./runInstaller -silent -ignorePrereq -ignoreSysPrereqs -responseFile /u01/oracle/rsp/db_install.rsp
#配置监听程序
# su -l oracle
$ cd /u01/oracle/product/12c/dbhome_1/bin
$ ./netca -silent -responseFile /u01/oracle/rsp/netca.rsp
#配置建库
$ ./dbca -silent -responseFile /u01/oracle/rsp/dbca.rsp
#配置数据库启动参数
$ vi /etc/oratab qzing:/u01/oracle/product/12c/dbhome_1:Y $ vi /u01/oracle/product/12c/dbhome_1/bin/dbshut # $ORACLE_HOME_LISTENER=$1 →注释掉 ORACLE_HOME_LISTNER=$ORACLE_HOME →添加一行 $ vi /u01/oracle/product/12c/dbhome_1/bin/dbstart # $ORACLE_HOME_LISTENER=$1 ORACLE_HOME_LISTNER=$ORACLE_HOME
#启动、停止数据库命令
dbshut
dbstart
#启动、停止Oracle Listener (监听1521端口)
lsnrctl start
lsnrctl stop
#为了方便管理创建了一个Oracle的启动,停止,重启的脚本
#在 /etc/init.d/ 下创建文件oracle,内容如下:
#!/bin/bash ### BEGIN INIT INFO # Provides: oracle # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: # Description: Oracle auto start-stop script. # /etc/init.d/oracle ### END INIT INFO ORACLE_HOME=/u01/oracle/product/12c/dbhome_1 ORACLE_OWNER=oracle if [ ! -f $ORACLE_HOME/bin/dbstart ] then echo "Oracle startup: cannot start" exit fi case "$1" in 'start') # Start the Oracle databases: echo "Starting Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart" >>/var/log/oracle echo "Done" # Start the Listener: echo "Starting Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" >>/var/log/oracle echo "Done." echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle touch /var/lock/subsys/oracle ;; 'stop') # Stop the Oracle Listener: echo "Stoping Oracle Listeners ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" >>/var/log/oracle echo "Done." rm -f /var/lock/subsys/oracle # Stop the Oracle Database: echo "Stoping Oracle Databases ... " echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut" >>/var/log/oracle echo "Done." echo "" echo "-------------------------------------------------" >> /var/log/oracle date +" %T %a %D : Finished." >> /var/log/oracle echo "-------------------------------------------------" >> /var/log/oracle ;; 'restart') $0 stop $0 start ;; *) echo $"Usage: $0 {start|stop|restart}" RETVAL=1 esac exit $RETVAL
#改变文件权限
chmod 755 /etc/init.d/oracle
#添加服务
chkconfig –level 2345 oracle on
#使用方法
service oracle start
service oracle stop
service oracle restart
#创建多个不同的服务名
[oracle@10-10-20-236 platform_rsp]$ tree /u01/oracle/platform_rsp/
/u01/oracle/platform_rsp/
├── dbca.rsp
├── netca.rsp
└── platform.sh
0 directories, 3 files
PS:其实这里只要修改下dbca.rsp的几个关键的配置就可以了,比如:
#安装新的服务名叫platform
[oracle@10-10-20-236 bin]$ pwd
/u01/oracle/product/12c/dbhome_1/bin
./dbca -silent -responseFile /u01/oracle/platform_rsp/dbca.rsp
#安装完成之后,机看到了新的服务
#分享2个创建表空间的shell脚本
#在qzing下创建nba
[oracle@10-10-20-236 qzing_rsp]$ cat nba-for-sid-qzing.sh #!/bin/bash ################################################################################################ # Install software -- Install oracle 12C database software on CentOS7 # # History: 2018/08/14 Asa release v1 # History: 2021/08/23 Asa release v2 ################################################################################################ # set a safe path before doing anything else PATH=/home/oracle/bin:/usr/local/bin:/usr/bin:/bin:/u01/oracle/product/12c/dbhome_1/bin; export PATH #RSP="/software/database_nba/rsp" #SOFTWARE_HOME="/software/database_nba" ORACLE_SID=qzing ORACLE_BASE=/u01/oracle ORACLE_HOME=\$ORACLE_BASE/product/12c/dbhome_1 #----------------------------------------------------------------------------------------------- # This script must be executed as root RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\= '{print $2}'` if [ ${RUID} != "0" ];then $ECHO "This script must be executed as root" exit 1 fi #----------------------------------------------------------------------------------------------- # Display an error and exit errorExit() { echo "$@" >&2 exit 1 } #----------------------------------------------------------------------------------------------- # Display the normal print displayheader() { echo -e "\033[32m*******************************************************************\033[0m" echo -e "\033[32m*\033[0m"$@"" echo -e "\033[32m*******************************************************************\033[0m" echo "" } #----------------------------------------------------------------------------------------------- # Create temp_tablespace tempspace(){ su - oracle -c "export ORACLE_SID=${ORACLE_SID} && ${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF connect / as sysdba create temporary tablespace nba_temp tempfile '/data/oradata/qzing/nba_temp.dbf' size 64m autoextend on next 64m maxsize unlimited extent management local; exit EOF if [ $? != 0 ]; then errorExit 'Unable to create temp_tablespace for database' fi return 0 } #----------------------------------------------------------------------------------------------- # Create data_tablespace dataspace(){ su - oracle -c "export ORACLE_SID=${ORACLE_SID} && ${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF connect / as sysdba create tablespace nba_data logging datafile '/data/oradata/qzing/nba_data.dbf' size 64m autoextend on next 64m maxsize unlimited extent management local; exit EOF if [ $? != 0 ]; then errorExit 'Unable to create data_tablespace for database' fi return 0 } #----------------------------------------------------------------------------------------------- # Create User Grant permission grant(){ su - oracle -c "export ORACLE_SID=${ORACLE_SID} && ${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF connect / as sysdba create user nba identified by nba777 default tablespace nba_data temporary tablespace nba_temp; grant connect,resource to nba; grant create view to nba; grant create public synonym to nba; grant drop public synonym to nba; grant unlimited tablespace to nba; alter profile default limit password_life_time unlimited; exit EOF if [ $? != 0 ]; then errorExit 'Unable to Create User Grant permission for database' fi return 0 } #----------------------------------------------------------------------------------------------- # Create or replace directory replace(){ su - oracle -c "mkdir -p /data/dbbackup" su - oracle -c "export ORACLE_SID=${ORACLE_SID} && ${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF connect / as sysdba create or replace directory dir_dump as '/data/dbbackup'; grant read,write on directory dir_dump to nba; exit EOF if [ $? != 0 ]; then errorExit 'Unable to create or replace directory for database' fi return 0 } tempspace && displayheader "Create temp_tablespace successful" || errorExit 'Failed to prepare system' sleep 5 dataspace && displayheader "Create data_tablespace successful" || errorExit 'Failed to system' sleep 5 grant && displayheader "Create User Grant permission successful" || errorExit 'Failed to system' sleep 5 replace && displayheader "Create or replace directory successful" || errorExit 'Failed to system' sleep 5
#在platform下创建nba
[oracle@10-10-20-236 platform_rsp]$ cat nba-for-sid-platform.sh #!/bin/bash ################################################################################################ # Install software -- Install oracle 12C database software on CentOS7 # # History: 2018/08/14 Asa release v1 # History: 2021/08/23 Asa release v2 ################################################################################################ # set a safe path before doing anything else PATH=/home/oracle/bin:/usr/local/bin:/usr/bin:/bin:/u01/oracle/product/12c/dbhome_1/bin; export PATH #RSP="/software/database_nba/rsp" #SOFTWARE_HOME="/software/database_nba" ORACLE_SID=platform ORACLE_BASE=/u01/oracle ORACLE_HOME=\$ORACLE_BASE/product/12c/dbhome_1 #----------------------------------------------------------------------------------------------- # This script must be executed as root RUID=`/usr/bin/id|awk -F\( '{print $1}'|awk -F\= '{print $2}'` if [ ${RUID} != "0" ];then $ECHO "This script must be executed as root" exit 1 fi #----------------------------------------------------------------------------------------------- # Display an error and exit errorExit() { echo "$@" >&2 exit 1 } #----------------------------------------------------------------------------------------------- # Display the normal print displayheader() { echo -e "\033[32m*******************************************************************\033[0m" echo -e "\033[32m*\033[0m"$@"" echo -e "\033[32m*******************************************************************\033[0m" echo "" } #----------------------------------------------------------------------------------------------- # Create temp_tablespace tempspace(){ su - oracle -c "export ORACLE_SID=${ORACLE_SID} && ${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF connect / as sysdba create temporary tablespace nba_temp tempfile '/data/oradata/platform/nba_temp.dbf' size 64m autoextend on next 64m maxsize unlimited extent management local; exit EOF if [ $? != 0 ]; then errorExit 'Unable to create temp_tablespace for database' fi return 0 } #----------------------------------------------------------------------------------------------- # Create data_tablespace dataspace(){ su - oracle -c "export ORACLE_SID=${ORACLE_SID} && ${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF connect / as sysdba create tablespace nba_data logging datafile '/data/oradata/platform/nba_data.dbf' size 64m autoextend on next 64m maxsize unlimited extent management local; exit EOF if [ $? != 0 ]; then errorExit 'Unable to create data_tablespace for database' fi return 0 } #----------------------------------------------------------------------------------------------- # Create User Grant permission grant(){ su - oracle -c "export ORACLE_SID=${ORACLE_SID} && ${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF connect / as sysdba create user nba identified by nba777 default tablespace nba_data temporary tablespace nba_temp; grant connect,resource to nba; grant create view to nba; grant create public synonym to nba; grant drop public synonym to nba; grant unlimited tablespace to nba; alter profile default limit password_life_time unlimited; exit EOF if [ $? != 0 ]; then errorExit 'Unable to Create User Grant permission for database' fi return 0 } #----------------------------------------------------------------------------------------------- # Create or replace directory replace(){ su - oracle -c "mkdir -p /data/dbbackup" su - oracle -c "export ORACLE_SID=${ORACLE_SID} && ${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF connect / as sysdba create or replace directory dir_dump as '/data/dbbackup'; grant read,write on directory dir_dump to nba; exit EOF if [ $? != 0 ]; then errorExit 'Unable to create or replace directory for database' fi return 0 } tempspace && displayheader "Create temp_tablespace successful" || errorExit 'Failed to prepare system' sleep 5 dataspace && displayheader "Create data_tablespace successful" || errorExit 'Failed to system' sleep 5 grant && displayheader "Create User Grant permission successful" || errorExit 'Failed to system' sleep 5 replace && displayheader "Create or replace directory successful" || errorExit 'Failed to system' sleep 5
#常见的操作
create temporary tablespace auctionent_temp #创建临时表空间 tempfile '/u01/oracle/oradata/qzing/auctionent_temp.dbf' #指定临时表空间的路径 size 64m #大小64M autoextend on #自动增大 next 64m maxsize unlimited #每次以64M大小自动增大,最大不限制 extent management local; #表空间采用本地表空间管理
create user auctionent identified by auctionent888 default tablespace auctionent_data temporary tablespace auctionent_temp; #以上3行为2个表空间创建用户和密码 grant connect,resource to auctionent; grant create view to auctionent; grant create public synonym to auctionent; grant drop public synonym to auctionent; grant unlimited tablespace to auctionent; #以上5行为用户授权 alter profile default limit password_life_time unlimited; #设置密码永不过期
#创建备份目录并授权 mkdir -p /u01/app/oracle/backup grant connect,dba to nba; create or replace directory dir_dump as '/u01/app/oracle/backup'; grant read,write on directory dir_dump to nba; --创建backup目录 --授权用户nba之dba权限 --该语句是将目录dir_dump和/u01/oracle/oradata/backup映射起来,所以一定要有backup目录 --授权用户nba读写目录dir_dump文件权限 #查询授权目录 select * from dba_directories; --------------- DIR_DUMP /u01/app/oracle/backup ---------------
在不同的服务之间导入导出数据库 #导出 su -l oracle -c "expdp platform/platform888@qzing schemas=platform dumpfile=platform`date +%Y-%m-%d`.dmp directory=dir_dump" #导入 su -l oracle -c "impdp platform/platform888@platform DUMPFILE=platform2021-12-07.dmp schemas=platform DIRECTORY=dir_dump EXCLUDE=STATISTICS"
#修改system 密码,本示例Oracle12c为例 sqlplus /nolog conn /as sysdba alter user system identified by newpasswd;
#先关闭服务并在restrict模式下运行 SQL> shutdown immediate; SQL> startup restrict; PS:执行删除命令前,否则可能会提示该此账号和数据库存在连接 #删除用户(CASCADE 的意思是将用户的数据库数据一并删除,并没有删除相应的表空间!) SQL> drop user cba cascade; User dropped. #删除临时表空间(包含物理文件) SQL> drop tablespace cba_temp including contents and datafiles; Tablespace dropped. #删除数据表空间(包含物理文件) SQL> drop tablespace cba_data including contents and datafiles; Tablespace dropped. #提交 SQL> commit; Commit complete. #关闭并启动 shutdown immediate; startup;
方式二,容器安装
docker run -d -p 8080:8080 -p 1521:1521 --name oracle12c truevoly/oracle-12c hostname: localhost port: 1521 sid: xe service name: xe username: system password: oracle
PS:
#查看字符集 SELECT * FROM Nls_Database_Parameters; #oracle12C使用命令行删除数据库 export ORACLE_SID=platform sqlplus / as sysdba; shutdown immediate; startup mount; alter system enable restricted session; drop database; 将/etc/oratab里面对应的记录注释或者删除掉
优化连接数
增加oracle数据库最大连接数
1,查看当前会话数
select count(*) from v$session;
2,查看数据库最大进程数
show parameter processes;
3,查看数据库最大会话数
show parameter sessions;
4,修改processes和sessions值
SQL> alter system set processes=300 scope=spfile;
系统已更改。
SQL> alter system set sessions=300 scope=spfile;
系统已更改。
注:一般只执行第一个命令就可以,session自动更改
5,创建pfile
SQL>create pfile from spfile;
注:如果不做此步,可能会导致更改最大连接数之后数据库不能启动现象
6,重启数据库,使更改生效
SQL> shutdown immediate
SQL> startup
注:shutdown normal正常关闭数据库可能会相当相当的慢呢
shutdown abort 可能会导致启动数据库时很慢。
7,查看进程数,会话数,已经修改过来了