第二章 ORACLE安装 之一 XE版本(免费练习版本)安装

版权声明:转载请注明原博客地址,博文名称,原作者姓名。 https://blog.csdn.net/lihan7/article/details/82429226

Oracle 11G XE 安装笔记(新手向)

在oracle网站上注册下载linux 64bit的安装包(好像只有64bit的),注意系统一定要是64bit的 不然你就是在浪费时间。

首先说一下,本人的系统是centos5 我曾经实验过在ubuntu 12.04 以及amazon EC2(8G 硬盘免费版)上安装,都因为各种原因没有成功,大家有兴趣的可以实验一下。网上有很多指导帖子。

[oracle@RAC02 ~]$ lsb_release -a

LSB Version: :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch

Distributor ID: OracleServer

Description: Oracle Linux Server release 6.6

Release: 6.6

Codename: n/a

数据库版本

oracle-xe-11.2.0-1.0.x86_64.rpm.zip

oracle-xe-11.2.0-1.0.x86_64.rpm

安装过程

在安装之前要注意,oracle对于系统的空间是有要求的,安装前可以查看下:

一、使用free -m查看交换空间大小,oracle XE 要求至少有1.2G 的交换空间,扩充的方法在我另外一篇博文上已经说明。传送门 http://www.linuxidc.com/Linux/2012-08/66973.htm

使用df -h查看tmpfs的大小,oracle XE 在init.ora文件中给出了最低要求,默认是1G 。

这里我们要把tmpfs扩充为2G:

1.修改/etc/fstab文件:

找到此行:tmpfs                   /dev/shm                tmpfs   defaults      0 0

修改为:    tmpfs                   /dev/shm                tmpfs   defaults,size=2048M      0 0

2.重新加载tmpfs:

使用命令:

#umount /dev/shm; mount /dev/shm;

然后输入

df -h /dev/shm查看输出:

Filesystem            Size   Used    Avail Use% Mounted on

tmpfs                      2.0G  492M  1.6G  25%    /dev/shm

说明重新加载成功。 【Linux公社 http://www.linuxidc.com 】

修改/etc/hosts文件,添加如下内容:

127.0.0.10 hostname(hostname根据实际情况填写)

二、做完这些,我们还要做一些安装一些依赖包:

yum install libaio*

来安装libaio包

我的电脑显示结果为:

软件包 libaio-0.3.109-13.el7.x86_64 已安装并且是最新版本

正在解决依赖关系

--> 正在检查事务

---> 软件包 libaio-devel.x86_64.0.0.3.109-13.el7 将被 安装

之后解压安装包,

unzip oracle-xe-11.2.0-1.0.x86_64.rpm.zip

 进入Disk1文件夹

安装解压后的rpm包

rpm -ivh oracle-xe-11.2.0-1.0.x86_64.rpm

安装成功后会提示成功,然后以super user身份运行以下脚本进行配置:

# /etc/init.d/oracle-xe configure

包括http的端口,如果你的服务器上运行了tomcat 而且没有改过端口配置 要把默认的8080端口换掉以免冲突。

另外,程序还会要求你为默认管理员账户 sys 设置密码。随后会等待一段时间,请耐心。

输出如下:

This will configure on-boot properties of Oracle Database 11g Express

Edition. The following questions will determine whether the database should

be starting upon system boot, the ports it will use, and the passwords that

will be used for database accounts. Press <Enter> to accept the defaults.

Ctrl-C will abort.

Specify the HTTP port that will be used for Oracle Application Express [8080]:

Specify a port that will be used for the database listener [1521]:

Specify a password to be used for database accounts. Note that the same

password will be used for SYS and SYSTEM. Oracle recommends the use of

different passwords for each database account. This can be done after

initial configuration:

Confirm the password:

Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:

Starting Oracle Net Listener...Done

Configuring database...Done

Starting Oracle Database 11g Express Edition instance...Done

Installation completed successfully.

安装结束后,系统会自动建立一个名为oracle的用户,home dir位置在 /u01/app/oracle 也就是数据库安装的位置。

为了使用方便,我们可以把个人用户home目录下的.bashrc 和.bash_profile拷贝到该目录下,再用chown改变文件所属:

# chown oracle .bash_profile

# chown oracle .bashrc

# chmod 755 .bash_profile

# chmod 755 .bashrc

之后, 我们要设置一下环境变量:

三、修改/etc/profile文件,添加如下内容:

# Oracle Settings

TMP=/tmp; export TMP

TMPDIR=$TMP; export TMPDIR

ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE

ORACLE_HOME=$ORACLE_BASE/product/11.2.0/xe; export ORACLE_HOME

ORACLE_SID=XE; export ORACLE_SID

ORACLE_TERM=xterm; export ORACLE_TERM

PATH=/usr/sbin:$PATH; export PATH

PATH=$ORACLE_HOME/bin:$PATH; export PATH

TNS_ADMIN=$ORACLE_HOME/network/admin

LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH

CLASSPATH=$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

注意:以下几点:

XE版本里只能有一个instance, 我将SID修改了以后貌似会报错,所以SID就不用修改了。

BASE和HOME两个变量后尽量不要加斜线 '/' ,有可能会报错,虽然不知到为什么... 同时,TNS_ADMIN这个变量一定要有。

修改完后使用命令 # source /etc/profile 重新加载改文件。

输入 echo $ORACLE_BASE修改是否成功。

初始化数据库:

# su oracle

如果不知道密码 可以用 # passwd oracle重新设置

修改init.ora:

cd  /u01/app/oracle/product/11.2.0/xe/dbs/

cp init.ora initXE.ora

vi initXE.ora

将该文件修改成如下内容:

db_name='XE'

memory_target=1G

processes = 150

audit_file_dest='/u01/app/oracle/admin/orcl/adump'

audit_trail ='db'

db_block_size=8192

db_domain=''

db_recovery_file_dest='/u01/app/oracle/fast_recovery_area'

db_recovery_file_dest_size=2G

diagnostic_dest='/u01/app/oracle'

dispatchers='(PROTOCOL=TCP) (SERVICE=ORCLXDB)'

open_cursors=300

remote_login_passwordfile='EXCLUSIVE'

undo_tablespace='UNDOTBS1'

# You may want to ensure that control files are created on separate physical

# devices

control_files = ('/u01/app/oracle/oradata/', '/u01/app/oracle/oradata/')

compatible ='11.2.0'

切换只oracle用户 使用sqlplus链接数据库

sqlplus /nolog

进入sqlplus控制台

SQL> connect as sysdba

提示输入用户名密码: 使用sys/password登录

SQL> connect as sysdba;

Enter user-name: sys

Enter password:

Connected.

启动并装载数据库

SQL>  startup mount

11g xe版本已经内置了一个设置好的数据库 XE, 因此不许要手动创建数据库,但是需要初始化数据库结构

运行一下两行代码:

SQL> @?/rdbms/admin/catalog.sql

SQL> @?/rdbms/admin/catproc.sql

等待出现提示complete之后,进行下一步。

如果运行过程中出现database didn‘t open 则需要重新启动并装载数据库。

接下来创建用户,初始数据库中应当已经存在users表空间,因此直接插入数据就可以了:

SQL> create user myaccount

      2   identified by “mypassword”

      3   default tablespace users;

授权用户:

SQL> grant dba to myaccount;

之后可以exit然后用该用户登录。

插表测试:

SQL> create table test_table (txt varchar2(100) not null);

SQL> insert into test_table values('Hello world !');

插入数据成功后查询

SQL> select * from test_table;

如果查询成功,那么恭喜你,大功告成了!

本人也是新手,如果文章有什么写的不对的地方,欢迎指正。

----------------------------------------------------------------------------------------------------------------------------

一些问题:

如果出现错误:

ORA-01034: ORACLE not available

ORA-27101: shared memory realm does not exist

一般是由于数据库没有启动,需要以DBA身份登录数据库后输入startup

在做之前请确保/u01/app/oracle/product/11.2.0/xe/dbs/文件夹中 存在init<SID>.orc文件存在

ORA-00845:MEMORY_TARGET not supported on this system

请查看你的init.orc文件中memory_target项中的值是否小于tmpfs,否则请扩充tmpfs容量。

ORA-44410:XE edition single instance violation error

XE版本中只能有唯一一个instance,笔者安装时,程序自动生成了一个叫做XE的instance并且路径已经设置好,至于如何添加新的instance请高人指明。

或者

保证你环境变量没有以'/'结尾 同时TNS_ADMIN变量已经设置。至于为什么这么改..希望有高人也能告诉我。

ORA-01261:Parameter db_recovery_file_dest destination string connot be translated

ORA-01262:Stat failed on a file destination directory

关于这个错误,比较无语,在init.orc中,db_recovery_file_dest destination 这一项的初始值是"<ORACLE_BASE>/flash_recovery_area"

如果你只修改了<ORACLE_BASE>你就会得到这个错误,因为在$ORACLE_BASE下只有一个文件叫做fast_recovery_area,把后面的文件名修改匹配后,问题解决。

SQL> select * from V$version;

BANNER

--------------------------------------------------------------------------------

Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production

PL/SQL Release 11.2.0.2.0 - Production

CORE 11.2.0.2.0 Production

TNS for Linux: Version 11.2.0.2.0 - Production

NLSRTL Version 11.2.0.2.0 - Production

猜你喜欢

转载自blog.csdn.net/lihan7/article/details/82429226