CentOS7环境下安装oracle数据库
一、配置yum源
- 跳转到/etc/yum.repos.d (cd /etc/yum.repos.d)
- 下载载oracle yum源
wget http://yum.oracle.com/public-yum-ol7.repo
- 下载阿里yum源
curl -o base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
二、下载oracle秘钥
wget https://yum.oracle.com/RPM-GPG-KEY-oracle-ol7 -O /etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
三、Oracle安装环境准备
输入yum list | grep oracle 可以看到有
oracle-rdbms-server-11gR2-preinstall.x86\_64
安装先导文件
yum -y install oracle-rdbms-server-11gR2-preinstall
安装补丁文件
yum -y install elfutils-libelf-devel
四、关闭selinux和防火墙
__ 不建议关闭selinux和防火墙__
防火墙开放端口:
firewall-cmd --zone=public --add-port=1521/tcp --permanent
关闭防火墙:
systemctl stop firewalld.service
关闭selinux:
跳转到selinux文件夹下 cd /etc/selinux
vim config
修改SELINUX=enforcing为SELINUX=disabled
五、配置中文字体
新建文件夹
mkdir -p /usr/share/fonts/zh_CN/TrueType
将中文字体文件上传到该文件夹下,若已上传到服务器上可以执行
cp zysong.ttf /usr/share/fonts/zh\_CN/TrueType
将文件复制到指定文件夹下
运行指令 xhost
运行指令 xhost +
[root@localhost ~\]# xhost
access control enabled, only authorized clients can connect
SI:localuser:root
[root@localhost ~\]# xhost +
access control disabled, clients can connect from any host
六、修改Oracle账户密码
执行命令
cat /etc/passwd
可以看到 最下面有个
oracle:x:54321:54321::/home/oracle:/bin/bash
修改oracle 密码
passwd oracle
七、上传数据库安装文件
在根目录下,新建文件夹oracle,将解压后的oracle安装文件上传到该文件夹下。
八、分配权限
执行命令:
chmod -R 777 /oracle
九、安装数据库
切换到oracle账号,并跳转到安装文件目录下,运行 runInstaller 文件 (./runInstaller)
进入oracle安装程序。
其中在检查环境中,遇到依赖包没有检测到,可以依次用命令
yum list | grep 缺失的依赖包,
Yum install 确实的依赖包,进行安装,当全部都安装好后,可以忽略这一项,直接下一步
其中可能会遇到错误 ins_emagent.mk
修改文件,将红色部分添加上去
vim ins_emagent.mk
#===========================
# emdctl
#===========================
$(SYSMANBIN)emdctl:
$(MK_EMAGENT_NMECTL) -lnnz11
十、配置环境变量
配置环境变量 .base_profile 隐藏文件(这个是oracle账号的环境变量)
vim /home/oracle/.base_profile
添加以下文本
export ORACLE_BASE=/home/oracle/app/oracle;
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1;
export ORACLE_SID=orcl;
export PATH=$ORACLE_HOME/bin:$PATH;
十一、设置数据库自启
- 修改oratab文件以root身份进入系统,通过vi命令打开文件vi /etc/oratab进入vi编辑器后,找到
“orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:N”,改为“orcl:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y”。修改完成后,保存退出vi
# This file is used by ORACLE utilities. It is created by root.sh
# and updated by the Database Configuration Assistant when creating
# a database.
# A colon, ':', is used as the field terminator. A new line terminates
# the entry. Lines beginning with a pound sign, '#', are comments.
#
# Entries are of the form:
# $ORACLE_SID:$ORACLE_HOME:<N|Y>:
#
# The first and second fields are the system identifier and home
# directory of the database respectively. The third filed indicates
# to the dbstart utility that the database should , "Y", or should not,
# "N", be brought up at system boot time.
#
# Multiple entries with the same $ORACLE_SID are not allowed.
#
#
#orcl11g:/home/oracle/app/oracle/product/11.2.0/dbhome_1:N
orcl11g:/home/oracle/app/oracle/product/11.2.0/dbhome_1:Y
键入命令“vi /etc/rc.d/rc.local”
在vi编辑器中,添加:
# The this to bring down Oracle Net Listener
ORACLE_HOME_LISTNER=$1
# 将此处的 ORACLE_HOME_LISTNER=$1 修改为
ORACLE_HOME_LISTNER=$ORACLE_HOME
if [ ! $ORACLE_HOME_LISTNER ] ; then
echo "ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener"
echo "Usage: $0 ORACLE_HOME"
else
LOG=$ORACLE_HOME_LISTNER/listener.log
注:其中/home/oracle/app/oracle/product/11.2.0/dbhome_1 为ORACLE_HOME
- oracle启动绑定监听器
修改dbstart和dbshut启动关闭脚本,使其启动数据库的同时也自动启动监听器(即启动数据库时启动监听器,停止数据库时停止监听器):
vim /oracle/product/11.2.0/dbhome_1/bin/dbstart
找到下面的代码,在实际脚本代码的同样也修改dbshut脚本:
vim /oracle/product/11.2.0/dbhome_1/bin/dbshut
# The this to bring down Oracle Net Listener
ORACLE_HOME_LISTNER=$1 #将此处的 ORACLE_HOME_LISTNER=$1 修改为
ORACLE_HOME_LISTNER=$ORACLE_HOME
if [ ! $ORACLE_HOME_LISTNER ] ; then
echo "ORACLE_HOME_LISTNER is not SET, unable to auto-stop Oracle Net Listener"
echo "Usage: $0 ORACLE_HOME"
else
LOG=$ORACLE_HOME_LISTNER/listener.log
- 新建Oracle服务启动脚本
vim /etc/init.d/oracle
新建一个以oracle命名的文件,并将以下脚本代码复制到文件里
#!/bin/sh
# chkconfig: 345 61 61
# description: Oracle 11g R2 AutoRun Servimces
# /etc/init.d/oracle
#
# Run-level Startup script for the Oracle Instance, Listener, and
# Web Interface
export ORACLE_BASE=/home/oracle/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export ORACLE_SID=ORCL
export PATH=$PATH:$ORACLE_HOME/bin
ORA_OWNR="oracle"
# if the executables do not exist -- display error
if [ ! -f $ORACLE_HOME/bin/dbstart -o ! -d $ORACLE_HOME ]
then
echo "Oracle startup: cannot start"
exit 1
fi
# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display
case "$1" in
start)
# Oracle listener and instance startup
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbstart
echo "Oracle Start Succesful!OK."
;;
stop)
# Oracle listener and instance shutdown
su $ORA_OWNR -lc $ORACLE_HOME/bin/dbshut
echo "Oracle Stop Succesful!OK."
;;
reload|restart)
$0 stop
$0 start
;;
*)
echo $"Usage: `basename $0` {start|stop|reload|reload}"
exit 1
esac
exit 0
保存退出
- 检查一下脚本能否正确执行
cd /etc/rc.d/init.d
./oracle start
./oracle stop
- 加入自动启动行列
执行如下命令:
chmod 750 /etc/rc.d/init.d/oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc2.d/S61oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc3.d/S61oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc4.d/S61oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc0.d/K61oracle
ln -s /etc/rc.d/init.d/oracle /etc/rc6.d/K61oracle
chkconfig –level 234 oracle on
chkconfig –add oracle
参考: