这次装好oracle参考了很多资料,其中经历了很多坑,所以专门记下来免得下次又去重复趟坑。
我用的Linux系统是CentOS7.6 Minimal,Oracle是11.2.0.1.0
注意:从Oracle 11g 11.2.0.2版本开始,在Linux x86_64上安装时,只需要安装64位的软件包,但是,对于11.2.0.2之前的任何Oracle database 11g,下表中列出的32位和64位的安装包都必须安装
需要安装的依赖包(版本号只能大于规定的版本,不能小于)
binutils-2.23.52.0.1-12.el7.x86_64
compat-libcap1-1.10-3.el7.x86_64
compat-libstdc++-33-3.2.3-71.el7.i686
compat-libstdc++-33-3.2.3-71.el7.x86_64
gcc-4.8.2-3.el7.x86_64
gcc-c++-4.8.2-3.el7.x86_64
glibc-2.17-36.el7.i686
glibc-2.17-36.el7.x86_64
glibc-devel-2.17-36.el7.i686
glibc-devel-2.17-36.el7.x86_64
ksh
libaio-0.3.109-9.el7.i686
libaio-0.3.109-9.el7.x86_64
libaio-devel-0.3.109-9.el7.i686
libaio-devel-0.3.109-9.el7.x86_64
libgcc-4.8.2-3.el7.i686
libgcc-4.8.2-3.el7.x86_64
libstdc++-4.8.2-3.el7.i686
libstdc++-4.8.2-3.el7.x86_64
libstdc++-devel-4.8.2-3.el7.i686
libstdc++-devel-4.8.2-3.el7.x86_64
libXi-1.7.2-1.el7.i686
libXi-1.7.2-1.el7.x86_64
libXtst-1.2.2-1.el7.i686
libXtst-1.2.2-1.el7.x86_64
make-3.82-19.el7.x86_64
sysstat-10.1.5-1.el7.x86_64
unixODBC-2.3.1-6.el7.i686
unixODBC-2.3.1-6.el7.x86_64
unixODBC-devel-2.3.1-6.el7.i686
unixODBC-devel-2.3.1-6.el7.x86_64
安装命令:
yum -y install 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
安装完,检查依赖是否安装成功
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 | grep "not installed"
如果要安装Oracle数据库,则需要以下本地操作系统组和用户:
groupadd oinstall
groupadd dba
groupadd oper
useradd -g oinstall -G dba oracle
修改oracle用户密码
passwd oracle
查看oracle用户
id oracle
vi /etc/sysctl.conf
在/etc/sysctl.conf
添加如下参数,如果系统中某个参数高于下面的参数的值 ,保留较大的值,下面的数值只是官方要求的最小值,可以根据系统调整数值,以优化系统性能
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.shmall = 2097152
kernel.shmmax = 2147483648
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
vi /etc/security/limits.conf
在/etc/security/limits.conf
中添加如下参数(直接cv在后面就行)
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
vi /etc/pam.d/login
在/etc/pam.d/login文件中,添加下面内容
session required /lib64/security/pam_limits.so
session required pam_limits.so
注意我装的CentOS是64位的所以路径是/lib64,32位的自己看看目录吧
vi /etc/profile
在/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
因为不知道该文件编写的语法,所以没有把它加在最后,把这段代码加在了done前面
使用/etc/profile
文件生效
source /etc/profile
如下目录,根据自己的实际情况可做修改
mkdir -p /data/app/
chown -R oracle:oinstall /data/app/
chmod -R 775 /data/app/
vi /home/oracle/.bash_profile
在文件/home/oracle/.bash_profile
里添加下面内容(具体值根据实际情况修改)
umask 022
export ORACLE_HOSTNAME=oracledb
export ORACLE_BASE=/data/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/
export ORACLE_SID=orcl
export PATH=.:$ORACLE_HOME/bin:$ORACLE_HOME/OPatch:$ORACLE_HOME/jdk/bin:$PATH
export LC_ALL="en_US"
export LANG="en_US"
export NLS_LANG="AMERICAN_AMERICA.ZHS16GBK"
export NLS_DATE_FORMAT="YYYY-MM-DD HH24:MI:SS"
加在后面就行,注意把主机名修改成自己的ORACLE_HOSTNAME=oracledb
source /home/oracle/.bash_profile#重载文件
vi /etc/hosts
在127.0.0.1那一行的最后加上自己的主机名
禁用使用Transparent HugePages(启用Transparent HugePages,可能会导致造成内存在运行时的延迟分配,Oracle官方建议使用标准的HugePages)
cat /sys/kernel/mm/transparent_hugepage/enabled
这样就说明没有禁用THP
vi /etc/rc.d/rc.local
保存退出,然后赋予rc.local文件执行权限:
chmod +x /etc/rc.d/rc.local
最后重启系统,以后再检查THP应该就是被禁用了
vi /etc/sysconfig/selinux
将SELINUX=enforcing 改为 SELINUX=disabled重启系统SELINUX就会被永久关闭
reboot#重启系统
cat /sys/kernel/mm/transparent_hugepage/enabled
说明THP已经禁用了
/usr/sbin/sestatus -v
说明SELINUX已经关闭了
安装上传文件的依赖
yum -y install lrzsz
安装解压和压缩的依赖
yum -y install unzip zip
cd /data#进入数据库目录
rz#上传数据库压缩包
unzip linux.x64_11gR2_database_1of2.zip -d /data#解压包1到data
unzip linux.x64_11gR2_database_2of2.zip -d /data#解压包2到data
上传解压压缩包已经完成,然后创建一个配置目录把/data/database/response/里的文件copy到配置目录里去
mkdir -p /data/etc
cp /data/database/response/* /data/etc/
在/data/etc/db_install.rsp
修改以下变量的值
vi /data/etc/db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=oinstall
ORACLE_HOSTNAME=lhk_oracle
INVENTORY_LOCATION=/data/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
一个一个找着慢慢改吧,ORACLE_HOSTNAME=lhk_oracle是自己的主机名
用oracle用户装oracle(oracle不支持root用户装)
su - oracle
cd /data/database
./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq
运行./runInstaller -silent -responseFile /data/etc/db_install.rsp -ignorePrereq指令后会出项一条
/data/app/oracle/inventory/logs/installActions2019-03-15_05-37-19PM.log
这样的提示,安装期间可以使用tail命令监看oracle的安装日志,来观察安装的过程(日志路径和名字就是那条提示)
#日志文件名称根据自己的实际执行时间变更
tail -f /data/app/oracle/inventory/logs/installActions2019-03-15_05-37-19PM.log
安装完成后有如下提示,如果有类似如下提示,说明安装完成
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run
/u01/app/oraInventory/orainstRoot.sh
/u01/app/oracle/product/11.2.0/db_1/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts
4. Return to this window and hit "Enter" key to continue
Successfully Setup Software.
但是我不知道我哪步错了,显示的这个
索性死马当成活马医进行下一步(Ctrl+c退出tail命令)
root
用户执行脚本su - root#换root用户
sh /data/app/oracle/inventory/orainstRoot.sh
sh /data/app/oracle/product/11.2.0/root.sh
正确的输出
su - oracle#换oracle用户
netca /silent /responsefile /data/etc/netca.rsp
如果出现
bash: netca: command not found
就检查第5步/home/oracle/.bash_profile文件是否配对
vi /home/oracle/.bash_profile
有可能是没有重新加载该文件
source /home/oracle/.bash_profile
然后再运行netca /silent /responsefile /data/etc/netca.rsp
#输出结果
[oracle@oracledb ~]$ netca /silent /responsefile /data/etc/netca.rsp
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /data/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/data/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
如果运行netca /silent /responsefile /data/etc/netca.rsp不是向上面这样的成功,注意看/home/hosts文件中是否加了你的主机名(详情在第5步),还有上面oracle配置文件中的主机名是否改成了你自己的主机名
查看监听端口
su root#切换到root用户安装依赖
yum -y install net-tools#安装依赖
su oracle#切换到oracle用户
netstat -tnpl | grep 1521#用安装的命令查端口号
编辑应答文件/data/etc/dbca.rsp
su root#切换到root用户
vi /data/etc/dbca.rsp
挨个找然后修改,别直接在后面加,有默认值直接加要出错
[GENERAL]
RESPONSEFILE_VERSION = "11.2.0"
OPERATION_TYPE = "createDatabase"
[CREATEDATABASE]
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/data/app/oracle/oradata
RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "1638"
执行静默建库
su oracle
dbca -silent -responseFile /data/etc/dbca.rsp
执行过程如下
[oracle@lhk_oracle database]$ dbca -silent -responseFile /data/etc/dbca.rsp
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
查看进程
ps -ef | grep ora_ | grep -v grep
[oracle@lhk_oracle database]$ ps -ef | grep ora_ | grep -v grep
oracle 17496 1 0 18:48 ? 00:00:00 ora_pmon_orcl
oracle 17498 1 0 18:48 ? 00:00:00 ora_vktm_orcl
oracle 17502 1 0 18:48 ? 00:00:00 ora_gen0_orcl
oracle 17504 1 0 18:48 ? 00:00:00 ora_diag_orcl
oracle 17506 1 0 18:48 ? 00:00:00 ora_dbrm_orcl
oracle 17508 1 0 18:48 ? 00:00:00 ora_psp0_orcl
oracle 17510 1 0 18:48 ? 00:00:00 ora_dia0_orcl
oracle 17512 1 0 18:48 ? 00:00:00 ora_mman_orcl
oracle 17514 1 0 18:48 ? 00:00:00 ora_dbw0_orcl
oracle 17516 1 0 18:48 ? 00:00:00 ora_lgwr_orcl
oracle 17518 1 0 18:48 ? 00:00:00 ora_ckpt_orcl
oracle 17520 1 0 18:48 ? 00:00:00 ora_smon_orcl
oracle 17522 1 0 18:48 ? 00:00:00 ora_reco_orcl
oracle 17524 1 0 18:48 ? 00:00:00 ora_mmon_orcl
oracle 17526 1 0 18:48 ? 00:00:00 ora_mmnl_orcl
oracle 17528 1 0 18:48 ? 00:00:00 ora_d000_orcl
oracle 17530 1 0 18:48 ? 00:00:00 ora_s000_orcl
oracle 17541 1 0 18:48 ? 00:00:00 ora_qmnc_orcl
oracle 17557 1 0 18:48 ? 00:00:00 ora_cjq0_orcl
oracle 17566 1 0 18:48 ? 00:00:00 ora_q000_orcl
oracle 17568 1 0 18:48 ? 00:00:00 ora_q001_orcl
查看监听状态
lsnrctl status
[oracle@lhk_oracle database]$ lsnrctl status
LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 15-MAR-2019 18:50:22
Copyright (c) 1991, 2009, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
Start Date 15-MAR-2019 17:55:11
Uptime 0 days 0 hr. 55 min. 10 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /data/app/oracle/product/11.2.0/network/admin/listener.ora
Listener Log File /data/app/oracle/diag/tnslsnr/lhk_oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521)))
Services Summary...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
su oracle#切换到oracle用户
sqlplus / as sysdba#进入数据库
select status from v$instance;#查数据库状态
执行select时,全出现以下情况
SQL> select status from v$instance;
select status from v$instance
*
ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0
解决方式:
startup
输入startup后出现以下结果
SQL> startup
ORA-01078: failure in processing system parameters
LRM-00109: could not open parameter file '/data/app/oracle/product/11.2.0/dbs/initORCL.ora'
exit#退出数据库
根据提示,将ORACLEBASE/admin/数据库名称/pfile目录下的init.ora.xxx形式的文件copy到ORACLE_HOME/dbs目录下initOracle.ora(根据startup提示)即可
首先先查看装数据库时生成的文件(根据你的安装目录来)
[oracle@lhk_oracle database]$ cd /data/app/oracle/admin/orcl/pfile/
[oracle@lhk_oracle pfile]$ ls
init.ora.2152019184812
然后把这个文件copy到startup指令提示的位置
su root#先切换到root用户,怕oracle用户没权限
cp /data/app/oracle/admin/orcl/pfile/init.ora.2152019184812 /data/app/oracle/product/11.2.0/dbs/initORCL.ora
最后再次startup
su oracle
sqlplus / as sysdba
startup
如果还是上面的错误,看看/home/oracle/.bash_profile里的ORACLE_SID、和你刚刚cp到/data/app/oracle/product/11.2.0/dbs/initORCL.ora里的db_name是不是一样(其实我也不太懂),总之把ORACLE_SID的值改成db_name的值就行了(注意大小写)
su root#切换到root用户
cat /home/oracle/.bash_profile
cat /data/app/oracle/product/11.2.0/dbs/initORCL.ora
然后重载/home/oracle/.bash_profile文件
source /home/oracle/.bash_profile
再次startup,出现
SQL> startup
ORACLE instance started.
Total System Global Area 1286066176 bytes
Fixed Size 2213016 bytes
Variable Size 352324456 bytes
Database Buffers 922746880 bytes
Redo Buffers 8781824 bytes
ORA-01102: cannot mount database in EXCLUSIVE mode
这是网上查找这个错误的资料:
A、在HA系统中,已经有其他节点启动了实例,将双机共享的资源(如磁盘阵列上的裸设备)占用了;
B、说明Oracle被异常关闭时,有资源没有被释放,一般有以下几种可能,
a、 Oracle的共享内存段或信号量没有被释放;
b、 Oracle的后台进程(如SMON、PMON、DBWn等)没有被关闭;
c、 用于锁内存的文件lk和sgadef.dbf文件没有被删除。
遇到c的情况,我删除了$ORACLE_HOME/dbs/下的lk开头文件(其实b种情况也出现了。后来才意识到)
我参考了另一篇文章,通过fuser命令找出占用lk开头文件的程序的进程然后kill掉那些进程来解决这个问题
su root
yum -y install psmisc#安装依赖
查看在占用lk开头文件的程序的进程
fuser -u /data/app/oracle/product/11.2.0/dbs/lkORCL#(如果没有,就到目录下找名叫lkXXX的文件,这是根据你们的配置生成的)
[root@lhk_oracle dbs]# fuser -u /data/app/oracle/product/11.2.0/dbs/lkORCL
/data/app/oracle/product/11.2.0/dbs/lkORCL: 17496(oracle) 17502(oracle) 17506(oracle) 17508(oracle) 17512(oracle) 17514(oracle) 17516(oracle) 17518(oracle) 17520(oracle) 17522(oracle) 17524(oracle) 17526(oracle) 17541(oracle) 17557(oracle) 17566(oracle) 17568(oracle) 18059(oracle) 20754(oracle)
果然有一大堆,然后kill掉这些进程
fuser -k /data/app/oracle/product/11.2.0/dbs/lkORCL
再次startup
su oracle
sqlplus / as sysdba
SQL> startup
ORACLE instance started.
Total System Global Area 1286066176 bytes
Fixed Size 2213016 bytes
Variable Size 352324456 bytes
Database Buffers 922746880 bytes
Redo Buffers 8781824 bytes
Database mounted.
Database opened.
启动数据库成功
转载自:
https://www.cnblogs.com/thg999/p/9981766.html
https://www.jb51.net/article/98191.htm
https://www.vpsv.cn/article/123.html
https://blog.csdn.net/chenghuikai/article/details/85776622
http://blog.itpub.net/12272958/viewspace-716020
http://blog.sina.com.cn/s/blog_4b5bc0110101d310.html