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登陆测试数据库是否已经打开。
VM虚拟机下在LINUX上安装ORACLE 11G单实例数据库