首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

Linux CentOS 6.4 Final 下安装 Oracle 11g R2 (11.2.0.3)

2013-03-25 
Linux CentOS 6.4 Final 上安装 Oracle 11g R2 (11.2.0.3)#-A INPUT -p tcp -m state --state NEW -m tcp

Linux CentOS 6.4 Final 上安装 Oracle 11g R2 (11.2.0.3)
#-A INPUT -p tcp -m state --state NEW -m tcp --dport 18030 -m comment --comment "Oracle EM"? -j ACCEPT
## 或者只接受内网地址连接
-A INPUT -s 127.0.0.1/32 -p tcp -m state --state NEW -m tcp --dport 1521 -m comment --comment "Oracle" -j ACCEPT
-A INPUT -s 192.168.0.0/16 -p tcp -m state --state NEW -m tcp --dport 1521 -m comment --comment "Oracle" -j ACCEPT
## 检查配置并启用、重启服务生效
chkconfig iptables on
service iptables restart
iptables -L


##########################################################################################
## Creating Required Operating System Groups and Users
## 创建组、用户、初始化,当存在多服务器(如备机或集群)安装时建议保持相同的uid和gid
##########################################################################################
#/usr/sbin/groupadd oinstall
#/usr/sbin/groupadd -g 502 dba
#/usr/sbin/groupadd -g 503 oper
#/usr/sbin/groupadd -g 504 asmadmin
#/usr/sbin/groupadd -g 506 asmdba
#/usr/sbin/groupadd -g 505 asmoper
#/usr/sbin/useradd -u 502 -g oinstall -G dba,asmdba,[oper] oracle
#/usr/sbin/usermod -g oinstall -G dba,asmdba[,oper] oracle
#/usr/sbin/userdel oracle; rm -fr /home/oracle; rm -fr /var/spool/mail/oracle
## 建议用户的home目录与安装基础目录分开
/usr/sbin/groupadd oinstall
/usr/sbin/groupadd dba
/usr/sbin/useradd -g oinstall -G dba -m -s /bin/bash -c "Oracle" oracle
/usr/bin/id oracle
# Specify the Global Database Name using the following syntax: database_name.domain
# database_name is the name of the database. It can contain no more than 30 characters (alphanumeric, underscore (_), dollar ($) , and pound (#)).
# NOTE!!! The first 8 characters of the name must be unique.
# domain is the domain used for the database. It can contain no more than 128 characters (alphanumeric, underscore (_), and pound (#)), inclusive of all periods.
# 当服务器存在多网卡或者多IP地址时,请设置用户环境变量: ORACLE_HOSTNAME (用户可访问地址)
## 安装前的环境变量配置如下,注意不要配置TNS_ADMIN等,不然安装可能不成功。
vi /home/oracle/.bash_profile
# .bash_profile
alias l='ls -altcr'
alias p='ps -ef | grep'
alias n='netstat -anp | grep'
set -o vi


umask 022
export DISPLAY=:1
export ORACLE_SID=gbk
export ORACLE_BASE=/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_HOME_NAME=OraDb11g_home1
export ORACLE_HOSTNAME=localhost
export ORACLE_UNQNAME=$ORACLE_SID
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"
export PATH=$PATH:$ORACLE_HOME/bin
unset TNS_ADMIN


##########################################################################################
## Configure Oracle Installation Owner Shell Limits
## 配置Oracle安装用户Shell限制
##########################################################################################
## 修改安全限制
# 1G=1048576, 5G=5242880, 12G=12582912, 25G=26214400
vi /etc/security/limits.conf
oracle?????????? soft??? memlock???????? 26214400
oracle?????????? hard??? memlock???????? 26214400
oracle?????????? soft??? nproc?????????? 2047
oracle?????????? hard??? nproc?????????? 16384
oracle?????????? soft??? nofile????????? 1024
oracle?????????? hard??? nofile????????? 65536
oracle?????????? hard??? stack?????????? 10240
# 注意需要重新登录oracle用户才可生效


##########################################################################################
## Configuring Kernel Parameters
## 配置操作系统核心参数
##########################################################################################
# shmall/shmmax: 1G=2097152/1073741824, 5G=10485760/5368709120, 12G=25165824/12884901888
vi /etc/sysctl.conf
#kernel.shmall = 7340032
#kernel.shmmax = 30064771072
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
fs.aio-max-nr = 1048576
fs.file-max = 6815744
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 = 1048586
net.ipv4.tcp_wmem = 262144 262144 262144
net.ipv4.tcp_rmem = 4194304 4194304 4194304
## 使修改立即生效(修改/etc/sysctl.conf永久生效)
/sbin/sysctl -p
## 确认修改是否生效
/sbin/sysctl -a | grep shm
/sbin/sysctl -a | grep sem
/sbin/sysctl -a | grep file-max
/sbin/sysctl -a | grep aio-max-nr
/sbin/sysctl -a | grep ip_local_port_range
/sbin/sysctl -a | grep rmem_default
/sbin/sysctl -a | grep rmem_max
/sbin/sysctl -a | grep wmem_default
/sbin/sysctl -a | grep wmem_max
/sbin/sysctl -a | grep tcp_wmem
/sbin/sysctl -a | grep tcp_rmem


##########################################################################################
## Identifying or Creating Required Software Directories
## 识别或创建软件安装目录
##########################################################################################
## Oracle安装目录分三大类如下:
## Oracle Base Directory, e.g. /u01/app/oracle, /u01/app/orauser, /opt/oracle/app/oracle
## Oracle Inventory Directory, e.g. /u01/app/oraInventory, /opt/oracle/oraInventory, /home/oracle/oraInventory
## Oracle Home Directory, Oracle recommends: oracle_base/product/11.2.0/dbhome_1
##########################################################################################
## 创建逻辑卷、数据库设备也使用文件系统
## pvdisplay??vgdisplay?lvdisplay
lvcreate -L 12G -n lv_oracle vg_db
lvcreate -L 32G -n lv_oradata vg_db


## 创建文件系统(Enterprise Linux 6 开始默认使用 mkfs.ext4,之前版本用mkfs.ext3)
mkfs.ext4 /dev/vg_db/lv_oracle
mkfs.ext4 /dev/vg_db/lv_oradata


## 初始化、人工挂接文件系统、以及编辑/etc/fstab使得自动挂接
cd /
mkdir oracle
mkdir oradata
mount /dev/vg_db/lv_oracle /oracle
mount /dev/vg_db/lv_oradata /oradata
vi /etc/fstab
/dev/mapper/vg_db-lv_oracle?/oracle??ext4?defaults?1 2
/dev/mapper/vg_db-lv_oradata?/oradata?ext4?defaults?1 2


## 修改属主和权限
chown -R oracle:oinstall /oracle
chown -R oracle:oinstall /oradata
chmod 775 /oracle
chmod 770 /oradata


## 扩充文件系统
umount /dev/vg_db/lv_oradata
lvextend -L 16G /dev/vg_db/lv_oradata
e2fsck -f /dev/vg_db/lv_oradata
resize2fs -p /dev/vg_db/lv_oradata
e2fsck -f /dev/vg_db/lv_oradata
mount /dev/vg_db/lv_oradata


## 收缩文件系统(注意丢失数据)
umount /dev/vg_db/lv_oradata
e2fsck -f /dev/vg_db/lv_oradata
resize2fs -p /dev/vg_db/lv_oradata 16G
lvreduce -L 16G /dev/vg_db/lv_oradata
e2fsck -f /dev/vg_db/lv_oradata
mount /dev/vg_db/lv_oradata

?

################################################################################
## Oracle 11g R2 Setup & Patch
################################################################################
## 查看当前Oracle进程
ps -ef | grep tnslsnr
## 查看默认Oracle侦听状态,后面可添加实际侦听名车参数,默认为 LISTENER
$ORACLE_HOME/bin/lsnrctl status
## 停止默认Oracle侦听,后面可添加实际侦听名车参数,默认为 LISTENER
$ORACLE_HOME/bin/lsnrctl stop
## su - root
cd /oracle
unzip /install/p10404530_112030_Linux-x86-64_1of7.zip
unzip /install/p10404530_112030_Linux-x86-64_2of7.zip
chown -R oracle:oinstall database
chmod 755 database


## 标准图形安装(注意:如果使用VNCSERVER,应注意启动X Server用户的一致性或权限。)
## 如果主机名按DNS标准命名且做了NAT,则在安装时建议先设置ORACLE_HOSTNAME=localhost
## 如果要以标准图形安装方式安装(推荐),则应配置正确的DISPLAY,并安装以下工具包:
yum install xorg-x11-utils


# 注:如果是直接在控制台安装,那么DISPLAY设置为“:0.0”,如果是通过VNC Server等X Server,
# 那么DISPLAY设置为相应的X-display,如“:1”,并且应注意启动X Server用户的一致性或权限。
vncserver -list


# 在设置正确 DISPLAY 后执行如下命令应该出现提示才正常:
# localhost being added to access control list
# oracle being added to access control list
xhost localhost oracle


# 如果网络足够安全,或者可以完全开放,没有任何主机和用户限制:
# access control disabled, clients can connect from any host
xhost +


## check setting
source .bash_profile
env | grep ora
echo $DISPLAY
echo $SHELL


su - oracle
cd /oracle/database
./runInstaller
## 一般Oracle安装了之后,会在/etc目录下存在以下两个文件: oraInst.loc, oratab
## 如果之前其它用户已经安装了Oracle版本, 则附加-invPtrLoc选项(UNIX only)
./runInstaller -invPtrLoc $ORACLE_BASE/oraInst.loc
####################################################################################################
## 录制静默安装,录制过程中选择只安装数据库软件不创建数据库,当安装界面到达最后一步时选择cancel
./runInstaller -record -destinationFile $ORACLE_BASE/db_install.rsp
## 可以在Windows环境下录制静默安装响应文件(不过没有尝试成功,无论是否指定-jreLoc选项还是使用rsp全路径)
setup -record -destinationFile $ORACLE_BASE/db_install.rsp
## 或者直接编制响应文件,模板在response子目录下: db_install.rsp, netca.rsp, dbca.rsp
cp response/db_install.rsp $ORACLE_BASE/db_install.rsp
vi $ORACLE_BASE/db_install.rsp
## default value: empty
## 若在静默安装时出现以下两行之一开始的错误,则编辑oraparam.ini文件,添加JRE_MEMORY_OPTIONS内容:
#(JDK 1.5): Exception in thread "main" java.lang.NoClassDefFoundError
#(JDK 1.6): Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit
vi install/oraparam.ini
## 在JRE_MEMORY_OPTIONS变量值中增加"-Djava.awt.headless=true"选项为("-mx150m"默认值不变)
JRE_MEMORY_OPTIONS=" -mx150m -Djava.awt.headless=true"
## 执行静默安装,安装完成后执行后面两个脚本(响应文件必须是绝对路径,并且大小写敏感)
./runInstaller -silent -responseFile $ORACLE_BASE/db_install.rsp oracle.install.db.config.starterdb.password.ALL=<password>
## Passwords may contain only alphanumeric characters from the chosen database character set, underscore (_), dollar sign ($), or pound sign (#).
## Oracle recommends that the ADMIN password entered should be at least 8 characters in length, contain at least 1 uppercase character, 1 lower case character and 1 digit [0-9].
## Clean and reinstall: rm -fr oraInst.loc product cfgtoollogs checkpoints; rm -fr /home/oracle/oraInventory
#!!! Last 实际执行命令
./runInstaller -ignorePrereq -invPtrLoc $ORACLE_BASE/oraInst.loc -silent -responseFile $ORACLE_BASE/db_install.rsp oracle.install.db.config.starterdb.password.ALL="<password>"
####################################################################################################
## 如果安装不成功,则最后会提示以下错误信息:
#? Then either from the log file or from installation manual find the appropriate configuration to meet the prerequisites and fix it manually.
# You can find the log of this install session at:
# /home/oracle/oraInventory/logs/installActions2011-08-14_10-26-41AM.log
## 没有启用ignorePrereq参数时,可以查看预检错误消息
more /home/oracle/oraInventory/logs/installActions2011-08-14_10-26-41AM.log | grep "Error Message:"
## 查看当前Oracle安装进程
ps -ef | grep oracle.installer
####################################################################################################
## 如果安装成功,则最后会出现如下信息:
The following configuration scripts need to be executed as the "root" user.
## 首先使用root用户执行以下语句
/home/oracle/oraInventory/orainstRoot.sh
## 使用 oracle 用户备份 root.sh
cp $ORACLE_HOME/root.sh $ORACLE_BASE
## 必须使用 root 用户运行 root.sh
$ORACLE_BASE/root.sh
## To start SQL*Plus and connect to the database from the command line:
# sqlplus {username | /} [as sysdba]
sqlplus / AS SYSDBA
# startup [force] [restrict] [pfile= FILENAME] [open [recover][ DATABASE] | mount | nomount]
STARTUP
SHUTDOWN
SHUTDOWN TRANSACTIONAL
SHUTDOWN IMMEDIATE
# 列出强制终止 oracle 进程时需要 kill 的主进程
ps -ef | grep ora_dbw0_$Oracle_SID
# 若在 STARTUP 时遇到“ORA-01012: not logged on”错误(或许是kill强制终止进程引起),先执行以下命令
SHUTDOWN ABORT
## 使用 oracle 用户运行 $ORACLE_HOME/rdbms/admin/utlrp.sql
sqlplus / AS SYSDBA
@?/rdbms/admin/utlrp.sql
## Oracle Net Listener Configuration
vi $ORACLE_HOME/network/admin/listener.ora
:%s/localhost/0.0.0.0/g
:wq!
## To view information about the listener at the command line
lsnrctl status
## To start or stop the listener at the command line
lsnrctl stop
lsnrctl start

?

####################################################################################################
## Automating Database Startup and Shutdown on Linux
####################################################################################################
## Once the instance is created, edit the "/etc/oratab" file setting the restart flag for each instance to 'Y'.
vi /etc/oratab
gbk:/oracle/product/11.2.0/dbhome_1:Y
## Next, create a file called "/etc/init.d/dbora" as the root user, containing the following.
vi /etc/init.d/dbora
#!--------------------------------------------------------------
#!/bin/sh
# chkconfig: 345 99 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.


ORA_HOME=/oracle/product/11.2.0/dbhome_1
ORA_OWNER=oracle


if [ ! -f $ORA_HOME/bin/dbstart ]
then
??? echo "Oracle startup: cannot start"
??? exit
fi


case "$1" in
??? 'start')
??????? # Start the Oracle databases:
??????? # The following command assumes that the oracle login
??????? # will not prompt the user for any values
??????? su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart $ORA_HOME"
??????? touch /var/lock/subsys/dbora
??????? ;;
??? 'stop')
??????? # Stop the Oracle databases:
??????? # The following command assumes that the oracle login
??????? # will not prompt the user for any values
??????? su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut $ORA_HOME"
??????? rm -f /var/lock/subsys/dbora
??????? ;;
esac
#!--------------------------------------------------------------
chmod 750 /etc/init.d/dbora
chkconfig --add dbora


####################################################################################################
## Configuring Database Control Using EMCA
####################################################################################################
## To configure Database Control with EMCA:
emca -config dbcontrol db -backup
## To view the status of the dbconsole process, run the following command:
emctl status dbconsole
## To start the dbconsole process, run the following command:
emctl start dbconsole
## To stop the dbconsole process, run the following command:
emctl stop dbconsole
## To access the Database Home page:
https://localhost:5500/em

热点排行