转:http://my.csdn.net/yangzhawen
oracle安装部分
1、检查下列包是否安装,若未安装则要先安装:
mount /dev/cdrom /mnt
cd /mnt/CentOS
rpm -Uvh binutils-2.*
rpm -Uvh compat-libstdc++-33*
rpm -Uvh compat-libstdc++-33*.i386.rpm
rpm -Uvh elfutils-libelf*
rpm -Uvh gcc-4.*
rpm -Uvh gcc-c++-4.*
rpm -Uvh glibc-2.*
rpm -Uvh glibc-common-2.*
rpm -Uvh glibc-devel-2.*
rpm -Uvh glibc-headers-2.*
rpm -Uvh ksh*
rpm -Uvh libaio-0.*
rpm -Uvh libaio-devel-0.*
rpm -Uvh libgomp-4.*
rpm -Uvh libgcc-4.*
rpm -Uvh libstdc++-4.*
rpm -Uvh libstdc++-devel-4.*
rpm -Uvh make-3.*
rpm -Uvh sysstat-7.*
rpm -Uvh numactl-devel-*
rpm -Uvh unixODBC-2.*
rpm -Uvh unixODBC-devel-2.*
---使用yum安装unixODBC
yum install unixODBC
yum install elfutils-libelf-devel
yum install pdksh
配置系统
[root@ora ~]# grep MemTotal /proc/meminfo
MemTotal: 4946772 kB
[root@ora ~]# grep SwapTotal /proc/meminfo
SwapTotal: 12289716 kB
[root@ora ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 17G 2.8G 14G 18% /
/dev/sda1 1012M 40M 921M 5% /boot
none 891M 0 891M 0% /dev/shm
/dev/hdc 192M 192M 0 100% /media/cdrom
参数修改
设置需要的IP
修改host文件
在/etc/hosts文件中添加一个全限定域名,如:
vi /etc/hosts
192.168.5.199 ocpyang.sz.com ocpyang
查看修改结果
hostname
cat /etc/hosts | grep `eval hostname`
设置核心参数
1、在/etc/sysctl.conf文件中加入下列行:
#vi /etc/sysctl.conf
fs.suid_dumpable = 1
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 2532755456
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
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=1048586
net.ipv4.ip_forward = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
运行下列命令改变核心参数:
#/sbin/sysctl -p
在/etc/security/limits.conf文件中加入下列行:
# vi /etc/security/limits.conf
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle hard stack 10240
在/etc/pam.d/login文件中加入下列行:
# vi /etc/pam.d/login
session required pam_limits.so
关闭SELINUX的工作模式和防火墙
# vi /etc/selinux/config
# 设置SELINUX为disabled
SELINUX=disabled
# service iptables stop
创建下列组和用户
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba,oper -d /home/oracle oracle
passwd oracle
创建安装oracle的目录
mkdir -p /u01
mkdir -p /u01/app/oracle/product/11.2.0/db_1
chown -R oracle.oinstall /u01
chmod -R 775 /u01
说明:/u01/app/oracle/product/11.2.0/db_1目录是用于放置程序文件的位置。
设置oracle用户的环境变量
用oracle登录在:/home/oracle/.bash_profile文件末尾,注意把其中ORACLE_SID换成自己的实例名:
# vi /home/oracle/.bash_profile
也可以
#su - oracle
#vi .bash_profile
增加下列内容:
# Oracle Settings
TMP=/tmp;
export TMP
TMPDIR=$TMP;
export TMPDIR
ORACLE_BASE=/u01/app/oracle;
export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1;
export ORACLE_HOME
ORACLE_SID=orcl;
export ORACLE_SID
ORACLE_TERM=xterm;
export ORACLE_TERM
PATH=/usr/sbin:$PATH;
export PATH
PATH=$ORACLE_HOME/bin:$PATH;
export PATH
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib;
export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib;
export CLASSPATH
#LD_ASSUME_KERNEL=2.4.1;
export LD_ASSUME_KERNEL
#set language
NLS_LANG="SIMPLIFIED CHINESE"_CHINA.AL32UTF8
export NLS_LANG
EDITOR=vi
export EDITOR
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
alias oratrace="cat $ORACLE_BASE/diag/rdbms/$ORACLE_SID/$ORACLE_SID/trace/alert_orcl.log"
alias oradata="cd $ORACLE_BASE/oradata/$ORACLE_SID"
alias oranetwork="cd $ORACLE_HOME/network/admin"
安装
$unzip 1.zip
$unzip 2.zip
$cd /soft/
chown -R oracle:oinstall /soft/database
$ cd database/
cp -R /soft/database/response /home/oracle
方法1:
$ ./runInstaller -silent -debug -force \
FROM_LOCATION=/soft/database/stage/products.xml \
oracle.install.option=INSTALL_DB_SWONLY \
ORACLE_HOSTNAME=ocpyang.sz.com \
UNIX_GROUP_NAME=oinstall \
INVENTORY_LOCATION=/u01/app/oraInventory \
SELECTED_LANGUAGES=en,zh_CN \
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1 \
ORACLE_BASE=/u01/app/oracle \
oracle.install.db.InstallEdition=EE \
oracle.install.db.EEOptionsSelection=false \
oracle.install.db.DBA_GROUP=dba \
oracle.install.db.OPER_GROUP=oper \
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE \
oracle.install.db.config.starterdb.memoryOption=false \
oracle.install.db.config.starterdb.installExampleSchemas=false \
oracle.install.db.config.starterdb.enableSecuritySettings=true \
oracle.install.db.config.starterdb.control=DB_CONTROL \
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false \
DECLINE_SECURITY_UPDATES=true \
oracle.installer.autoupdates.option=SKIP_UPDATES
方法2:
vi /home/oracle/ocp.rsp
oracle.install.responseFileVersion=/oracle/install/rspfmt_dbinstall_response_schema_v11_2_0
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=ocpyang.sz.com
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/app/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1
ORACLE_BASE=/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.EEOptionsSelection=false
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=oper
oracle.install.db.config.starterdb.type=GENERAL_PURPOSE
oracle.install.db.config.starterdb.memoryOption=false
oracle.install.db.config.starterdb.installExampleSchemas=false
oracle.install.db.config.starterdb.enableSecuritySettings=true
oracle.install.db.config.starterdb.control=DB_CONTROL
SECURITY_UPDATES_VIA_MYORACLESUPPORT=false
DECLINE_SECURITY_UPDATES=true
oracle.installer.autoupdates.option=SKIP_UPDATES
./runInstaller -ignoreSysPrereqs -force -silent -responseFile /home/oracle/response/ocp.rsp
[oracle@ocp ~]$ su -l root
Password:
#/u01/app/oraInventory/orainstRoot.sh
#/u01/app/oracle/product/11.2.0/db_1/root.sh
静默建库和静默配置监听:
—静默建库
$ cat /home/oracle/createdb.rsp
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
TEMPLATENAME = "General_Purpose.dbc"
SYSPASSWORD = "password"
SYSTEMPASSWORD = "password"
SYSMANPASSWORD = "password"
DBSNMPPASSWORD = "password"
DATAFILEDESTINATION ="/u01/app/oracle/oradata"
STORAGETYPE=FS
CHARACTERSET = "ZHS16GBK"
DATABASETYPE = "MULTIPURPOSE"
AUTOMATICMEMORYMANAGEMENT = "FALSE"
$ dbca -silent -responseFile /home/oracle/response/createdb.rsp
ps -ef | grep ora_ | grep -v grep | wc -l
—静默配置监听
$ $ORACLE_HOME/bin/netca /silent /responsefile /home/oracle/response/netca.rsp
$ ll $ORACLE_HOME/network/admin/*.ora
$ lsnrctl status
执行完后, 监听就已经启
安装后配置
修改oratab文件,在/etc/oratab文件中添加下面的一行,
vi /etc/oratab
orcl:/u01/app/oracle/product/11.2.0/db_1:Y
启动和停止 Oracle Enterprise Manager 数据库控制:
$ emctl start dbconsole
$ emctl stop dbconsole
启动和停止 iSQL*Plus:
$ isqlplusctl start
$ isqlplusctl stop
启动和停止监听器:
监听器接受客户端的连接请求,并在验证证书后创建数据库连接。要使用 OEM 或 iSQL*Plus,必须先启动监听器。
$ lsnrctl start
$ lsnrctl stop
$cat /u01/app/oracle/product/11.2.0/db_1/network/admin/listener.ora
启动和停止数据库:
启动:
$ sqlplus
SQL> startup
关闭:
$ sqlplus
SQL> shutdown immediate
设置开机oracle自动启动
步骤1:
# vi /etc/oratab
ORCL:/u01/app/oracle/product/10.2.0/db_1:Y
/etc/oratab格式为:SID:ORACLE_HOME:AUTO把AUTO域设置为Y(大写),只有这样,
oracle 自带的dbstart和dbshut才能够发挥作用
步骤2:使用Oracle用户修改$Oracle_HOME/bin/dbstart文件
$vi /u01/app/oracle/product/11.2.0/db_1/bin/dbstart
82行 ORACLE_HOME_LISTNER=$1
修改为
ORACLE_HOME_LISTNER=$ORACLE_HOME
步骤3:root新建oracle控制文件
#vi /etc/init.d/oracle11gr2
内容为oracle11gr2脚本
步骤4:让linux服务控制
# chmod 774 /etc/init.d/oracle11gr2
# chkconfig --add oracle11gr2
这样开机将随机启动。
同时也可以使用命令随时启动:
#service oracle11gr2 start
#service oracle11gr2 stop
#service oracle11gr2 restart
配置:(解决侦听失败,见文件)
安装完成后,第一次启动是没有问题的,但是,重启动计算机后,你必需通过手工或者脚本启动数据库。
1、手工启动数据库:以oracle用户执行dbstart,这个命令在我安装完成后,出现错误,我就把这个脚本修改了一下,
利用文本编辑器打开dbstart,
把78行的
vi /u01/app/oracle/product/11.2.0/db_1/bin/dbstart
ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle换成你自己的路径。
ORACLE_HOME_LISTNER=/u01/app/oracle/product/10.2.0/db_1/
关闭数据库用dbshut就可以了。
如果你需要使用isqlplus管理数据库,就要启动isqlplus,运行命令:isqlplusctl start | stop
要使用基于web的企业管理器,就要运行命令:emctl start | stop dbconsole
常见sql全局配置文件
vi /u01/app/oracle/product/11.2.0/db_1/sqlplus/admin/glogin.sql
--dba add for oracle
alter session set nls_date_format='YYYY-MM-DD HH24:MI:SS';
define _editor=vi
set serveroutput on size 1000000
set trimspool on
set long 5000
set linesize 100
set pagesize 9999
column plan_plus_exp format a80
column global_name new_value gname
set termout off
define gname=idle
column global_name new_value gname
select lower(user) || '@' || substr( global_name, 1,
decode( dot, 0, length(global_name), dot-1) ) global_name
from (select global_name, instr(global_name,'.') dot from global_name );
set time on
set sqlprompt '&gname>'