Centos6/7下静默安装oracle10g

Centos6/7下静默安装Oracle10g

远程安装oracle10g,通过网上资料,不断摸索成功安装。先在本地虚拟机Centos7上做实验,快照恢复快照恢复,安装了几十次成功之后,再在服务器Centos6上安装,(6和7还是有区别的,比如默认防火墙)中间遇到各种问题特记录下来分享。

在linux下安装oracle主要注意点:

1.关闭不必要的服务
2.安装必要的依赖包(少包会引起各种问题)
3.根据系统版本选择合适的oracle安装包
4.添加用户和用户组,创建安装文件夹
5.配置系统环境(创建修改各种文件)
6.安装软件并建库
7.开机自启配置


检查硬件需求(略)

关闭防火墙

1、关闭firewall:

systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)

2、iptables防火墙

vi /etc/sysconfig/iptables #编辑防火墙配置文件
# sampleconfiguration for iptables service
# you can edit thismanually or use system-config-firewall
# please do not askus to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT[0:0]
:OUTPUT ACCEPT[0:0]
-A INPUT -m state--state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -jACCEPT
-A INPUT -i lo -jACCEPT
-A INPUT -p tcp -mstate --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -jACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8080-j ACCEPT
-A INPUT -j REJECT--reject-with icmp-host-prohibited
-A FORWARD -jREJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
备注:这里使用808080端口为例。***部分一般添加到“-A INPUT -p tcp -m state --state NEW -m tcp--dport 22 -j ACCEPT”行的上面或者下面,切记不要添加到最后一行,否则防火墙重启后不生效。
systemctlrestart iptables.service #最后重启防火墙使配置生效
systemctlenable iptables.service #设置防火墙开机启动

3.编写关闭服务脚本(根据需要来)

#vi serverstop.sh
chkconfig iptables off  
chkconfig ip6tables off  
chkconfig cups off  
chkconfig firstboot off  
chkconfig wpa_supplicant off  
chkconfig postfix off  
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config  
sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config  
sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config 

执行关闭服务脚本

#sh serverstop.sh

准备文件Oracle10g

上传文件 xxx.zip 到 /oracle(没有就建,放哪都行)目录下(工具任意,Xshell带的Xftp,SecureCRT带的SecureFX);
[root@localhost oracle]# unzip xxx.zip

如果压缩格式是cpio.gz  这种格式有这样几种解压缩方式  
 a.  # zcat XXXX.cpio.gz | cpio -idmv   
 b.  # gunzip XXXX.cpio.gz
 解压出XXXX.cpio文件然后再> # cpio -idvm < XXXX.cpio 解压缩完成后,设置oracle帐户可以操作安装文件所在的目录  
 chown -R oracle:oinstall 所在目录

添加用户组和用户

[root@localhost Server]# groupadd oinstall
[root@localhost Server]# groupadd dba
[root@localhost  Server]# groupadd oper

[root@localhost Server]# useradd -g oinstall -G dba oracle
[root@localhost Server]# passwd oracle

Changing password for user oracle.
New UNIX password: 
Retype new UNIX password: 
passwd: all authentication tokens updated successfully.

创建Oracle安装文件夹,并授权Oracle

[root@localhost Server]# mkdir -p /u01/app/oracle/product/10.2.0/db_1
[root@localhost Server]# chown -R oracle.oinstall /u01
[root@localhost Server]# chmod 775 /u01

oraInst.loc

在/etc目录下创建一个名为 oraInst.loc 的文件,文件中的内容(两行代码)如下:

inventory_loc=/u01/app/oracle/oraInventory
inst_group= oinstall

输入下面的命令在oraInst.loc文件上设置合适的拥有者,组和权限:

[root@localhost oracle]# chown oracle:oinstall oraInst.loc
[root@localhost oracle]# chmod 664 oraInst.loc

安装常用软件及必需软件

从网上搜集的,可能有重复包,不影响,yum安装时,已安装会自动略过

安装常用包

yum -y install autoconf automake binutils-devel bison cpp dos2unix ftp gcc gcc-c++ lrzsz python-devel

安装Oracle必需软件:

yum -y install compat-db compat-gcc-34 compat-gcc-34-c++ compat-libstdc++-33 glibc-* glibc-*.i686 libXpm-*.i686 libXp.so.6 libXt.so.6 libXtst.so.6 libgcc_s.so.1 ksh libXp libaio-devel numactl numactl-devel unixODBC unixODBC-devel

