Centos6安装oracle10g

时间:2024-04-27 21:01:59

刚刚开始学OCP。第一关,安装,被折腾得稀碎。。。查询了大量资料,多次失败后终于总结出一些经验,简单整理如下。【2014-12-11 重新整理了一下顺序,修改了脚本!】

需要注意的是:如果想尝试我提供的环境设置脚本,一定要根据自己的实际情况修改变量!

Centos6安装oracle10g
一、安装流程
1、最小安装Centos6.6虚拟机(虚拟机系统推荐Virtualbox https://www.virtualbox.org ),Centos6镜像地址 http://mirrors.163.com/centos/6.6/isos/x86_64/CentOS-6.6-x86_64-minimal.iso

  • CPU: 2
  • MEM: 2G
  • DISK: >=20G (创建固定大小的虚拟硬盘文件能提高安装速度)
  • 分区时选最上面的 Use All Space
  • 手工指定主机名、分配IP地址

2、上传环境设置脚本,编辑变量部分,IP、主机名等值必须与本机相符。核查无误后,运行环境设置脚本(因为脚本没有做容错,所以只能运行一次),环境设置脚本会提示如下错误,忽略。
error: "net.bridge.bridge-nf-call-ip6tables" is an unknown key
error: "net.bridge.bridge-nf-call-iptables" is an unknown key
error: "net.bridge.bridge-nf-call-arptables" is an unknown key

3、安装桌面环境和依赖包

[root@centos6 ~]# yum install wget -y && \
yum groupinstall "Desktop" "X Window System" && \
yum install ksh make sysstat binutils* compat-libstdc++-33* \
elfutils-libelf* gcc gcc-c++ glibc* glibc*.i686 libgcc* libgcc*.i686 \
libaio* libaio*.i686 libstdc++* libstdc++*.i686 libXp libXp.i686 \
libXt libXt.i686 libXtst libXtst.i686

安装过程中以orausr用户登录,将学习用的Oracle10g安装包复制到/home/orausr,解压缩。如果虚拟机磁盘文件是自动增长的,此时可以用dd指令扩扩容。

[orausr@centos6 ~]$ wget http://10.34.67.204/package/oracle10g/Oracle10g-10201-Linux-X64.cpio.gz
[orausr@centos6 ~]$ gunzip Oracle10g--Linux-X64.cpio.gz
[orausr@centos6 ~]$ cpio -idmv < Oracle10g--Linux-X64.cpio
[orausr@centos6 ~]$
[orausr@centos6 ~]$ rm Oracle10g-10201-Linux-X64.cpio
[orausr@centos6 tmp]$ cd /tmp
[orausr@centos6 tmp]$ dd if=/dev/zero of=test bs=10M count= oflag=sync
[orausr@centos6 tmp]$ rm test

4、安装完成后重启系统!

5、以orausr用户登录控制台,运行 startx 启动桌面,桌面里打开终端运行 ./database/runInstaller 安装Oracle10g。以下选择仅供参考:

  • 选择Advanced Installation
  • 仔细核查安装目录是否跟脚本一致
  • 选择Enterprise Edition,选择Product Languages,增加 Simplified Chinese
  • Name推荐跟主机名一致,再次核查安装目录
  • 等待自检依赖项,完毕后点Next
  • 选择Create a database
  • 选择General Purpose
  • Global Database Name、SID可以不动,选择Database Character Set 为 Unicode standard UTF-8 AL32UTF8,选择Create database with sample schemas
  • 点Next
  • 选择File System,核查数据文件位置
  • 选择Do not enable Automatic backups
  • 选择Use the same password for all the accounts,输入密码,需要字母开头,大小写数字结合
  • 点Install
  • 忽略报错,点 Continue
  • 点OK
  • 以root身份运行完两个脚本后,点OK

中间会出现一个编译错误,Error in invoking target 'collector' of makefile '/opt/oracle/10.2.1/instance0/sysman/lib/ins_emdb.mk'. 可以点“Continue”忽略。

Centos6安装oracle10g

6、安装结束时,runInstaller会提示在root终端窗口运行两个脚本 orainstRoot.sh,root.sh,照做就行,接着完成Installer里面的操作,重启服务器。
如果安装失败,重新安装之前需要删除安装目录和一些文件
    /opt/oracle/*
    /opt/oraInventory/*
    /etc/oratab
    /usr/local/bin/* (新装系统这里只有3个Oracle程序,不会有其他文件)

二、使用Oracle
1、启动

[orausr@centos6 ~]$ emctl start dbconsole
[orausr@centos6 ~]$ lsnrctl start
[orausr@centos6 ~]$ dbstart

emctl start dbconsole启动时间很长,要耐心。

第一次手工运行dbstart会报错,需要修改dbstart脚本。嗯,oracle有个工程师叫vikrkuma,他写脚本有点儿马虎。。。

[orausr@centos6 ~]$ vi $ORACLE_HOME/bin/dbstart
ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracle 替换为 ORACLE_HOME_LISTNER=$ORACLE_HOME

2、访问

sqlplus访问:

[orausr@centos6 ~]$ sqlplus /nolog
SQL> conn /as sysdba
SQL> startup
SQL> show linesize;
linesize
SQL> set linesize ;
SQL> select * from scott.emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
SMITH CLERK -DEC-
ALLEN SALESMAN -FEB-
WARD SALESMAN -FEB-
JONES MANAGER -APR-
MARTIN SALESMAN -SEP-
BLAKE MANAGER -MAY-
CLARK MANAGER -JUN-
SCOTT ANALYST -APR-
KING PRESIDENT -NOV-
TURNER SALESMAN -SEP-
ADAMS CLERK -MAY- EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
JAMES CLERK -DEC-
FORD ANALYST -DEC-
MILLER CLERK -JAN- rows selected. SQL>
SQL> create user jerry identified by password123;
SQL> grant create session to jerry;
SQL> conn jerry/password123
SQL> show user;

OEM Web管理(需要先在sqlplus运行startup后才能正常):
http://192.168.122.2:1158/em

三、环境设置脚本
ins-c6-10g.sh

#!/bin/bash
#script for Oracle10g installation on Centos6.
#Change the following variables for your installation.
local_ip="192.168.122.2"
host_name="centos6"
host_name_fqdn="centos6.localdomain"
oracle_user="orausr"
oracle_user_password="mysql"
oracle_base="/opt/oracle"
oracle_home="/opt/oracle/10.2.1/instance0"
oracle_data="/opt/oracle/data"
oracle_data_recoveryarea="/opt/oracle/data_recover"
oracle_inventory="/opt/oraInventory"
oracle_sid="centos6"
#Change the above variables for your installation. echo "${local_ip} ${host_name} ${host_name_fqdn}" >>/etc/hosts

groupadd -g 505 dba
groupadd oinstall
groupadd oper
useradd ${oracle_user}
echo ${oracle_user_password}|passwd --stdin ${oracle_user}
usermod -g oinstall -G dba ${oracle_user} mkdir -p ${oracle_base}
mkdir -p ${oracle_data}
mkdir -p ${oracle_data_recoveryarea}
mkdir -p ${oracle_home}
mkdir -p ${oracle_inventory}
chown -R ${oracle_user}:oinstall ${oracle_base}
chmod -R ${oracle_base}
chmod -R g+s ${oracle_base}
chown -R ${oracle_user}:oinstall ${oracle_inventory}
chmod -R ${oracle_inventory}
chmod -R g+s ${oracle_inventory} sysctl_value="
kernel.sem =
fs.file-max =
kernel.shmall =
kernel.shmmax =
kernel.shmmni =
net.ipv4.ip_local_port_range =
net.core.rmem_default =
net.core.rmem_max =
net.core.wmem_default =
net.core.wmem_max =
vm.hugetlb_shm_group =
"
/bin/cp /etc/sysctl.conf /etc/sysctl.conf.bak
echo -e "${sysctl_value}" >> /etc/sysctl.conf
sysctl -p limits_value="
${oracle_user} soft nofile
${oracle_user} hard nofile
${oracle_user} soft nproc
${oracle_user} hard nproc
"
/bin/cp /etc/security/limits.conf /etc/security/limits.conf.bak
echo -e "${limits_value}" >> /etc/security/limits.conf bash_profile_value="
umask
ORACLE_BASE=${oracle_base}
ORACLE_SID=${oracle_sid}
ORACLE_HOME=${oracle_home}
ORACLE_UNQNAME=${oracle_sid}
export ORACLE_BASE ORACLE_SID ORACLE_HOME ORACLE_UNQNAME
PATH=$PATH:${oracle_home}/bin
export PATH
"
/bin/cp /home/${oracle_user}/.bash_profile /home/${oracle_user}/.bash_profile.bak
echo -e "${bash_profile_value}" >> /home/${oracle_user}/.bash_profile /bin/cp /etc/redhat-release /root/redhat-release.bak
echo "redhat4" > /etc/redhat-release

service iptables stop
service ip6tables stop
chkconfig iptables off
chkconfig ip6tables off
setenforce 0
sed 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux -i
 
echo
echo "All prepared! Restart the system and then run Oracle Installer in linux GUI."

四、启动过程示范:

[orausr@centos6 ~]$ emctl start dbconsole
TZ set to PRC
Oracle Enterprise Manager 10g Database Control Release 10.2.0.1.
Copyright (c) , Oracle Corporation. All rights reserved.
http://c608:1158/em/console/aboutApplication
Starting Oracle Enterprise Manager 10g Database Control .............................. started.
------------------------------------------------------------------
Logs are generated in directory /opt/oracle/10.2./instance0/c608_c608/sysman/log [orausr@centos6 ~]$
[orausr@centos6 ~]$ lsnrctl start LSNRCTL for Linux: Version 10.2.0.1. - Production on -DEC- :: Copyright (c) , , Oracle. All rights reserved. Starting /opt/oracle/10.2.1/instance0/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 10.2.0.1. - Production
System parameter file is /opt/oracle/10.2./instance0/network/admin/listener.ora
Log messages written to /opt/oracle/10.2./instance0/network/log/listener.log
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=c608)(PORT=))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 10.2.0.1. - Production
Start Date -DEC- ::
Uptime days hr. min. sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/10.2./instance0/network/admin/listener.ora
Listener Log File /opt/oracle/10.2./instance0/network/log/listener.log
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=c608)(PORT=)))
Services Summary...
Service "PLSExtProc" has instance(s).
Instance "PLSExtProc", status UNKNOWN, has handler(s) for this service...
The command completed successfully [orausr@centos6 ~]$
[orausr@centos6 ~]$ dbstart
[orausr@centos6 ~]$ sqlplus /nolog SQL*Plus: Release 10.2.0.1. - Production on Thu Dec :: Copyright (c) , , Oracle. All rights reserved. SQL> conn /as sysdba
Connected to an idle instance.
SQL> startup
ORACLE instance started. Total System Global Area bytes
Fixed Size   bytes
Variable Size bytes
Database Buffers bytes
Redo Buffers   bytes
Database mounted.
Database opened.
SQL> select * from scott.emp;