標籤:linux;oracle
VM虛擬機器下在LINUX上安裝ORACLE 11G單一實例資料庫
1.環境及安裝前規劃:虛擬機器及OS如下
環境:VMware Wordstation ACE版 6.0.2
作業系統:OracleLinux-R5-U8-Server-i386-dvd 3.2G
安裝作業系統,這裡需要注意的是磁碟空間要預留足夠。
我的規劃是:
虛擬機器分配1024M記憶體,當然如果主機記憶體足夠,安裝時記憶體設定2048M可以更快。
虛擬機器分配一塊磁碟,30G磁碟空間。
/boot 100M ext3
/ 20G ext3
swap 2048M
剩餘的近8G空間留著做ASM時用。
同時最好安裝系統時選擇圖形模式安裝,直接安裝好圖形模式,比較省事。
2.OS的配置:
作業系統安裝好後,暫時需要配置以下內容
固定IP及DNS /etc/sysconfig/network-scripts/ifcfg-eth0
主機名稱 /etc/sysconfig/network
修改開機運行層級 /etc/inittab
關閉SELINUX /boot/grub/menu.lst
修改sshd_config,解決SSH逾時自動斷開問題
login as: root
[email protected]‘s password:
Last login: Wed Jun 5 09:11:26 2013
[[email protected] ~]# hostname
oel-01
[[email protected] ~]# cat/etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970[PCnet32 LANCE]
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0C:29:99:8B:C9
ONBOOT=yes
NETMASK=255.255.255.128
IPADDR=192.168.1.212
GATEWAY=192.168.1.254
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes
[[email protected] ~]# cat /etc/resolv.conf
nameserver 222.88.88.88
[[email protected] ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=oel-01
[[email protected] ~]# vi /etc/inittab
id:3:initdefault:
[[email protected] ~]# vi /boot/grub/menu.lst
在kernel 行末尾增加selinux=0關閉SELINUX。也可以在安裝完系統時的圖形配置介面中關閉。
[[email protected] ~]# cd /etc/ssh/
[[email protected] ssh]# grep"ClientAlive" sshd_config
#ClientAliveInterval 0
#ClientAliveCountMax 3
[[email protected] ssh]# cp sshd_configsshd_config.bak
[[email protected] ssh]# sed -i"s/#ClientAliveInterval 0/ClientAliveInterval 60/g" sshd_config
[[email protected] ssh]# grep"ClientAlive" sshd_config
ClientAliveInterval 60
#ClientAliveCountMax 3
[[email protected] ssh]# sed -i"s/#ClientAliveCountMax 3/ClientAliveCountMax 10/g" sshd_config
[[email protected] ssh]# grep"ClientAlive" sshd_config
ClientAliveInterval 60
ClientAliveCountMax 10
[[email protected] ssh]# service sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
到此應該將系統重啟,驗證以上各項配置是否生效。如生效,關機,在VMWARE中做快照
3.建立安裝ORACLE的使用者組
[[email protected] ~]# groupadd -g 1000 oinstall
[[email protected] ~]# groupadd -g 1031 dba
[[email protected] ~]# groupadd -g 1032 oper
[[email protected] ~]# useradd oracle
[[email protected] ~]# passwd oracle
Changing password for user oracle.
New UNIX password:
BAD PASSWORD: it is based on a dictionaryword
Retype new UNIX password:
passwd: all authentication tokens updatedsuccessfully.
[[email protected] ~]# usermod -g oinstall -Gdba,oper oracle
[[email protected] ~]# mkdir -p/u01/app/oracle/product/11.2.0/dbhome_1
[[email protected] ~]# chown -R oracle:oinstall/u01/
[[email protected] ~]# chmod 775 /u01/
[[email protected] app]# pwd
/u01/app
[[email protected] app]# ls -al
total 16
drwxrwxr-x 4 oracle oinstall 4096 Jun 5 10:56 .
drwxrwxr-x 3 oracle oinstall 4096 Jun 5 10:55 ..
drwxrwxr-x 2 oracle oinstall 4096 Jun 5 10:55 oracle
4.掛載光碟片,安裝軟體
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
[[email protected] yum.repos.d]# viOEL_CDROM.repo
[[email protected] yum.repos.d]# catOEL_CDROM.repo
[OEL5.8]
name=oracle linux
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[[email protected] yum.repos.d]# cd /mnt/
[[email protected] mnt]# mkdir cdrom
[[email protected] mnt]# mount /dev/cdrom/mnt/cdrom
mount: block device /dev/cdrom iswrite-protected, mounting read-only
[[email protected] mnt]# ls
cdrom
[[email protected] mnt]# cd cdrom/
[[email protected] cdrom]# ls
blafdoc.css eula.py README-en.html Server
Cluster GPL RELEASE-NOTES-en supportinfo
ClusterStorage images RELEASE-NOTES-en.html TRANS.TBL
EULA isolinux RPM-GPG-KEY VT
eula.en_US README-en RPM-GPG-KEY-oracle
[[[email protected] Server]# pwd
/mnt/cdrom/Server
[[email protected] Server]# ls /etc/pki/rpm-gpg/
RPM-GPG-KEY RPM-GPG-KEY-fedora RPM-GPG-KEY-oracle
RPM-GPG-KEY-EL4 RPM-GPG-KEY-fedora-test
[[email protected] Server]# rpm --import/etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
開始安裝軟體
方法一:
[[email protected] Server]# yum -y installoracleasm-support-2.1.7-1.el5.i386.rpm
[[email protected] Server]# yum -y installreadline-devel-5.1-3.el5.i386.rpm
[[email protected] Server]# yum -y installunixODBC
[[email protected] Server]# yum -y install make* gcc* glibc* compat-db* compat-gcc*compat-gcc* compat-libstdc++* compat-libstdc* openmotif* setarch*
[[email protected] Server]# yum -y installelfutils-libelf-devel-* libaio-devel-0.3.106-5.i386.rpm sysstat-7.0.2-11.el5.i386.rpm unixODBC-devel-2.2.11-10.el5.i386.rpm
安裝rlwrap-0.37.tar.gz,這裡我也是上傳上去的,這個軟體可以在網上自己找。
[[email protected] ~]# ls
anaconda-ks.cfg install.log rlwrap-0.37
Desktop install.log.syslog rlwrap-0.37.tar.gz
[[email protected] ~]# tar -zxvfrlwrap-0.37.tar.gz
[[email protected] rlwrap-0.37]# pwd
/root/rlwrap-0.37
[[email protected] rlwrap-0.37]# ./configure
[[email protected] rlwrap-0.37]# make
[[email protected] rlwrap-0.37]# make install
方法二:大量安裝
掛載光碟片後
[[email protected] mnt]#mkdir cdrom
[[email protected] mnt]# mount /dev/cdrom/mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[[email protected] mnt]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# vi public-yum-el5.repo
[oel5]
name = Enterprise Linux 5.7 DVD
baseurl=file:///mnt/cdrom/Server/
gpgcheck=0
enabled=1
[[email protected] yum.repos.d]# yum installoracle-validated
如果是OEL5: yum install oracle-validated
如果是OEL6: yum install oracle-rdbms-server-11gR2-preinstall
5.修改LINUX中的環境變數
修改oracle的.bash_profile,樣本如下:oracle_sid之類要提前規劃好。
[[email protected] oracle]# pwd
/home/oracle
[[email protected] oracle]# cat .bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
PATH=$PATH:$HOME/bin
#after is add by admin.
#
ORACLE_SID=bys001
ORACLE_BASE=/u01/app/oracle
ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1
PATH=$ORACLE_HOME/bin:$PATH:/user/sbin
export ORACLE_BASE ORACLE_SID ORACLE_HOMEPATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib:/usr/local/lib:/usr/X11R6/lib/
exportCLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
alias sqlplus=‘rlwrap sqlplus‘
alias rman=‘rlwrap rman‘
使用ORACLE使用者驗證下
[[email protected] ~]$ source .bash_profile
[[email protected] ~]$ sqlplus
rlwrap: Cannot execute sqlplus: No suchfile or directory
[[email protected] ~]$ rman
rlwrap: Cannot execute rman: No such fileor directory
說明:其它的核心參數等可以不修改,在安裝時檢查系統內容時可以使用ORACLE給出的指令碼進行修改,我這裡就用的這種方法。
6.把ORACLE DATABASE軟體上傳並解壓
我這裡使用的是SSH Secure Shell.這個軟體裡的傳檔案功能
注意要用ORACLE使用者上傳並解壓檔案,避免檔案許可權問題。
[[email protected] u01]$ ls
app linux_11gR2_database_2of2.zip
linux_11gR2_database_1of2.zip
[[email protected] u01]$ du -sh /u01/linux*
1.2G /u01/linux_11gR2_database_1of2.zip
951M /u01/linux_11gR2_database_2of2.zip
[[email protected] u01]$ unziplinux_11gR2_database_1of2.zip
[[email protected] u01]$ unziplinux_11gR2_database_2of2.zip
解壓後刪除原壓縮檔節省磁碟空間
[[email protected] u01]$ du -sh database/
2.3G database/
[[email protected] u01]$ rm -rf linux_11gR2_*
[[email protected] u01]$ ls
app database
[[email protected] u01]$
到此,關機,做一次快照。安裝前準備工作完成。
7.使用OUI圖形介面安裝
[[email protected] ~]# init 5
ORACLE軟體的安裝
去圖形介面,使用oracle使用者登陸,然後在案頭右鍵菜單中,開啟一個命令列終端視窗
[[email protected] ~]$ cd /u01/database/
[[email protected] database]$ ls
doc install response rpm runInstaller sshsetup stage welcome.html
[[email protected] database]$ ./runInstaller
安裝時的注意事項:
在安裝時過程中,要查看ORACLE_BASE/HOME等是否正確。
在安裝到檢查安裝環境時,會出現一些核心參數調整、缺少包(如果缺少包,按我這個說明上的環境及軟體如果都安裝的話是不會缺少包的)等提示。
根據提示框中 Fixable下有YES參數的,都是ORACLE可以自動修複的。
選擇上方的FIX&CHECK AGAIN。
這時開啟一個終端,注意要使用root使用者.根據對話方塊提示,開啟一個終端輸入下面:
[[email protected] ~]# sh/tmp/CVU_11.2.0.1.0_oracle/runfixup.sh
Response file being used is :/tmp/CVU_11.2.0.1.0_oracle/fixup.response
Enable file being used is:/tmp/CVU_11.2.0.1.0_oracle/fixup.enable
Log file location:/tmp/CVU_11.2.0.1.0_oracle/orarun.log
Setting Kernel Parameters...
kernel.sem = 250 32000 100 128
fs.file-max = 6815744
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
uid=501(oracle) gid=1000(oinstall)groups=1000(oinstall),1031(dba),1021(asmdba)
[[email protected] ~]#
再點擊對話方塊中OK選項。
此時重新檢查,發現這些參數都自動修複了。
如果有未安裝的包再進行安裝並重新檢查環境。
此時再進行檢查,發現就SWAP SIZE未通過,這個可以直接選擇IGNORE-ALL。
然後在下一步時檢查一下配置是否正確,然後點擊下一步進行安裝。
#######################################################
安裝到啟動NETCA時會出錯,不能啟動,需要打一個補丁
其實我的打了補丁還是不行,安裝完成後手動修改了下LISTNER.ORA檔案
[INS-20802] Oracle Net ConfigurationAssistant failed
Cause-The plug-in failed in its performmethod
解決方案:
需打名為p8670579_112010_LINUX.zip的補丁。
出現此錯誤時,先不要關閉安裝程式:
使用oracle使用者上傳和解壓檔案以及操作
unzip p8670579_112010_LINUX.zip
cd 8670579
/u01/app/oracle/product/11.2.0/dbhome_1/OPatch/opatchapply -invPtrLoc /u01/app/oracle/product/11.2.0/dbhome_1/oraInst.loc
其中/apps/oracle/product/11.2.0/db_1/為ORACLE_HOME,可使用$ORACLE_HOME代替
補丁打好後,點擊安裝程式的retry,繼續安裝即可。
查看系統中安裝的補丁
[[email protected] 8670579]$/u01/app/oracle/OPatch/opatch lsinventory
#########################################################
安裝完成後根據提示運行以下兩個指令碼。
[[email protected] Server]# sh/u01/app/oraInventory/orainstRoot.sh
Changing permissions of/u01/app/oraInventory.
Adding read,write permissions for group.
Removing read,write,execute permissions forworld.
Changing groupname of /u01/app/oraInventoryto oinstall.
The execution of the script is complete.
[[email protected] Server]# sh/u01/app/oracle/product/11.2.0/dbhome_1/root.sh
Running Oracle 11g root.sh script...
The following environment variables are setas:
ORACLE_OWNER= oracle
ORACLE_HOME= /u01/app/oracle/product/11.2.0/dbhome_1
Enter the full pathname of the local bindirectory: [/usr/local/bin]:
Copying dbhome to /usr/local/bin ...
Copying oraenv to /usr/local/bin ...
Copying coraenv to /usr/local/bin ...
Creating /etc/oratab file...
Entries will be added to the /etc/oratabfile as needed by
Database Configuration Assistant when adatabase is created
Finished running generic part of root.shscript.
Now product-specific root actions will beperformed.
Finished product-specific root actions.
8.安裝完成後續工作
1.防火牆開放1521連接埠
[[email protected] ~]# iptables-I INPUT 1 -p tcp --dport 1521 -j ACCEPT
[[email protected] ~]# /etc/rc.d/init.d/iptablessave
Saving firewall rules to/etc/sysconfig/iptables: [ OK ]
[[email protected] ~]# services iptables restart
-bash: services: command not found
[[email protected] ~]# service iptablesrestart
Flushing firewall rules: [ OK ]
Setting chains to policy ACCEPT:filter [ OK ]
Unloading iptables modules: [ OK ]
Applying iptables firewall rules: [ OK ]
Loading additional iptables modules: ip_conntrack_netbios_ns
2.配置LISTENER---如安裝過程中已經正常配置完成可以不做。
安裝完成後,啟動LISTENER
[[email protected] admin]$ lsnrctl start
輸出的最後兩句:
The listener supports no services
The command completed successfully
這樣啟動後遠端連線會報錯:
oracle ORA-12514:TNS:listener does notcurrently know of service requested in connect descriptor
原因:資料庫執行個體沒註冊到listener
在listener.ora裡面添加了如下內容:--配置為靜態監聽。
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(GLOBAL_DBNAME = orcl)
(SID_NAME = orcl)
)
)
註:裡面的orcl根據你安裝的資料庫執行個體名確定,我用此法解決了這個報錯。
解決方案二:這個網上看的,我自己沒使用,使用第一種就解決了。
這種應該是解決非動態註冊問題的,要手動註冊執行個體到listener
登入資料庫:
$sqlplus / as sysdba
顯示服務名:
SQL>show parameter service_names
強制註冊服務:
SQL>alter system register;
查看監聽狀態:
$lsnrctl status
9.設定資料庫開機自啟動
安裝好Oracle資料庫後:執行 dbstart和dbshut會提示:
[[email protected] ~]$ dbstart
ORACLE_HOME_LISTNER is not SET, unable toauto-start Oracle Net Listener
Usage:/u01/app/oracle/oracle/product/10.2.0/db_1/bin/dbstart ORACLE_HOME
錯誤原因是:dbstart和dbshut指令檔中ORACLE_HOME_LISTNER的設定有問題,
分別開啟兩個檔案找到:ORACLE_HOME_LISTNER=$1,(在檔案開頭,比較好找)修改為
ORACLE_HOME_LISTNER=$ORACLE_HOME
修改後儲存退出,問題已解決;
測試:
1.SQLPLUS能否啟動,如不能,檢查.bash_profile中環境變數 ORACLE_HOME PATH等,按我的方法做就可以。
2.使用SQLPLUS登陸測試
sqlplus / as sysdba
需要解鎖SCOTT使用者,並配置/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
[[email protected] admin]$ cat tnsnames.ora
# tnsnames.ora Network Configuration File:/u01/app/oracle/product/11.2.0/dbhome_1/network/admin/tnsnames.ora
# Generated by Oracle configuration tools.
BYS001 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.212)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = bys001)
)
)
sqlplus scott/[email protected]
sqlplusscott/[email protected]:1521/bys001
3.正常情況下資料庫執行個體未啟動,此時用SYS登陸,啟動資料庫,看資料庫能否啟動
4.實現開機ORACLE自動啟動監聽和執行個體
第一步:修改/etc/oratab檔案,命令如下:
格式如下:
--------------------------------------------------------------------------------
SID:ORACLE_HOME:AUTO
--------------------------------------------------------------------------------
[[email protected] ~]$ vi /etc/oratab
添加或修改成(預設好像是N)這一句:
bys001:/u01/app/oracle/product/11.2.0/dbhome_1/:Y
[[email protected] ~]# cat /etc/oratab
bys001:/u01/app/oracle/product/11.2.0/dbhome_1:Y
第二步:把lsnrctl start和dbstart添加到rc.local檔案中,命令如下:
[[email protected] ~]$ vi /etc/rc.d/rc.local
添加如下內容:
su oracle -lc"/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
su oracle -lc"/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"
[[email protected] ~]# cat /etc/rc.d/rc.local
#!/bin/sh
#
# This script will be executed *after* allthe other init scripts.
# You can put your own initialization stuffin here if you don‘t
# want to do the full Sys V style initstuff.
touch /var/lock/subsys/local
su oracle -lc"/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start"
su oracle -lc "/u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart"
第三步,重啟後直接用SQLPLUS登陸測試資料庫是否已經開啟。