Chinaunix首页 | 论坛 | 博客
  • 博客访问: 571503
  • 博文数量: 155
  • 博客积分: 7055
  • 博客等级: 少将
  • 技术积分: 1700
  • 用 户 组: 普通用户
  • 注册时间: 2004-11-22 11:40
文章分类

全部博文(155)

文章存档

2016年(1)

2011年(2)

2010年(1)

2009年(2)

2008年(9)

2007年(39)

2006年(58)

2005年(38)

2004年(5)

我的朋友

分类: LINUX

2007-04-04 18:19:59

//070302
oracle 安装.

1 在oracle网站上,免费注册后下载 Oracle Database 10g Express Universal Edition / oracle-xe-univ-10.2.0.1-1.0.i386.rpm , //下载速度有点慢


2 phpchina 一位朋友有个xe的官方的ppt安装说明,按照上面操作(设置环境变量时执行方式应为
. /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/oracle_env.sh
, PPT里有误). 关于oracle启动,PPT里没有写

文件:oracle-PHP_InstallFest_20070203_cn.zip
大小:449KB
下载:下载


3 关于安装的说明:
rpm安装后, 添加了oracle.dba用户组
修改了一些系统文件: /etc/sysctl.conf.
运行/etc/init.d/oracle-xe configure生成了/etc/sysconfig/oracle-xe.
启动脚本: /etc/init.d/oracle-xe

配置和启动

1 配置: /etc/init.d/oracle-xe configure

2 root用户执行 /etc/init.d/oracle-xe start 
(我第一次运行 没有任何提示.
原因是configure阶段,一个设置导致: /etc/sysconfig/oracle-xe: ORACLE_DBENABLED=false.
但脚本不给任何提示太不够意思
导致我不知如何是好,无头苍蝇瞎搞了好几天. )
故注意,在 oracle-xe configure时, 设置开机启动oracle为true.
输出为:
Starting Oracle Net Listener...Done
Configuring Database...Done //这一步会耗去不少时间.
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to ""

连接, 登录上oracle server
(比如 对应 mysql-server 有 phpMyAdmin / mysql)

1 用sqlplus. 用户名system, 密码为configure时配置的密码.

2 用PL/SQL Developer
客户端:PL/SQL Developer V6.0.4.906
(这个依赖于 oracle client,故先装了 Oracle Database client 10g Release 1 (10.1.0.2.0) )
安装上之后,要配置。不像mysql的客户端,指定了用户名,密码,服务器IP就可以连接。

如何配置:
a 使用oracle client后段安装程序的向导
b 直接修改配置文件 network/admin/tnsnames.ora:
一个例子:
TEST =
  (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 202.3.4.5)(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = XE)
    )
  )

对应java程序里的url是: jdbc:oracle:thin:@202.3.4.5:1521:XE
配置好之后,就可以使用pl/sql dev连接,输入用户名密码就可以登录了.

3 pl/sql dev 查看数据库存在的中文乱码
select userenv('language') from dual;
SIMPLIFIED CHINESE_CHINA.WE8ISO8859P1

在注册表里查找 NLS_LANG , 将其值改为上面的. 比如我的:
SIMPLIFIED CHINESE_CHINA.ZHS16GBK (original) -> SIMPLIFIED CHINESE_CHINA.WE8ISO8859P1

附一个 出错参考:
http://xzh2000.itpub.net/post/96/36127
ORA-00600: internal error code, arguments: [keltnfy-ldmInit], [46], [1], [], [], [], [], []
在10gR2+rhel4u1中,一般不要随便修改机器的名称,如果要修改机器名,稍一不慎重,就有可能会触发ORA-00600: [keltnfy-ldmInit],[46]这样的错误,查metalink没有任何信息,最严重的结果是实例无法启动,如果一定要修改机器名,需要修改的比较彻底,/etc/hosts, /etc/sysconfig/network这两个文件,如果忘了将/etc/hosts中127.0.0.1对应的机器修改成network文件中的一样,将会导致上面描述的错误。

附 /etc/init.d/oracle-xe 片断

学习是需要环境的. 以前学shell, perl等总是没劲.
其实今天发现, 这诸多开源软件中对于shell,perl等的使用, 正是学习的大好环境.
#hjh 为我的注释

# description: This is a program that is responsible for taking care of
# configuring the Oracle Database 10g Express Edition and its associated
# services.

RETVAL=0
ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server
ORACLE_OWNER=oracle
ORACLE_SID=XE
LSNR=$ORACLE_HOME/bin/lsnrctl
SQLPLUS=$ORACLE_HOME/bin/sqlplus
SU=/bin/su
export ORACLE_HOME
export ORACLE_SID
export PATH=$ORACLE_HOME/bin:$PATH
LOG="$ORACLE_HOME_LISTNER/listener.log"

export LC_ALL=C

if [ $(id -u) != "0" ]
then
echo "You must be root to run the configure script. Login as root and then run the
configure script."
exit 1
fi

CONFIG_NAME=oracle-xe
CONFIGURATION="/etc/sysconfig/$CONFIG_NAME"

# Source configuration
[ -f "$CONFIGURATION" ] && . "$CONFIGURATION"

#hjh 写配置文件的方法
write_sysconfig()
{
cat >"$CONFIGURATION" <
#This is a configuration file for automatic starting of the Oracle
#Database and listener at system startup.It is generated By running
#'/etc/init.d/oracle-xe configure'.Please use that method to modify this
#file

# ORACLE_DBENABLED:'true' means to load the Database at system boot.
ORACLE_DBENABLED=${ORACLE_DBENABLED:-false}

# LISTENER_PORT: Database listener
LISTENER_PORT=${LISTENER_PORT}

# HTTP_PORT : HTTP port for Oracle Application Express
HTTP_PORT=${HTTP_PORT}

# Configuration : Check whether configure has been done or not
CONFIGURE_RUN=${CONFIGURE_RUN}

EOF

if [ $? != 0 ]
then
return 1
fi
return 0
}

#hjh oracle-xe configure 时的提问
configure_ask()
{
cat <
Oracle Database 10g Express Edition Configuration
-------------------------------------------------
This will configure on-boot properties of Oracle Database 10g 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 to accept the defaults.
Ctrl-C will abort.

EOF

#get the http port value
while :
do
while [ 1 ]
do
echo -n Specify the HTTP port that will be used for Oracle Application Express [8080]:
read LINE
if [ -z $LINE ]
then
LINE=8080
fi
#hjh 0.0.0.0:25 与 :::8080 , 后者是cut不到 8080的. 前者可以
port=`netstat -n --tcp --listen | grep :$LINE | awk '{print $4}' | cut -d':' -f2`
if [ "$port" = "$LINE" ]
then
echo Port $port appears to be in use by another application.\
Please specify a different port.
else
break;
fi
done

case "$LINE" in
"")
break
;;
*[^0-9]*)
echo "Invalid http port: $LINE"
;;
*)
HTTP_PORT=$LINE
break
;;
esac
done

#hjh 这个牛嘀,是用来处理输入的密码的.
#get the database password
while :
do
echo -n "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:"
while [ 1 ]
do
#hjh set tty为不 echo input. 有一个方法破解, 把此script挂起,再进入
/bin/stty -echo > /dev/null 2>&1
temp=`echo $IFS`
export IFS="\n"
while [ 1 ]
do
read LINE
while [ -z "$LINE" ]
do
echo
echo -n "Password can't be null. Enter password:"
read LINE
done

result=`expr index "$LINE" [\'\"]`
if [ $result != 0 ];
then
echo
echo -n "The password you entered contains invalid characters. Enter password:"
else
break
fi
done
echo
echo -n "Confirm the password:"
read LINE1
echo
if [ "$LINE" != "$LINE1" ];
then
echo
echo -n "Passwords do not match. Enter the password:"
else
break
fi
done
/bin/stty echo > /dev/null 2>&1
ORACLE_PASSWORD=$LINE
export IFS=$temp
break;
done

# configure_perform()
#
# Instantantiate listener.ora,tnsnames.ora,and create the database,
# sets the password,start the listener,and adds database to inittab
# if necessary

