一、安装
必须配置固定IP地址
1、系统需求
硬件需求:内存2G,SWAP4G ,磁盘空间大于8G,TMP大于1G
软件需求:
yum install elfutils-libelf-devel gcc gcc-c++ libaio-devel sysstat unixODBC unixODBC-devel compat-libstdc++-33-3.2.3 -y
rpm -ivh pdksh-5.2.14-36.el5.i386.rpm
用户环境:
groupadd oinstall&&groupadd dba&&useradd -g oinstall -G dba oracle
passwd oracle
mkdir /opt/oracle&&chown -R oracle:oinstall /opt/&&chmod -R 775 /opt
[[email protected] ~]# vim ~oracle/.bash_profile
……
ORACLE_BASE=/opt
ORACLE_HOME=$ORACLE_BASE/oracle
ORACLE_OWNER=oracle
ORACLE_TERM=xterm
ORACLE_SID=orcl
PATH=$ORACLE_HOME/bin:$PATH:$HOME/bin
LANG=zh_CN.UTF-8
export ORACLE_BASE ORACLE_HOME LANG ORACLE_OWNER ORACLE_TERM ORACLE_SID PATH
内核要求:
vim /etc/sysctl.conf
fs.aio-max-nr = 1048576
fs.file-max = 6815744
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 = 1048586
sysctl -p
会话要求:
vim /etc/pam.d/login
session required pam_limits.so
vim /etc/security/limits.conf
oracle soft nproc 8192
oracle hard nproc 16384
oracle soft nofile 32768
oracle hard nofile 65536
reboot 以ORACLE用户登录
二、ORACLE安装
mkdir /opt/sourcedb
cp -rv /misc/cd/* /opt/sourcedb
cd /opt/sourcedb
./runInstaller -jreLoc /usr/lib/jvm/jre-1.6.0
如果提示网络配置助手(net configuration assistant)出错,
关闭安装程序,删除产品清单目录,重新安装。
rm -rf /opt/oracle/oraInventory/
三、ORACLE配置
1、运行dbstart时启动数据库实例
vim /etc/oratab
orcl:/opt/oracle:Y
2、启动ORACLE数据库
ORACLE侦听器:lsnrctl status/start/stop
ORACLE企业管理器:emctl start/stop/status dbconsole
启动关闭ORACLE数据库:
dbstart/dbshut
vim /opt/oracle/bin/dbstart
把ORACLE_HOME_LISTNER=$1替换为ORACLE_HOME_LISTNER=$ORACLE_HOME
vim /opt/oracle/bin/dbshut
把ORACLE_HOME_LISTNER=$1替换为ORACLE_HOME_LISTNER=$ORACLE_HOME
3、为避免手动启动ORACLE数据库,需将ORACLE注册为系统服务
vim /root/oracled
#!/bin/bash
# chkconfig: 35 88 99
# description: Oracle Database Service Daemon.
ORACLE_BASE="/opt"
ORACLE_HOME=$ORACLE_BASE/oracle
ORACLE_OWNER=oracle
case "$1" in
start)
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl start" #//启用监听器
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME" #//启用数据库
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl start dbconsole" #//启用OEM
;;
stop)
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/emctl stop dbconsole" #//停止OEM
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/dbshut $ORACLE_HOME" #//停止数据库
su - $ORACLE_OWNER -c "$ORACLE_HOME/bin/lsnrctl stop" #//停止监听器
;;
status)
if(pgrep "tnslsnr" && netstat -anpt | grep ":1521") &> /dev/null
then
echo "Oracle 11g Net Listener is running."
else
echo "Oracle 11g Net Listener is not running."
fi
if(netstat -anpt | grep ":1158" && netstat -anpt | grep ":5520") &> /dev/null
then
echo "Oracle 11g Enterprise Manager is running."
else
echo "Oracle 11g Enterprise Manager is not running."
fi
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit 0
chmod o+x /root/oracled
cp /root/oracled /etc/init.d
chkconfig --add oracled
chkconfig oracled on
reboot
四、ORACLE数据库的维护
1、登录及退出命令
sqlplus /nolog
conn /as sysdba
exit
2、用户操作命令
create user wcg identified by "123456";
grant connect,resource to wcg;
select * from all_users where username=‘WCG‘
alter user wcg identified by 654321;
drop user wcg cascade;
3、表操作命令
create table stu01(name char(16) not null primary key,password char(16) not null );
desc stu01
select table_name from all_tables where table_name=‘STU01‘;
drop table stu01;
4、记录操作命令
insert into stu01 values(‘wcg‘,‘123456‘);
DELETE FROM STU01 WHERE NAME=‘WCG‘;
UPDATE STU01 SET PASSWORD=‘000000‘ WHERE NAME=‘LY‘;
SELECT * FROM STU01;
5、数据库的备份与还原
a、环境准备
mkdir /opt/bakup&&chown -R oracle:oinstall /opt/bakup
CREATE DIRECTORY dmpdir AS ‘/opt/bakup‘;
GRANT all ON DIRECTORY dmpdir TO wcg;
b、备份
expdp wcg/123456 DIRECTORY=dmpdir DUMPFILE=wcg-20121010.dmp
c、还原
impdp wcg/123456 DIRECTORY=dmpdir DUMPFILE=wcg-20121010.dmp REUSE_DATAFILES=Y TABLE_EXISTS_ACTION=REPLACE