最小化centos7安装oracle11g2

1、转载自

  1. 转载自:https://blog.csdn.net/h8178/article/details/78251198
  2. 第6、7步可以不做。

2、下载 Oracle 11g

Oracle官方网站
http://www.oracle.com/technetwork/database/enterprise-edition/downloads/
我的机器安装的是CentOS7 64位系统,因此下载的Oracle版本也是64位的
最小化centos7安装oracle11g2_第1张图片

11.2.0.2.0 zlinux64版本的Oracle是安装在IBM服务器的,CentOS 7是无法安装的。
下载完成后,有两个压缩文件

linux.x64_11gR2_database_1of2.zip
linux.x64_11gR2_database_2of2.zip

通过Xftp将压缩文件上传到 /tmp/

3、安装依赖包

安装依赖包之前,个人建议将yum源修改为aliyun源,下载速度快些,执行如下命令即可:

cd /etc
mv yum.repos.d yum.repos.d.bak
mkdir yum.repos.d
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache

修改成功后,安装如下依赖包:

yum -y install binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel

使用如下命令检查依赖是否安装完整

rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel | grep "not installed"

发现 pdksh 没有安装
最小化centos7安装oracle11g2_第2张图片

执行yum -y install pdksh,发现CentOS 7 没有相关安装包可用
最小化centos7安装oracle11g2_第3张图片

通过wget命令直接下载pdksh的rpm包,我下载到了/tmp/

wget -O /tmp/pdksh-5.2.14-37.el5_8.1.x86_64.rpm http://vault.centos.org/5.11/os/x86_64/CentOS/pdksh-5.2.14-37.el5_8.1.x86_64.rpm

下载完成后,进入 /tmp/

rpm -ivh pdksh-5.2.14-37.el5_8.1.x86_64.rpm

再次检查依赖包是否安装完整

rpm -q binutils compat-libstdc++-33 elfutils-libelf elfutils-libelf-devel expat gcc gcc-c++ glibc glibc-common glibc-devel glibc-headers libaio libaio-devel libgcc libstdc++ libstdc++-devel make pdksh sysstat unixODBC unixODBC-devel | grep "not installed"

最小化centos7安装oracle11g2_第4张图片
到此依赖包安装完整

4、添加oracle用户组和用户

groupadd oinstall
groupadd dba
groupadd asmadmin
groupadd asmdba
useradd -g oinstall -G dba,asmdba oracle -d /home/oracle

添加完成后,查看oracle用户

id oracle

初始化oracle用户的密码

passwd oracle

最小化centos7安装oracle11g2_第5张图片

5、配置hostname(本机IP映射)

vim /etc/hosts
192.168.154.154 centos-oracle

测试hostname

ping -c 3 centos-oracle

最小化centos7安装oracle11g2_第6张图片

6、优化OS内核参数

kernel.shmmax 参数设置为物理内存的一半

vim /etc/sysctl.conf
fs.aio-max-nr=1048576
fs.file-max=6815744
kernel.shmall=2097152
kernel.shmmni=4096
kernel.shmmax = 1073741824
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

最小化centos7安装oracle11g2_第7张图片

7、限制oracle用户的shell权限

vim /etc/security/limits.conf
oracle              soft    nproc   2047
oracle              hard    nproc   16384
oracle              soft    nofile  1024
oracle              hard    nofile  65536
vim /etc/pam.d/login
session  required   /lib64/security/pam_limits.so
session  required   pam_limits.so
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

8、创建oracle安装目录

mkdir -p /db/app/oracle/product/11.2.0 
mkdir /db/app/oracle/oradata 
mkdir /db/app/oracle/inventory 
mkdir /db/app/oracle/fast_recovery_area 
chown -R oracle:oinstall /db/app/oracle 
chmod -R 775 /db/app/oracle

9、配置oracle用户环境变量

su - oracle
vim .bash_profile
umask 022
export ORACLE_HOSTNAME=centos-oracle
export ORACLE_BASE=/db/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"

以上配置完成后,个人建议重启下系统

reboot 

10、解压oracle压缩文件到 /db

cd /tmp
unzip linux.x64_11gR2_database_1of2.zip -d /db
unzip linux.x64_11gR2_database_2of2.zip -d /db

解压完成后

