0. 操作系统
[root@HM311~]# uname -m
x86_64
[root@HM311~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
1. 安装前的准备
1.1 /etc/hosts文件中添加主机名
[root@HM311~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
113.33.26.198 HM311
127.0.0.1 HM311
1.2 关闭selinux
[root@HM311~]# vi /etc/selinux/config
SELINUX=disabled
SELINUXTYPE=targeted
1.3 关闭防火墙
[root@HM311~]# service iptables stop
[root@HM311~]# systemctl stop firewalld
[root@HM311~]# systemctl disable firewalld
1.4 用yum进行安装
-- 使用下面2个语句都可以 , 建议使用第一个
yum -y install gcc gcc-c++ make binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel elfutils-libelf-devel-static glibc glibc-common glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel numactl-devel sysstat unixODBC unixODBC-devel kernelheaders pdksh pcre-devel readline rlwrap
yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.devel compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686
==检测是否31个包都有安装==
[root@HM311~]# rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel
binutils-2.23.52.0.1-55.el7.x86_64
compat-libcap1-1.10-7.el7.x86_64
compat-libstdc++-33-3.2.3-72.el7.x86_64
compat-libstdc++-33-3.2.3-72.el7.i686
gcc-4.8.5-4.el7.x86_64
gcc-c++-4.8.5-4.el7.x86_64
glibc-2.17-106.el7_2.8.x86_64
glibc-2.17-106.el7_2.8.i686
glibc-devel-2.17-106.el7_2.8.x86_64
glibc-devel-2.17-106.el7_2.8.i686
ksh-20120801-22.el7_1.3.x86_64
libaio-0.3.109-13.el7.x86_64
libaio-0.3.109-13.el7.i686
libaio-devel-0.3.109-13.el7.x86_64
libaio-devel-0.3.109-13.el7.i686
libgcc-4.8.5-4.el7.x86_64
libgcc-4.8.5-4.el7.i686
libstdc++-4.8.5-4.el7.x86_64
libstdc++-4.8.5-4.el7.i686
libstdc++-devel-4.8.5-4.el7.x86_64
libstdc++-devel-4.8.5-4.el7.i686
libXi-1.7.2-2.1.el7.x86_64
libXi-1.7.4-2.el7.i686
libXtst-1.2.2-2.1.el7.x86_64
libXtst-1.2.2-2.1.el7.i686
make-3.82-21.el7.x86_64
sysstat-10.1.5-7.el7.x86_64
unixODBC-2.3.1-11.el7.x86_64
unixODBC-2.3.1-11.el7.i686
unixODBC-devel-2.3.1-11.el7.x86_64
unixODBC-devel-2.3.1-11.el7.i686
1.5 创建用户、组
groupadd oinstall && groupadd dba && useradd -g oinstall -G dba oracle
echo "123456" | passwd --stdin oracle && id oracle
1.6 上传软件包
[linux.x64_11gR2_database_1of2.zip]
[linux.x64_11gR2_database_2of2.zip]
可以下载到本地通过ftp上传到虚拟机中,也可以使用wget命令,下载到虚拟机中
1.7 修改内核参数
vim /etc/sysctl.conf
#添加以下内容
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
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
#使内核新配置生效
sysctl -p
1.8 修改用户限制
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
1.9 修改/etc/pam.d/login 文件
vim /etc/pam.d/login
#添加以下内容
session required /lib64/security/pam_limits.so
session required pam_limits.so
1.20 修改/etc/profile 文件
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
2. ORACLE 安装
2.1 创建安装包文件存放目录
mkdir -p /data/u01/software
mv linux.x64_11gR2_database_* /data/u01/software/ && cd /data/u01/software
2.2 解压安装包文件
unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip
2.3 创建目录
mkdir -p /data/u01/app/oracle/product/11.2.0/dbhome_1
mkdir /data/u01/app/oracle/{oradata,inventory,fast_recovery_area}
chown -R oracle:oinstall /data/u01/app/oracle
chmod -R 775 /data/u01/app/oracle
2.4 设置 oracle 用户环境变量
su - oracle
vim .bash_profile
#添加以下内容
export ORACLE_BASE=/data/u01/app/oracle
export ORACLE_HOME=/data/u01/app/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export ORACLE_UNQNAME=$ORACLE_SID
export PATH=$ORACLE_HOME/bin:$PATH
export NLS_LANG=american_america.AL32UTF8
#生效
source .bash_profile
2.5 编辑静默安装响应文件
cp -R /data/u01/software/database/response/ . && cd response/
vim db_install.rsp
#设置以下内容
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=自己的主机名
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/u01/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/data/u01/app/oracle/product/11.2.0/dbhome_1
ORACLE_BASE=/data/u01/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
2.6 安装
cd /data/u01/software/database/
./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq
等待几分钟
2.7 打开终端,以 root 身份登录,执行脚本
su - root
source .bash_profile
sh /data/u01/app/oracle/inventory/orainstRoot.sh
sh /data/u01/app/oracle/product/11.2.0/dbhome_1/root.sh
2.8 查看监听响应文件配置信息
egrep -v "(^#|^$)" /home/oracle/response/netca.rsp
#以静默方式配置监听
su - oracle
source .bash_profile
netca /silent /responsefile /home/oracle/response/netca.rsp
2.9 用Oracle用户启动
su - oracle
lsnrctl start
netstat -tunlp|grep 1521
#查看监听状态
lsnrctl status
#查看监听器配置文件 listener.ora
cat $ORACLE_HOME/network/admin/listener.ora
#查看监听服务名配置文件 tnsnames.ora
cat $ORACLE_HOME/network/admin/tnsnames.ora
2.10 配置以静默方式建立新库,和实例 的响应文件
vim /home/oracle/response/dbca.rsp
设置以下参数
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "SYS 用户密码"
SYSTEMPASSWORD = "SYSTEM 用户密码"
SYSMANPASSWORD = "sysman"
DBSNMPPASSWORD = "dbsnmp"
DATAFILEDESTINATION =/data/u01/app/oracle/oradata
RECOVERYAREADESTINATION=/data/u01/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "6144"
2.11 查看建库响应文件配置信息
root@oracle ~]# egrep -v "(^#|^$)" /home/oracle/response/dbca.rsp
2.12 启用配置,以静默方式建立新库,和实例
dbca -silent -responseFile /home/oracle/response/dbca.rsp
#查看监听器配置文件 listener.ora
cat $ORACLE_HOME/network/admin/listener.ora
# listener.ora Network Configuration File: /data/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = HM311)(PORT = 1521))
)
)
ADR_BASE_LISTENER = /data/u01/app/oracle
#查看监听服务名配置文件 tnsnames.ora
cat $ORACLE_HOME/network/admin/tnsnames.ora
# tnsnames.ora Network Configuration File: /data/u01/app/oracle/product/11.2.0/d bhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = HM311)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
2.13 检查实例后台进程
ps -ef | grep ora_ | grep -v grep
#查看 ORACLE_UNQNAME 环境变量
env|grep ORACLE_UNQNAME
以 sysdba 身份登录
sqlplus / as sysdba
启动 oralce 数据库
SQL> startup
3. 报错解决
3.1 ORA-00845
SQL> startup
ORA-00845: MEMORY_TARGET not supported on this system
因为内存太小可以加大虚拟机的内存或者临时解决如下:解决方法
su - root
mount -o remount,size=4G /dev/shm
su - oracle
lsnrctl stop
lsnrctl start
sqlplus / as sysdba
SQL> startup
3.2 ORA-28000
ORA-28000: the account is locked
解决方法
[oracle@oracal ~]$ sqlplus /nolog
SQL>conn /as sysdba
SQL> alter profile default limit failed_login_attempts unlimited;
sqlplus /nolog
sqlplus /nolog
3.3 ORA-01017
#ORA-01017: invalid username/password; logon denied
解决方法密码不合适 用sys用户登录修改密码
[oracle@oracal ~]$ sqlplus / as sysdba
SQL> conn / as sysdba;
SQL> alter user scott identified by 123456;
SQL> alter user scott account unlock;
SQL> conn scott/123456;
3.4 #[ConfigureListener.isPortFree:1088] Returning is Port 1521 free: false
#[ConfigureListener.isPortFree:1088] Returning is Port 1521 free: false
/etc/hosts里面127.0.0.0后面没有添加主机名
3.5 ORA-12547
oracle ORA-12547: TNS:lost contact
cd /db/app/oracle/product/11.2.0/bin/
chmod 6751 oracle
3.6 TNS-12555
TNS-12555: TNS:permission denied
cd /var/tmp
chown -R oracle:oinstall .oracle
---------------------
4. 设置Oracle开机启动
修改/data/app/oracle/product/11.2.0/bin/dbstart
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改/data/app/oracle/product/11.2.0/bin/dbshut
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改vi /etc/oratab
orcl:/data/app/oracle/product/11.2.0:Y
新建文件/etc/rc.d/init.d/oracle
#! /bin/bash
# oracle: Start/Stop Oracle Database 11g R2
#
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
#
# processname: oracle
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/data/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添加执行权限
chmod +x /etc/init.d/oracle
开机启动oracle
systemctl enable oracle
或
chkconfig oracle on
给启动文件加权限
cd /data/app/oracle/product/11.2.0/bin/
chmod 6751 oracle
cd /var/tmp
chown -R oracle:oinstall .oracle
防火墙配置放开Oracle的端口firewall-cmd --zone=public --add-port=1521/tcp --permanent firewall-cmd --reload