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文件中添加主机名
- 在/etc/hosts文件中添加主机名
[root@CentOS tmp]# reboot[root@CentOS tmp]# service iptables stop[root@CentOS ~]# systemctl stop firewalld[root@CentOS ~]# systemctl disable firewalld6、安装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-devel7、添加安装用户和用户组[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 oracleuid=1001(oracle) gid=1001(oinstall) 组=1001(oinstall),1002(dba)8、修改内核参数配置文件[root@CentOS ~]# vim /etc/sysctl.conf添加以下内容fs.aio-max-nr = 1048576fs.file-max = 6815744kernel.shmall = 2097152kernel.shmmax = 2147483648kernel.shmmni = 4096kernel.sem = 250 32000 100 128net.ipv4.ip_local_port_range = 9000 65500net.core.rmem_default = 262144net.core.rmem_max = 4194304net.core.wmem_default = 262144net.core.wmem_max = 1048576[root@CentOS ~]# /sbin/sysctl –p其中kernel.shmmax = 2147483648 为本机物理内存(4G)的一半,单位为byte。9、修改用户的限制文件[root@CentOS ~]# vim /etc/security/limits.conf添加以下内容oracle soft nproc 2047oracle hard nproc 16384oracle soft nofile 1024oracle hard nofile 65536oracle soft stack 10240修改/etc/pam.d/login文件:[root@CentOS ~]# vim /etc/pam.d/login添加以下内容:session required /lib64/security/pam_limits.sosession 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 fifi[root@CentOS ~]# source /etc/profile10、创建安装目录和设置文件权限[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/oracle11、设置oracle用户环境变量[root@CentOS ~]# su - oracle[oracle@CentOS ~]$ vim .bash_profile添加如下内容:export ORACLE_BASE=/u01/app/oracleexport ORACLE_HOME=$ORACLE_BASE/product/11.2.0export ORACLE_SID=orclexport PATH=$PATH:$ORACLE_HOME/binexport ORACLE_UNQNAME=$ORACLE_SIDexport ORACLE_BASE ORACLE_HOME ORACLE_SID PATH[oracle@CentOS ~]$ source .bash_profile12、编辑静默安装响应文件oracle@CentOS ~]$ cp -R /tmp/database/response/ .[oracle@CentOS ~]$ cd response/[oracle@CentOS response]$ vim db_install.rsp需要设置的选项如下:oracle.install.option=INSTALL_DB_SWONLYORACLE_HOSTNAME=CentOSUNIX_GROUP_NAME=oinstallINVENTORY_LOCATION=/u01/app/oracle/inventorySELECTED_LANGUAGES=en,zh_CNORACLE_HOME=/u01/app/oracle/product/11.2.0ORACLE_BASE=/u01/app/oracleoracle.install.db.InstallEdition=EEoracle.install.db.DBA_GROUP=dbaoracle.install.db.OPER_GROUP=dbaDECLINE_SECURITY_UPDATES=true13、根据响应文件静默安装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 152115、以静默方式建立新库,同时也建立一个对应的实例。
[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 sysdbaSQL> 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账户建立自启动脚本
#!/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服务文件权限
- 设置为开机启动
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://hemw-pc:1158/em/console/aboutApplication
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