mkdir /db/etc/
cp /db/database/response/* /db/etc/
vim /db/etc/db_install.rsp
oracle.install.option=INSTALL_DB_SWONLY
DECLINE_SECURITY_UPDATES=true
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/db/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOSTNAME=centos-oracle
ORACLE_HOME=/db/app/oracle/product/11.2.0
ORACLE_BASE=/db/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.isCustomInstall=true
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba

开始安装

su - oracle
./runInstaller -silent -responseFile /db/etc/db_install.rsp -ignorePrereq

安装期间可以使用tail命令监看oracle的安装日志

tail -f /db/app/oracle/inventory/logs/installActions2017-07-12_03-48-29PM.log

这里写图片描述
安装完成,提示Successfully Setup Software.
根据提示完成配置
最小化centos7安装oracle11g2_第8张图片

su root
sh /db/app/oracle/inventory/orainstRoot.sh
sh /db/app/oracle/product/11.2.0/root.sh

最小化centos7安装oracle11g2_第9张图片

11、配置静默监听

su - oracle
netca /silent /responsefile /db/etc/netca.rsp

最小化centos7安装oracle11g2_第10张图片

查看监听端口

netstat -tnulp | grep 1521

这里写图片描述

12、静默创建数据库

TOTALMEMORY 设置为总内存的80%

vi /db/etc/dbca.rsp
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/db/app/oracle/oradata
RECOVERYAREADESTINATION=/db/app/oracle/fast_recovery_area
CHARACTERSET = "AL32UTF8"
TOTALMEMORY = "1638"

执行静默建库

dbca -silent -responseFile /db/etc/dbca.rsp

最小化centos7安装oracle11g2_第11张图片

查看oracle实例进程

ps -ef | grep ora_ | grep -v grep

最小化centos7安装oracle11g2_第12张图片

查看监听状态

lsnrctl status

最小化centos7安装oracle11g2_第13张图片

登录sqlplus,查看实例状态

sqlplus / as sysdba
select status from v$instance;

最小化centos7安装oracle11g2_第14张图片

出现以下情况,解决方式如下:输入startup,根据提示信息,将$ORACLE_BASE/admin/数据库名称/pfile目录下的init.ora.xxx形式的文件copy到$ORACLE_HOME/dbs目录下init{sid}.ora(根据startup提示)即可。
最小化centos7安装oracle11g2_第15张图片

如果报错:ORA-01102: cannot mount database in EXCLUSIVE mode

cause:A database is started in EXCLUSIVE mode by default.Some other instance has the database mounted exclusive or shared.

solution:(我安装的时候是通过第3步解决的)

1. Verify that there is not a "sgadef.dbf" file in the directory "ORACLE_HOME/dbs".

        % ls $ORACLE_HOME/dbs/sgadef.dbf  If this file does exist, remove it.

        % rm $ORACLE_HOME/dbs/sgadef.dbf

2. Verify that there are no background processes owned by "oracle"

       % ps -ef | grep ora_ | grep $ORACLE_SID

If background processes exist, remove them by using the Unix

command "kill". For example:

     % kill -9

3. Verify that no shared memory segments and semaphores that are owned by "oracle" still exist

% ipcs -b

If there are shared memory segments and semaphores owned by "oracle", remove the shared memory segments

        % ipcrm -m

and remove the semaphores

       % ipcrm -s

NOTE: The example shown above assumes that you only have one

database on this machine. If you have more than one

database, you will need to shutdown all other databases

before proceeding with Step 4.

4. Verify that the "$ORACLE_HOME/dbs/lk" file does not exist

5. Startup the instance

Solution Explanation:

=====================

The "lk" and "sgadef.dbf" files are used for locking shared memory. It seems that even though no memory is allocated, Oracle thinks memory is still locked. By removing the "sgadef" and "lk" files you remove any knowledge oracle has of shared memory that is in use. Now the database can start.

查看数据库编码

select userenv('language') from dual;

这里写图片描述

查看数据库版本信息

select * from v$version;

最小化centos7安装oracle11g2_第16张图片

激活scott用户

alter user scott account unlock;
alter user scott identified by tiger;
select username,account_status from all_users;

最小化centos7安装oracle11g2_第17张图片

13、Navicat远程连接Oracle

开放1521端口

firewall-cmd --zone=public --add-port=1521/tcp --permanent
firewall-cmd --reload

官方网站
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
下载 instantclient-basic,解压压缩文件
最小化centos7安装oracle11g2_第18张图片

下载Navicat
http://pan.baidu.com/s/1c2GP9U4
打开Navicat,工具→选项
最小化centos7安装oracle11g2_第19张图片

打开OCI界面,在右侧OCI library一栏中选择instantclient-basic解压目录下的oci.dll,然后点击确定。
最小化centos7安装oracle11g2_第20张图片

重启Navicat,点击连接,选中Oracle
最小化centos7安装oracle11g2_第21张图片

IP为Oracle服务器的IP地址,服务名为Oracle的实例名,可忽略大小写

select instance_name from v$instance;

这里写图片描述

用户名使用刚激活的scott,密码为tiger,填完以上信息后点击连接测试
最小化centos7安装oracle11g2_第22张图片

到此Navicat远程连接Oracle数据库成功。

14、设置Oracle开机启动

vi /db/app/oracle/product/11.2.0/bin/dbstart
ORACLE_HOME_LISTNER=$ORACLE_HOME
vi /db/app/oracle/product/11.2.0/bin/dbshut
ORACLE_HOME_LISTNER=$ORACLE_HOME
vi /etc/oratab

orcl:/db/app/oracle/product/11.2.0:Y

vi /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=/db/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

开机启动oracle

systemctl enable oracle

15、开机启动问题

oracle ORA-12547: TNS:lost contact

cd /db/app/oracle/product/11.2.0/bin/
chmod 6751 oracle

TNS-12555: TNS:permission denied

cd /var/tmp
chown -R oracle:oinstall .oracle

你可能感兴趣的:(程序人生)