configure_perform()
{
sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/network/admin/listener.ora
sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/network/admin/listener.ora
/bin/chown oracle:dba $ORACLE_HOME/network/admin/listener.ora

sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/network/admin/tnsnames.ora
sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/network/admin/tnsnames.ora
/bin/chown oracle:dba $ORACLE_HOME/network/admin/tnsnames.ora

sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/postDBCreation.sql
/bin/chown oracle:dba $ORACLE_HOME/config/scripts/postDBCreation.sql

if test $LISTENER_PORT -ne 1521
then
if [ -f /tmp/local_listener ]
then
#hjh $$ shell's pid
cat >/tmp/local_listener$$ <###########################################
# Registration of instance with listsner
###########################################
local_listener="(ADDRESS = (PROTOCOL=TCP) (HOST=%hostname%) (PORT=%port%))"
EOF
/bin/chmod 664 /tmp/local_listener$$
cat /tmp/local_listener$$ >> $ORACLE_HOME/config/scripts/init.ora
else
cat >/tmp/local_listener <###########################################
# Registration of instance with listsner
###########################################
local_listener="(ADDRESS = (PROTOCOL=TCP) (HOST=%hostname%) (PORT=%port%))"
EOF
/bin/chmod 664 /tmp/local_listener
cat /tmp/local_listener >> $ORACLE_HOME/config/scripts/init.ora
fi

if test -f /tmp/local_listener
then
rm -fr /tmp/local_listener
elif test -f /tmp/local_listener$$
then
rm -fr /tmp/local_listener$$
fi
#init.ora有点问题,没有上面的内容
sed -i "s/%port%/$LISTENER_PORT/g" $ORACLE_HOME/config/scripts/init.ora
sed -i "s/%hostname%/`hostname`/g" $ORACLE_HOME/config/scripts/init.ora
/bin/chown oracle:dba $ORACLE_HOME/config/scripts/init.ora

fi

#下面2个是类似的.启动浏览器访问.
sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/DatabaseHomePage.sh
/bin/chown oracle:dba $ORACLE_HOME/config/scripts/DatabaseHomePage.sh
sed -i "s/%httpport%/$HTTP_PORT/g" $ORACLE_HOME/config/scripts/readonlinehelp.sh
/bin/chown oracle:dba $ORACLE_HOME/config/scripts/readonlinehelp.sh

homedir=`echo $HOME`
if [ "$homedir" = "/root" ]
then
homedir=`sh -c "echo ~$USER"`
fi

if [ -f $ORACLE_HOME/bin/tnslsnr ]
then
echo -n "Starting Oracle Net Listener..."
#hjh su - run a shell with substitute user and group IDs
$SU -s /bin/bash $ORACLE_OWNER -c "$LSNR start" > /dev/null 2>&1
echo "Done"
fi

echo -n "Configuring Database..."
#hjh 后面有XE.sh的内容
$SU -s /bin/bash $ORACLE_OWNER -c "$ORACLE_HOME/config/scripts/XE.sh" > /dev/null 2>&1
#ORA-44410 这是个什么错误
err=`grep "ORA-44410" $ORACLE_HOME/config/log/*.log`
if test "$err" != ""
then
echo "Database Configuration failed. Look into $ORACLE_HOME/config/log for details"
exit 1
fi
#hjh 这个是修改sys, system 用户的密码
# 奇怪,which sqlplus找不到(未设置PATH),但man sqlplus有帮助. man的系统还不熟
echo alter user sys identified by \"$ORACLE_PASSWORD\"\; | $SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s / as sysdba" > /dev/null 2>&1
echo alter user system identified by \"$ORACLE_PASSWORD\"\; | $SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s / as sysdba" > /dev/null 2>&1
echo "Done"

#hjh 这个目录里放的是dbf文件,有6个
/bin/chmod -R 640 /usr/lib/oracle/xe/oradata/XE
/bin/chmod 750 /usr/lib/oracle/xe/oradata/XE
rm -fr $ORACLE_HOME/config/seeddb

if [ -f /etc/oratab ]
then
echo "XE:$ORACLE_HOME:N" >> /etc/oratab
else
echo "XE:$ORACLE_HOME:N" >> /etc/oratab
/bin/chown oracle:dba /etc/oratab
/bin/chmod 644 /etc/oratab
fi

echo -n "Starting Oracle Database 10g Express Edition Instance..."
pmon=`ps -ef | egrep pmon_$ORACLE_SID'\>' | grep -v grep`

if [ "$pmon" = "" ];
then
#hjh 配置好后startdb.sql就很简单了.就三句.
#connect / as sysdba
#startup
#exit
$SU -s /bin/bash $ORACLE_OWNER -c "$SQLPLUS -s /nolog @$ORACLE_HOME/config/scripts/startdb.sql" > /dev/null 2>&1
fi
echo "Done"
echo "Installation Completed Successfully."
return 0
}

Starting Oracle Net Listener...Done
Configuring Database...Done
Starting Oracle Database 10g Express Edition Instance...Done
Installation Completed Successfully.
To access the Database Home Page go to ""

#hjh 建立一些目录,sqlplus连接上,并执行XE.sql, sql文件是一个套一个,至少三层
# 但这些sql, 对于了解oracle的sql语法是有用的.
XE.sh
#!/bin/sh
mkdir -p /usr/lib/oracle/xe/app/oracle/admin/XE/adump
mkdir -p /usr/lib/oracle/xe/app/oracle/admin/XE/bdump
mkdir -p /usr/lib/oracle/xe/app/oracle/admin/XE/cdump
mkdir -p /usr/lib/oracle/xe/app/oracle/admin/XE/dpdump
mkdir -p /usr/lib/oracle/xe/app/oracle/admin/XE/pfile
mkdir -p /usr/lib/oracle/xe/app/oracle/admin/XE/udump
mkdir -p /usr/lib/oracle/xe/app/oracle/admin/cfgtoollogs/dbca/XE
mkdir -p /usr/lib/oracle/xe/app/oracle/admin/XE/dbs
mkdir -p /usr/lib/oracle/xe/app/oracle/flash_recovery_area
mkdir -p /usr/lib/oracle/xe/oradata/XE
ORACLE_SID=XE; export ORACLE_SID
/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/sqlplus -s /nolog @/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/config/scripts/XE.sql

#hjh 好像修改了密码
XE.sql
set verify off
DEFINE sysPassword = "oracle"
DEFINE systemPassword = "oracle"
host /usr/lib/oracle/xe/app/oracle/product/10.2.0/server/bin/orapwd file=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/dbs/orapwXE password=&&sysPassword force=y
@/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/config/scripts/CloneRmanRestore.sql
@/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/config/scripts/cloneDBCreation.sql
@/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/config/scripts/postScripts.sql
@/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/config/scripts/postDBCreation.sql
exit


阅读(6975) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~