一、修改配置文件
1.1、修改/etc/security/limits.conf文件,修改用戶的SHELL的限制。
輸入命令:vi /etc/security/limits.conf,將下列內容加入該文件
oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536
1.2、修改/etc/pam.d/login 文件。
輸入命令:vi /etc/pam.d/login,將下列內容加入該文件
session required /lib/security/pam_limits.so
session required pam_limits.so
1.3、修改linux內核,修改/etc/sysctl.conf文件。
輸入命令: vi /etc/sysctl.conf ,將下列內容加入該文件。
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
並用#符號注釋掉原有的配置。
# Controls the maximum shared segment size, in bytes
#kernel.shmmax = 68719476736
# Controls the maximum number of shared memory segments, in pages
#kernel.shmall = 4294967296
輸入命令:sysctl -p,使/etc/sysctl.conf配置文件立即生效。
1.4、修改/etc/profile。
輸入命令:vi /etc/profile,將下列內容加入該文件。
if [ $USER = "oracle" ]; then if [ $SHELL = "/bin/ksh" ]; then ulimit -p 16384 ulimit -n 65536 else ulimit -u 16384 -n 65536 fi fi
1.5、創建用戶和組。
創建用戶組oinstall、dba
創建oracle用戶,主組為oinstall,副組dba,輸入命令:
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba -m oracle
副組的參數是大寫G,別弄錯,否則安裝時會出現錯誤:
[FATAL] [INS-35341] User is not a member of the following chosen OS groups
設置用戶oracle密碼,輸入兩次密碼,輸入命令:
passwd oracle
1.6、創建數據庫軟件目錄和數據文件存放目錄。
mkdir /home/oracle/app mkdir /home/oracle/app/oracle mkdir /home/oracle/app/oradata mkdir /home/oracle/app/oraInventory mkdir /home/oracle/app/fast_recovery_area mkdir /home/oracle/app/oracle/product
修改目錄權限,更改目錄屬主為Oracle用戶所有,輸入命令:
chown -R oracle:oinstall /home/oracle/app
1.7、配置oracle用戶的環境變量。
用命令su - oracle切換到oracle用戶下。
su - oracle
輸入命令:vi .bash_profile,將下列內容加入該文件。
umask 022 export ORACLE_BASE=/home/oracle/app export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1 export ORACLE_SID=orcl export PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
1.8、上傳Oracle安裝文件
上傳Oracle安裝文件到Linux服務器。
linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip
上傳到/tmp目錄下面。
1.9、解壓安裝文件
進入tmp目錄,使用unzip命令解壓文件。
[root@localhost /]# cd /tmp [root@localhost tmp]# unzip linux.x64_11gR2_database_1of2.zip [root@localhost tmp]# unzip linux.x64_11gR2_database_2of2.zip
解壓完成后,在tmp目錄下會有一個database的文件夾。
1.10、創建/etc/oraInst.loc文件,否則安裝時會報錯:
SEVERE: [FATAL] [INS-32038] The operating system group specified for central inventory (oraInventory) ownership is invalid.
vi /etc/oraInst.loc inventory_loc=/home/oracle/app/oraInventory inst_group=oinstall
1.11、安裝未安裝的package
yum install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel
二、安裝Oracle 11.2產品
Oracle支持靜默安裝。在我看來,它主要有兩方面的好處:一、極大地提升了效率,尤其是批量安裝。二、很多時候,只有終端環境可供使用。
2.0、准備responseFile文件
從Oracle軟件中獲取文件模板
[root@localhost tmp]# cd database/response/ [root@localhost response]# ls dbca.rsp db_install.rsp netca.rsp
其中database是Oracle軟件解壓后生成的目錄。可見在response目錄下有三個模板,其中dbca.rsp是用來創建數據庫的。db_install.rsp是用來安裝Oracle軟件的。netca.rsp是用來創建監聽器的。當然也可在db_install.rsp中直接創建數據庫。在這里,為求方便,我們選擇db_install.rsp模板一並安裝軟件,創建數據庫。
2.1、編輯responseFile文件
[root@localhost response]# vi db_install.rsp [root@localhost response]# grep -Ev "^$|^#" db_install.rsp oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0 oracle.install.option=INSTALL_DB_AND_CONFIG ORACLE_HOSTNAME=oracle UNIX_GROUP_NAME=oinstall INVENTORY_LOCATION=/home/oracle/app/oraInventory SELECTED_LANGUAGES=en,zh_CN ORACLE_HOME=/home/oracle/app/oracle/product/11.2.0/dbhome_1 ORACLE_BASE=/home/oracle/app oracle.install.db.InstallEdition=EE oracle.install.db.isCustomInstall=false 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 oracle.install.db.DBA_GROUP=dba oracle.install.db.OPER_GROUP=oinstall oracle.install.db.CLUSTER_NODES= oracle.install.db.config.starterdb.type=GENERAL_PURPOSE oracle.install.db.config.starterdb.globalDBName=orcl oracle.install.db.config.starterdb.SID=orcl oracle.install.db.config.starterdb.characterSet=AL32UTF8 oracle.install.db.config.starterdb.memoryOption=true oracle.install.db.config.starterdb.memoryLimit=400 oracle.install.db.config.starterdb.installExampleSchemas=false oracle.install.db.config.starterdb.enableSecuritySettings=true oracle.install.db.config.starterdb.password.ALL=1Password oracle.install.db.config.starterdb.password.SYS= oracle.install.db.config.starterdb.password.SYSTEM= oracle.install.db.config.starterdb.password.SYSMAN= oracle.install.db.config.starterdb.password.DBSNMP= oracle.install.db.config.starterdb.control=DB_CONTROL oracle.install.db.config.starterdb.gridcontrol.gridControlServiceURL= oracle.install.db.config.starterdb.dbcontrol.enableEmailNotification=false oracle.install.db.config.starterdb.dbcontrol.emailAddress=xxxx@xxxx.com oracle.install.db.config.starterdb.dbcontrol.SMTPServer= oracle.install.db.config.starterdb.automatedBackup.enable=false oracle.install.db.config.starterdb.automatedBackup.osuid= oracle.install.db.config.starterdb.automatedBackup.ospwd= oracle.install.db.config.starterdb.storageType=FILE_SYSTEM_STORAGE oracle.install.db.config.starterdb.fileSystemStorage.dataLocation=/home/oracle/app/oradata oracle.install.db.config.starterdb.fileSystemStorage.recoveryLocation=/home/oracle/app/fast_recovery_area 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=
2.3 改用oracle用戶登錄,靜默安裝
cd /tmp/database
./runInstaller -silent -ignorePrereq -responseFile /tmp/database/response/db_install.rsp
可以通過查看日志文件,來知曉安裝進度。
如果是測試環境的VM可能會出現tmpfs比MEMORY_TARGET小,導致oracle沒辦法起來。ORA-00845: MEMORY_TARGET not supported on this system。
mount -o remount,size=4G /dev/shm
2.4、啟動數據庫:
[oracle@oracle ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.1.0 Production on Wed Dec 6 09:14:24 2017 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to an idle instance. SQL> start SP2-1506: START, @ or @@ command has no arguments SQL> startup
查看監聽器狀態:
lsnrctl status
2.5、修改Oracle啟動配置文件:
[root@oracle admin]# vi /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:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y
為了讓oracle在系統啟動時服務自動啟動,修改/etc/rc/loacl文件:
[root@oracle admin]# vi /etc/rc.local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local su - oracle -c "/home/oracle/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"
2.6、打開防火牆端口:
輸入命令:vi /etc/sysconfig/iptables編輯防火牆配置:
2.7、創建表空間:
創建臨時表空間:
create temporary tablespace user_temp tempfile '/home/oracle/app/oradata/orcl/user_temp.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;
創建數據表空間:
create tablespace user_data logging datafile '/home/oracle/app/oradata/orcl/user_data.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;
創建用戶並指定表空間:
SQL> create user mydbuser identified by myDbuser1 default tablespace user_data temporary tablespace user_temp; User created. SQL> grant connect,resource to mydbuser; Grant succeeded.