1. 程式人生 > >Centos6/7下靜默安裝oracle10g

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);
[[email protected] 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]
這裡寫圖片描述
解決方法:

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

安裝完成檢視日誌
這裡寫圖片描述
如果只有下面這個問題(其它問題自行百度),可以忽略
這裡寫圖片描述

執行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

這裡寫圖片描述

測試看能否進sqlplus

這裡寫圖片描述

至此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/
這裡寫圖片描述

報錯 說明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

這裡寫圖片描述

[[email protected]  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.

如果出現問題:

這裡寫圖片描述
解決方法:
這裡寫圖片描述

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.

問題:
這裡寫圖片描述
該檔案許可權問題,可能當時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下

[[email protected] ~]$ 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> 

這裡寫圖片描述

可以看到,我們可以利用

/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

這裡寫圖片描述

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> 

這裡寫圖片描述

下面我們將資料庫名稱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

這裡寫圖片描述

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> 

問題:
這裡寫圖片描述

解決方法:
這裡寫圖片描述
這裡寫圖片描述

create rollback segment rbs_seg tablespace system;

alter rollback segment rbs_seg tablespace online;

這裡寫圖片描述

問題:

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

這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述

這裡寫圖片描述

未設定自啟動前,重啟linux後的問題集:

(大部分問題的解決方法,都能夠解決問題,直接截圖了,當時安裝的時候在word文件裡做得筆記,截圖比