1、可以在虛擬機或者服務器上安裝centos,具體過程省略,建議使用最小化安裝
以root用戶登錄centos,安裝vim、unzip、lrzsz、wget包
yum install vim -y
yum install unzip -y
yum install lrzsz -y
yum install wget -y
2、更新centos內核到最新版本並更換yum源為aliyun源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum update
3、通過rz命令上傳oracle11gR2,並解壓縮
[root@CentOS ~]#
cd /tmp
[root@CentOS tmp]#
unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip
等待解壓完成后,會在
/tmp
目錄下生產一個
database
文件夾,里面就
Oracle 11g
安裝文件。
4、在/etc/hosts文件中添加主機名
[root@CentOS tmp]# vim /etc/hosts
添加
192.168.206.135 CentOS
[root@CentOS tmp]# vim /etc/sysconfig/network
添加
NETWORKING=yes
HOSTNAME=CentOS
[root@CentOS tmp]# hostname CentOS
5、關閉selinux和firewalld
[root@CentOS tmp]# vim /etc/selinux/config
設置
SELINUX=disabled
[root@CentOS tmp]# reboot
[root@CentOS tmp]# service iptables stop
[root@CentOS ~]# systemctl stop firewalld
[root@CentOS ~]# systemctl disable firewalld
6、安裝Oracle 11g依賴包
[root@CentOS tmp]# yum install gcc make binutils gcc-c++ compat-libstdc++-33 elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel
7、添加安裝用戶和用戶組
[root@CentOS tmp]# groupadd oinstall
[root@CentOS tmp]# groupadd dba
[root@CentOS tmp]# useradd -g oinstall -G dba oracle
[root@CentOS tmp]# passwd oracle
[root@CentOS tmp]# id oracle
uid=1001(oracle) gid=1001(oinstall)
組
=1001(oinstall),1002(dba)
8、修改內核參數配置文件
[root@CentOS ~]# vim /etc/sysctl.conf
添加以下內容
fs.aio-max-nr = 1048576
fs.file-max = 6815744
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 = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
[root@CentOS ~]# /sbin/sysctl –p
其中
kernel.shmmax =
2147483648
為本機物理內存(4
G
)的一半,單位為
byte
。
9、修改用戶的限制文件
[root@CentOS ~]# vim /etc/security/limits.conf
添加以下內容
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
修改
/etc/pam.d/login
文件:
[root@CentOS ~]# vim /etc/pam.d/login
添加以下內容:
session required /lib64/security/pam_limits.so
session required pam_limits.so
修改
/etc/profile
文件:
[root@CentOS ~]# vim /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
[root@CentOS ~]# source /etc/profile
10、創建安裝目錄和設置文件權限
[root@CentOS ~]# mkdir -p /u01/app/oracle/product/11.2.0
[root@CentOS ~]# mkdir /u01/app/oracle/oradata
[root@CentOS ~]# mkdir /u01/app/oracle/inventory
[root@CentOS ~]# mkdir /u01/app/oracle/fast_recovery_area
[root@CentOS ~]# chown -R oracle:oinstall /u01/app/oracle
[root@CentOS ~]# chmod -R 775 /u01/app/oracle
11、設置oracle用戶環境變量
[root@CentOS ~]# su - oracle
[oracle@CentOS ~]$ vim .bash_profile
添加如下內容:
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_UNQNAME=$ORACLE_SID
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
[oracle@CentOS ~]$ source .bash_profile
12、編輯靜默安裝響應文件
oracle@CentOS ~]$ cp -R /tmp/database/response/ .
[oracle@CentOS ~]$ cd response/
[oracle@CentOS response]$ vim db_install.rsp
需要設置的選項如下:
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=CentOS
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/u01/app/oracle/product/11.2.0
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
13、根據響應文件靜默安裝Oracle 11g
[oracle@CentOS response]$ cd /tmp/database/
[oracle@CentOS database]$ ./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq
開始
Oracle
在后台靜默安裝。安裝過程中,如果提示
[WARNING]
不必理會,此時安裝程序仍在后台進行,如果出現
[FATAL]
,則安裝程序已經停止了。
可以在以下位置找到本次安裝會話的日志
:
/u01/app/oracle/inventory/logs/installActions2015-06-08_04-00-25PM.log
可以切換終端執行
top
命令查看后台進程一直是在安裝的,
/data
目錄也在不斷增大,
當出現以下提示時,代表安裝成功:
按照要求執行腳本。
打開終端,以
root
身份登錄,執行腳本:
[root@CentOS ~]# sh /u01/app/oracle/inventory/orainstRoot.sh
[root@CentOS ~]# sh /u01/app/oracle/product/11.2.0/root.sh
14、以靜默方式配置監聽
重新使用oracle用戶登錄
[oracle@CentOS ~]$ netca /silent /responsefile /home/oracle/response/netca.rsp
成功運行后,在
/u01/app/oracle/product/11.2.0/network/admin/
中生成
listener.ora
和
sqlnet.ora
通過
netstat
命令可以查看
1521
端口正在監聽。
Yum
安裝
netstat
軟件,軟件包是在
net-tools
中。
[root@CentOS ~]# yum install net-tools
[root@CentOS ~]# netstat -tnulp | grep 1521
15、以靜默方式建立新庫,同時也建立一個對應的實例。
[oracle@CentOS ~]$ vim /home/oracle/response/dbca.rsp
設置以下參數:
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/u01/app/oracle/oradata
RECOVERYAREADESTINATION=/u01/app/oracle/fast_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = "3277"
其中TOTALMEMORY = "3277"為3277 MB,物理內存4G*80%。
進行靜默配置:
[oracle@CentOS ~]$ dbca -silent -responseFile /home/oracle/response/dbca.rsp
建庫后進行實例進程檢查:
[oracle@CentOS ~]$ ps -ef | grep ora_ | grep -v grep
查看監聽狀態:
[oracle@CentOS ~]$ lsnrctl status
登錄查看實例狀態:
[oracle@CentOS ~]$ sqlplus / as sysdba
SQL> select status from v$instance;
16、Oracle開機自啟動設置
1、修改/u01/app/oracle/product/11.2.0/bin/dbstart
[oracle@CentOS ~]$ vim /u01/app/oracle/product/11.2.0/bin/dbstart
將ORACLE_HOME_LISTNER=$1修改為ORACLE_HOME_LISTNER=$ORACLE_HOME
2、修改/u01/app/oracle/product/11.2.0/bin/dbshut
[oracle@CentOS ~]$ vim /u01/app/oracle/product/11.2.0/bin/dbshut
將ORACLE_HOME_LISTNER=$1修改為ORACLE_HOME_LISTNER=$ORACLE_HOME
3、修改/etc/oratab文件
[oracle@CentOS ~]$ vim /etc/oratab
將orcl:/u01/app/oracle/product/11.2.0:N中最后的N改為Y,成為orcl:/u01/app/oracle/product/11.2.0:Y
4、輸入命令dbshut和dbstart測試
[oracle@CentOS ~]$ dbshut