网上的第二版本

或者一起安装(推荐再执行一次,以免遗漏,不费力)

yum -y install binutils compat-libstdc++-33 compat-libstdc++-33.i686 elfutils-libelf elfutils-libelf-devel gcc gcc-c++ glibc glibc.i686 glibc-common glibc-devel glibc-devel.i686 glibc-headers ksh libaio libaio.i686 libaio-devel libaio-devel.i686 libgcc libgcc.i686 libstdc++ libstdc++.i686 libstdc++-devel make sysstat

遇到下面问题[1]
Centos6/7下静默安装oracle10g_第1张图片
解决方法:

Ctrl+c退出命令

rm –f /var/run/yum.pid

配置内核及其他参数

sysctl.conf

vi /etc/sysctl.conf

加入以下11行代码(并将原来的# kernel.shmmax和kernel.shmall这两行参数屏蔽)(kernel.shmmax和kernel.shmall好像要单独考虑,我略过了)

kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
# semaphores: semmsl, semmns, semopm, semmni
kernel.sem = 250 32000 100 128
fs.file-max = 65536
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default=262144
net.core.rmem_max=262144
net.core.wmem_default=262144
net.core.wmem_max=262144

执行以下命令使以上参数修改生效

[root@localhost Server]# /sbin/sysctl -p

limits.conf

vi /etc/security/limits.conf

加入以下四行代码

oracle              soft    nproc   2047  
oracle              hard    nproc   16384  
oracle              soft    nofile  1024  
oracle              hard    nofile  65536 

login

vi /etc/pam.d/login 

加入最后一行上面,下面代码(64位和32位注意lib64/lib这个区别)

session    required     /lib64/security/pam_limits.so  
session    required     pam_limits.so

config

vi /etc/selinux/config

禁用SELINUX,安装完后可再还原成原值) 将SELINUX设置为

SELINUX=disabled

伪装操作系统版本

vi /etc/centos-release 

注释掉原来的,添加下面的,因为oracle支持的操作系统包含rh4

redhat-4

LANG

Oracle 10g 默认不支持中文
安装时,临时执行修改就行

export LANG=en_US

Oracle环境变量

可根据你的需要作适当更改

[root@localhost Server]# vi /home/oracle/.bash_profile  

加入内容如下,注释原PATH及export

# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR

ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
ORACLE_SID=TSH1; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jre:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH

if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi

静默安装模板文件

注销root用户,并登录oracle用户,在/home/oracle目录下建立一个名为enterprise01.rsp的文件,里面的具体内容如下(参考/oracle/database/response目录下面的enterprise.rsp文件,该目录下有三个文件enterprise.rsp(企业版静默安装文件),standard.rsp(标准版静默安装文件)和custom.rsp(客户版静默安装文件),另外还有其他三个静默安装文件)。


有三四个值在enterprise.rsp中没有,可以直接使用下面的配置

RESPONSEFILE_VERSION=2.2.1.0.0
FROM_LOCATION="../stage/products.xml"
ORACLE_HOME="/u01/app/oracle/product/10.2.0/db_1/"
ORACLE_HOME_NAME="OraDb10g_home1"
TOPLEVEL_COMPONENT={"oracle.server","10.2.0.1.0"}
DEINSTALL_LIST={"oracle.server","10.2.0.1.0"}
SHOW_SPLASH_SCREEN=false
SHOW_WELCOME_PAGE=false
SHOW_COMPONENT_LOCATIONS_PAGE=false
SHOW_CUSTOM_TREE_PAGE=false
SHOW_SUMMARY_PAGE=false
SHOW_INSTALL_PROGRESS_PAGE=false
SHOW_REQUIRED_CONFIG_TOOL_PAGE=false
SHOW_CONFIG_TOOL_PAGE=false
SHOW_RELEASE_NOTES=false
SHOW_ROOTSH_CONFIRMATION=false
SHOW_END_SESSION_PAGE=false
SHOW_EXIT_CONFIRMATION=false
NEXT_SESSION=false
NEXT_SESSION_ON_FAIL=false
SHOW_DEINSTALL_CONFIRMATION=false
SHOW_DEINSTALL_PROGRESS=false
ACCEPT_LICENSE_AGREEMENT=true
COMPONENT_LANGUAGES={"en"}
CLUSTER_NODES=
INSTALL_TYPE="EE"
s_nameForDBAGrp=dba
s_nameForOPERGrp=dba
b_oneClick=false
SHOW_DATABASE_CONFIGURATION_PAGE=false
b_createStarterDB=false