Oracle
監聽停止,進程消失。
[oracle@CentOS ~]$ dbstart
Oracle
監聽啟動,進程啟動。
- 切換到root賬戶建立自啟動腳本
[oracle@CentOS ~]$ su -
[root@CentOS ~]# vim /etc/rc.d/init.d/oracle
添加以下內容(有些值如ORACLE_HOME和ORACLE_USER等根據實際情況可以修改):
#!/bin/bash
# oracle: Start/Stop Oracle Database 11g R2
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0
ORACLE_USER=oracle
case "$1" in
'start')
if [ -f $LOCKFILE ]; then
echo $0 already running.
exit 1
fi
echo -n $"Starting Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch $LOCKFILE
;;
'stop')
if [ ! -f $LOCKFILE ]; then
echo $0 already stopping.
exit 1
fi
echo -n $"Stopping Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f $LOCKFILE
;;
'restart')
$0 stop
$0 start
;;
'status')
if [ -f $LOCKFILE ]; then
echo $0 started.
else
echo $0 stopped.
fi
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
esac
exit 0
- 修改/etc/init.d/oracle服務文件權限
[root@CentOS init.d]# chmod 755 /etc/init.d/oracle
- 設置為開機啟動
[root@CentOS ~]# chkconfig oracle on
8、進行service oracle start/stop/restart測試

9、Reboot重啟查看Oracle監聽和實例進程均能自動啟動。
17、啟動em
1、刪除早期DBCONSOLE創建的用戶:
- sql>drop role MGMT_USER;
- sql>drop user MGMT_VIEW cascade;
- sql>drop user sysman cascade;
2、刪除早期DBCONSOLE創建的對象:
- sql>drop PUBLIC SYNONYM MGMT_TARGET_BLACKOUTS;
- sql>drop public synonym SETEMVIEWUSERCONTEXT;
3、重新創建DBCONSOLE:
$emca -config dbcontrol db -repos create
4、如果提示創建失敗,輸出類似 “Could not complete the configuration. Refer to the log file at /opt/oracle/cfgtoollogs/emca/orcl/emca_*.log for more details.” 的錯誤信息,請查看對應的日志文件, 日志文件的最后一行內容如果是 “ORA-00955: name is already used by an existing object”,則需要執行一次重建的命令:
$emca -config dbcontrol db -repos recreate
在執行上面命令的過程中需要根據提示輸入對應的數據庫信息及 SYS、DBSNMP 和 SYSMAN 的登錄密碼,最后輸入 Y 進行確認,如:
STARTED EMCA at Mar 10, 2015 10:03:17 PM
EM Configuration Assistant, Version 11.2.0.0.2 Production
Copyright (c) 2003, 2005, Oracle. All rights reserved.
Enter the following information:
Database SID: orcl
Listener port number: 1521
Listener ORACLE_HOME [ /opt/oracle/11g ]:
Password for SYS user:
Password for DBSNMP user:
Password for SYSMAN user:
Email address for notifications (optional):
Outgoing Mail (SMTP) server for notifications (optional):
5、檢查 em 的狀態
$ emctl status dbconsole
Oracle Enterprise Manager 11g Database Control Release 11.2.0.1.0
Copyright (c) 1996, 2009 Oracle Corporation. All rights reserved.
https:
Oracle Enterprise Manager 11g is running.
------------------------------------------------------------------
Logs are generated in directory /opt/oracle/11g/hemw-pc_orcl/sysman/log
導出用戶數據庫數據:(需要用oracle用戶)
exp system/systempwd@ORCL owner=system file=abcd.dmp