安装oracle

[oracle@localhost ~]$ cd /oracle/database
[oracle@localhost database]$ ./runInstaller -silent -responseFile /home/oracle/enterprise01.rsp

安装完成查看日志
这里写图片描述
如果只有下面这个问题(其它问题自行百度),可以忽略
Centos6/7下静默安装oracle10g_第2张图片

执行oracle脚本

以root用户运行安装后环境所需脚本(千万主意:要以root用户去执行这两个脚本,执行后一个脚本时,回车一下就可以了)

[root@localhost ~]# sh /u01/app/oracle/oraInventory/orainstRoot.sh(非第一次安装,可无)
[root@localhost ~]# sh /u01/app/oracle/product/10.2.0/db_1/root.sh

Centos6/7下静默安装oracle10g_第3张图片

测试看能否进sqlplus

Centos6/7下静默安装oracle10g_第4张图片


至此Oracle的产品已经安装完成,可是目前为止我们还没有建立数据库。 由于没有X界面无法启动dbca ,所以不能用dbca来帮我们建立数据库。这时候你可能会想到用create database 语句来建立数据库,可是语法实在是繁琐,并且还要运行许多的oracle脚本 。

此时,我们可以利用oracle提供的种子数据库还原一个数据库出来(详细见以下操作) 假设我们要建立的数据库的名称为TSH1(这个名称跟你安装前设置的环境变量中的ORACLE_SID相一致)。

建库

利用oracle提供的种子数据库还原一个数据库出来 的详细步骤

建议同时建立三个远程连接,一个root,一个oracle下一般操作,一个oracle下rman操作,避免来回切换引起的不便和带来意想不到的问题(注意在重启数据库时要退出rman)。

建立所需目录,并授权

[root@localhost Server]# mkdir -p /u01/app/oracle/admin/TSH1/{a,b,u}dump
[root@localhost Server]# mkdir -p /u01/app/oracle/oradata/TSH1
[root@localhost Server]# chown -R oracle.oinstall /u01
[root@localhost Server]# chmod 775 /u01
[oracle@localhost  oracle]$ ls -l     

刷新授权前/uo1/oracle/oracle下面各文件的权限

/u01/app/oracle
total 16
drwxr-xr-x 3 root   root     4096 May 22 06:24 admin
drwxr-xr-x 3 root   root     4096 May 22 06:25 oradata
drwxr-xr-x 6 oracle oinstall 4096 May 22 06:19 oraInventory
drwxr-xr-x 3 oracle oinstall 4096 May 22 06:08 product   

种子数据库控制文件

找到oracle为种子数据库提供的控制文件并copy至/u01/app/oracle/oradata/TSH1目录下(在Oracle用户下操作)

[oracle@localhost  oracle]$ cd /u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/

这里写图片描述

[oracle@localhost templates]$ cp Seed_Database.ctl /u01/app/oracle/oradata/TSH1

pfile文件

建立pfile文件(在Oracle用户下操作)

[oracle@localhost templates]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs

注意权限

[oracle@localhost templates]$ vi initTSH1.ora  

输入以下三行并保存退出

*.db_name=SEEDDATA
control_files='/u01/app/oracle/oradata/TSH1/Seed_Database.ctl'
compatible=10.2.0.1.0

注:因为Seed_Database.ctl控制文件中记录的db_name为SEEDDATA,所以第一行的设置如此

spfile

启动数据库到mount状态,并使用默认的参数建立spfile文件;然后重新启动数据库并更改sga_max_size,sga_target参数的值;然后再次重新启动数据库(具体操作如下)

问题

这里写图片描述

先 cd /u01/app/oracle/product/10.2.0/db_1/bin/
Centos6/7下静默安装oracle10g_第5张图片

报错 说明oracle_home的问题 临时解决方案(可能原因是从root用户切换过引起的,直接使用oracle用户登录,或者su -
oracle 切换)

echo $ORACLE_HOME
export ORACLE_HOME=/u01/app/oracle/product/10.2.0/db_1
echo $ORACLE_SID
export ORACLE_SID=TSH1

也可以建立软链接

ln -s /u01/app/oracle/product/10.2.0/db_1/bin/sqlplus /usr/bin

Centos6/7下静默安装oracle10g_第6张图片

[oracle@localhost  dbs]$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu May 22 06:56:19 2008

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> startup mount
ORACLE instance started.
Total System Global Area  113246208 bytes
Fixed Size                  1218004 bytes
Variable Size              58722860 bytes
Database Buffers           50331648 bytes
Redo Buffers                2973696 bytes
Database mounted.

如果出现问题:

这里写图片描述
解决方法:
Centos6/7下静默安装oracle10g_第7张图片

more /proc/sys/vm/hugetlb_shm_group
SQL> create spfile from pfile;
File created.

SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.

SQL> startup mount
ORACLE instance started.
Total System Global Area  113246208 bytes
Fixed Size                  1218004 bytes
Variable Size              58722860 bytes
Database Buffers           50331648 bytes
Redo Buffers                2973696 bytes
Database mounted.

问题:
Centos6/7下静默安装oracle10g_第8张图片
该文件权限问题,可能当时copy的时候使用的是root,修改一下就行

SQL> alter system set sga_max_size=200M scope=spfile;
System altered.
SQL> alter system set sga_target=160M scope=spfile;
System altered.
SQL> shutdown immediate
ORA-01109: database not open
Database dismounted.
ORACLE instance shut down.

这里写图片描述

SQL> startup mount
ORACLE instance started.
Total System Global Area  209715200 bytes
Fixed Size                  1218580 bytes
Variable Size             100665324 bytes
Database Buffers          104857600 bytes
Redo Buffers                2973696 bytes
Database mounted.

用RMAN连接数据库

和sqlplus一样的命令,在oracle安装目录bin下

[oracle@localhost ~]$ rman target /
/u01/app/oracle/product/10.2.0/db_1/bin/rman target /
Recovery Manager: Release 10.2.0.1.0 - Production on Thu May 22 07:22:51 2008

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

connected to target database: SEEDDATA (DBID=3891038516, not open)

RMAN> list backup;
using target database control file instead of recovery catalog

List of Backup Sets
===================

BS Key  Type LV Size       Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
1       Full    89.23M     DISK        00:00:36     30-JUN-05      
        BP Key: 1   Status: AVAILABLE  Compressed: YES  Tag: 
        Piece Name: /ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb
  List of Datafiles in backup set 1
  File LV Type Ckp SCN    Ckp Time  Name
  ---- -- ---- ---------- --------- ----
  1       Full 446074     30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/system01.dbf
  2       Full 446074     30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/undotbs01.dbf
  3       Full 446074     30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/sysaux01.dbf
  4       Full 446074     30-JUN-05 /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/users01.dbf

RMAN> 

Centos6/7下静默安装oracle10g_第9张图片

可以看到,我们可以利用

/ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb

这个备份集来还原数据库
上面的地址是其他人的,我的是下面的,注意一下就行,灵活变通

/ade/aime_ship_10gR2_050630.0022/oracle/oradata/Seed_Database.dfb

但是很明显我们系统中并没有这样一个文件

/ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb

但是查找发现路径

/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates

下有 Seed_Database.dfb文件


有两种方法解决此问题,一个是建立一个软链接

/ade/aime_10.2_lnx_push/oracle/oradata/Seed_Database.dfb 

指向

/u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates/Seed_Database.dfb 

另一种是创建目录

/ade/aime_10.2_lnx_push/oracle/oradata/

并将Seed_Database.dfb copy至其下 。
这里,我们使用第二种方法(具体操作如下):

[root@localhost ~]# mkdir -p mkdir -p /ade/aime_ship_10gR2_050630.0022/oracle/oradata/
[root@localhost ~]# chown -R oracle.oinstall /ade
[root@localhost ~]# chmod 775 /ade
[root@localhost ~]# su - oracle

[oracle@localhost ~]$ cd /u01/app/oracle/product/10.2.0/db_1/assistants/dbca/templates
[oracle@localhost templates]$cp Seed_Database.dfb /ade/aime_ship_10gR2_050630.0022/oracle/oradata/

还原数据库

先在RMAN下执行如下命令

run {
set newname for datafile '/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata/system01.dbf' to '/u01/app/oracle/oradata/TSH1/system01.dbf';
set newname for datafile '/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata/sysaux01.dbf' to '/u01/app/oracle/oradata/TSH1/sysaux01.dbf';
set newname for datafile '/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata/undotbs01.dbf' to '/u01/app/oracle/oradata/TSH1/undotbs01.dbf';
set newname for datafile '/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata/users01.dbf' to '/u01/app/oracle/oradata/TSH1/users01.dbf';
restore database;
switch datafile all;
}

因为控制文件中记录的log file路径为

/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata 

所以要先创建相应的目录并再次刷新其权限,体操作如下

[root@localhost ~]#mkdir -p /ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata
[root@localhost  ~]# chown -R oracle.oinstall /ade
[root@localhost ~]# chmod 775 /ade

然后在sqlplus中执行如下命令:

[oracle@localhost TSH1]$ sqlplus / as sysdba

Centos6/7下静默安装oracle10g_第10张图片

SQL> alter database open resetlogs;

Database altered.

SQL>

此时,在目录

/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata

下创建了redo01.log,redo02.log,redo03.log,temp01.dbf文件

我们要更改这几个文件的路径,所以先将数据库关闭

/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata

然后

cp /ade/aime_10.2_lnx_push/oracle/oradata/seeddata/* /u01/app/oracle/oradata/orcl/

启动数据库到mount状态,并更改日志和临时文件的路径(具体操作如下)

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> 

[oracle@localhost ~]$cd /ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata

[oracle@localhost seeddata]$ cp redo01.log redo02.log redo03.log temp01.dbf /u01/app/oracle/oradata/TSH1/

然后启动数据库到mount状态,并更改日志和临时文件的路径


SQL> startup mount;
ORACLE instance started.

Total System Global Area  209715200 bytes
Fixed Size                  1218580 bytes
Variable Size             104859628 bytes
Database Buffers          100663296 bytes
Redo Buffers                2973696 bytes
Database mounted.
SQL> alter database rename file '/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata/redo01.log' to '/u01/app/oracle/oradata/TSH1/redo01.log';

Database altered.
SQL> 
alter database rename file '/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata/redo02.log' to '/u01/app/oracle/oradata/TSH1/redo02.log';

Database altered.

SQL> 
alter database rename file '/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata/redo03.log' to '/u01/app/oracle/oradata/TSH1/redo03.log';

Database altered.

SQL>
alter database rename file '/ade/aime_ship_10gR2_050630.0022/oracle/oradata/seeddata/temp01.dbf' to '/u01/app/oracle/oradata/TSH1/temp01.dbf';

注意空格引起的错误

Database altered.

SQL> alter database open;

Database altered.

SQL> 

到此数据库已经建立,并且数据文件也放到了我们期待的地方。但是还有一个问题,就是数据库名称不是我们事先期待的。

SQL> show parameter name

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      SEEDDATA
db_unique_name                       string      SEEDDATA
global_names                         boolean     FALSE
instance_name                        string      TSH1
lock_name_space                      string
log_file_name_convert                string
service_names                        string      SEEDDATA
SQL> 

Centos6/7下静默安装oracle10g_第11张图片


下面我们将数据库名称SEEDDATA改成我们需要的TSH1 。注意此时仅仅更改参数文件的值是不行的,因为控制文件中同样也记录着数据库的名称。

更改数据库名称

首先备份控制文件脚本
SQL> alter database backup controlfile to trace as '/tmp/ctl.txt';
Database altered.
SQL> create pfile from spfile;
File created.
SQL> 

然后将spfile文件(spfileTSH1.ora)删除,编辑pfile文件(initTSH1.ora)将

db_name="SEEDDATA"

改成

db_name="TSH1"
[oracle@localhost dbs]$ cd /u01/app/oracle/product/10.2.0/db_1/dbs
[oracle@localhost dbs]$ rm spfileTSH1.ora
[oracle@localhost dbs]$ vi initTSH1.ora

保存对initTSH1.ora的修改并退出。然后

vi /home/oracle/ctl2.txt

(参考/tmp/ctl.txt重建控制文件脚本),脚本的内容如下:

CREATE CONTROLFILE REUSE DATABASE "SEEDDATA" set database "TSH1"  RESETLOGS  NOARCHIVELOG
    MAXLOGFILES 16
    MAXLOGMEMBERS 3
    MAXDATAFILES 100
    MAXINSTANCES 8
    MAXLOGHISTORY 292
LOGFILE
  GROUP 1 '/u01/app/oracle/oradata/TSH1/redo01.log'  SIZE 50M,
  GROUP 2 '/u01/app/oracle/oradata/TSH1/redo02.log'  SIZE 50M,
  GROUP 3 '/u01/app/oracle/oradata/TSH1/redo03.log'  SIZE 50M
DATAFILE
  '/u01/app/oracle/oradata/TSH1/system01.dbf',
  '/u01/app/oracle/oradata/TSH1/undotbs01.dbf',
  '/u01/app/oracle/oradata/TSH1/sysaux01.dbf',
  '/u01/app/oracle/oradata/TSH1/users01.dbf'
CHARACTER SET US7ASCII
;
nomount

然后重新启动数据库到nomount状态,运行上面建立控制文件的脚本,然后打开数据库(具体操作如下)

SQL> shutdown immediate;
Database closed.
Database dismounted.
ORACLE instance shut down.
SQL> startup nomount;
ORACLE instance started.

Total System Global Area  209715200 bytes
Fixed Size                  1218580 bytes
Variable Size             104859628 bytes
Database Buffers          100663296 bytes
Redo Buffers                2973696 bytes
SQL> @/home/oracle/ctl2.txt

Control file created.

SQL> alter database open resetlogs; 

Database altered.

SQL> 

控制文件更名并实现冗余(可略)

[root@localhost ~]# cd /u01/app/oracle/oradata/TSH1
[root@localhost TSH1]# mv Seed_Database.ctl control01.ctl
[root@localhost TSH1]# cp control01.ctl control02.ctl
[root@localhost TSH1]# cp control01.ctl control03.ctl
[root@localhost TSH1]# cd /u01/app/oracle/product/10.2.0/db_1/dbs
[root@localhost dbs]# chown -R oracle.oinstall /u01
[root@localhost  dbs]# chmod 775 /u01 

修改参数文件initTSH1.ora(修改.control_files这一行,其内容如下)*

[root@localhost dbs]# vi initTSH1.ora
*.control_files='/u01/app/oracle/oradata/TSH1/control01.ctl','/u01/app/oracle/oradata/TSH1/control02.ctl','/u01/app/oracle/oradata/TSH1/control03.ctl'

重新启动数据库,大功告成!

SQL> startup
ORACLE instance started.

Total System Global Area  209715200 bytes
Fixed Size                  1218580 bytes
Variable Size             104859628 bytes
Database Buffers          100663296 bytes
Redo Buffers                2973696 bytes
Database mounted.
Database opened.
SQL> show parameter name

Centos6/7下静默安装oracle10g_第12张图片

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
db_file_name_convert                 string
db_name                              string      TSH1
db_unique_name                       string      TSH1
global_names                         boolean     FALSE
instance_name                        string      TSH1
lock_name_space                      string
log_file_name_convert                string
service_names                        string      TSH1
SQL> create user yyidentified by yy;

User created.

SQL> grant resource to yy;

Grant succeeded.

SQL> grant create session to yy;

Grant succeeded.

SQL> conn yy/yy;
Connected.
SQL> select sysdate from dual;

SYSDATE
---------
2016-04-17 10:33:31

SQL> 

问题:
Centos6/7下静默安装oracle10g_第13张图片

解决方法:
Centos6/7下静默安装oracle10g_第14张图片
Centos6/7下静默安装oracle10g_第15张图片

create rollback segment rbs_seg tablespace system;

alter rollback segment rbs_seg tablespace online;

Centos6/7下静默安装oracle10g_第16张图片

问题:

ORA-12162: TNS:net service name is incorrectly specified 

方法:
http://blog.itpub.net/519536/viewspace-672034/

这里写图片描述

Centos6/7下静默安装oracle10g_第17张图片

Centos6/7下静默安装oracle10g_第18张图片

Centos6/7下静默安装oracle10g_第19张图片

Centos6/7下静默安装oracle10g_第20张图片

Centos6/7下静默安装oracle10g_第21张图片

Centos6/7下静默安装oracle10g_第22张图片

未设置自启动前,重启linux后的问题集:


(大部分问题的解决方法,都能够解决问题,直接截图了,当时安装的时候在word文档里做得笔记,截图比较快,结果整理到博客上只能一张一张上传图片。。。)

首先要直接用oracle登陆,不能root ->su oracle,丢失环境变量

启动系统后,使用navicat连接oracle
问题1
Centos6/7下静默安装oracle10g_第23张图片

关闭防火墙
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动

这里写图片描述

Centos6/7下静默安装oracle10g_第24张图片

因为用户非root,需密码

再次连接oracle
问题2
Centos6/7下静默安装oracle10g_第25张图片
Centos6/7下静默安装oracle10g_第26张图片

这里写图片描述
方法:
这里写图片描述

这里写图片描述

Centos6/7下静默安装oracle10g_第27张图片

然后(建立两个链接,避免来回切换)(出现乱码是因为使用backespace和delete,百度设置一下xshell就行)

Centos6/7下静默安装oracle10g_第28张图片

然后exit,lsnrctl start,emctl start dbconsole

Centos6/7下静默安装oracle10g_第29张图片

Centos6/7下静默安装oracle10g_第30张图片

再次连接
Centos6/7下静默安装oracle10g_第31张图片

新增数据后
问题3
Centos6/7下静默安装oracle10g_第32张图片

方法

Centos6/7下静默安装oracle10g_第33张图片

Centos6/7下静默安装oracle10g_第34张图片

Centos6/7下静默安装oracle10g_第35张图片

create undo tablespace "UNDOTBSGCH02" datafile '/u01/app/oracle/oradata/TSH1/UNDOTBSGCH02.DBF' size 128m reuse autoextend on next 10m maxsize 2048m;

 alter system set undo_tablespace=UNDOTBSGCH02  scope=spfile;

oracle自动启动与关闭

Oracle启动&停止脚本
1.修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用。

# vi /etc/oratab
orcl:/opt/oracle/102:Y
# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME::

2. 在 /etc/init.d/ 下创建文件oracle,内容如下:

#!/bin/sh
# chkconfig: 35 80 10
# description: Oracle auto start-stop script.

#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/u01/app/oracle/product/10.2.0/db_1
ORA_OWNER=oracle
if [ ! -f $ORA_HOME/bin/dbstart ]
then
    echo "Oracle startup: cannot start"
    exit
fi
case "$1" in
'start')
# Start the Oracle databases:
echo "Starting Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle
echo "Done"

# Start the Listener:
echo "Starting Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle
echo "Done."
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
touch /var/lock/subsys/oracle
;;

'stop')
# Stop the Oracle Listener:
echo "Stoping Oracle Listeners ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle
echo "Done."
rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:
echo "Stoping Oracle Databases ... "
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle
echo "Done."
echo ""
echo "-------------------------------------------------" >> /var/log/oracle
date +" %T %a %D : Finished." >> /var/log/oracle
echo "-------------------------------------------------" >> /var/log/oracle
;;

'restart')
$0 stop
$0 start
;;
Esac

3.改变文件权限

# chmod 755 /etc/init.d/oracle

4.添加服务

# chkconfig --level 35 oracle on

5.需要在关机或重启机器之前停止数据库,做一下操作

# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle   //关机
# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle   //重启 

6.使用方法

# service oracle start        //启动oracle
# service oracle stop        //关闭oracle
# service oracle restart     //重启oracle

7.测试
a. 开机自启动

Last login: Mon Nov 26 19:57:06 2012 from 10.0.0.145
[root@localhost ~]# su - oracle
[oracle@ORS ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:07:33 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> set linesize 300;
SQL> set pagesize 30;
SQL> select * from scott.emp;

     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
SMITH      CLERK           7902 17-DEC-80        800                    20
ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
WARD       SALESMAN        7698 22-FEB-81       1250        500         30
JONES      MANAGER         7839 02-APR-81       2975                    20
MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
BLAKE      MANAGER         7839 01-MAY-81       2850                    30
CLARK      MANAGER         7839 09-JUN-81       2450                    10
SCOTT      ANALYST         7566 19-APR-87       3000                    20
KING       PRESIDENT            17-NOV-81       5000                    10
TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
ADAMS      CLERK           7788 23-MAY-87       1100                    20
JAMES      CLERK           7698 03-DEC-81        950                    30
FORD       ANALYST         7566 03-DEC-81       3000                    20
MILLER     CLERK           7782 23-JAN-82       1300                    10
rows selected.

SQL>


如果还不能远程连接oracle
可能是一下问题引起:
1.  端口映射
2.  编辑oracle的文件
是确保sid正确
![这里写图片描述](https://img-blog.csdn.net/20160419104834156)
还有主机名称


端口扫描http://tool.chinaz.com/port/

或者

Netstat –p  port  ip

转载于:https://www.cnblogs.com/llhl/p/9648695.html

你可能感兴趣的:(Centos6/7下静默安装oracle10g)