如何在linux操作系统中安装oracle数据库,并设置开机自启动
1、 ping www.baidu.com 查看是否联网成功
2、 不能联网,就将ip修改为动态dhcp模式使之能链接成功。
3、 Vi /etc/hosts 写上ip地址与主机名
4、 yum install libXp* xterm* unixODBC* sysstat* make* libstdc++* libgomp* libgcc* libaio* kernel-headers* glibc* gcc* elfutils* binutils* bind bind-devel bind-chroot caching-nameserver compat-libcap1* compat-libstdc++-33* openssh* xdpyinfo vi unzip
在线安装Oracle所需的依赖包;若是包安装不完整,则会在安装oracle数据库时被检查出来,彼时就需要重新回到root下进行安装。
5、[[email protected] ~]# rpm -ivh pdksh-5.2.14-30.x86_64.rpm
安装此包
6、[[email protected] ~]#vi /etc/selinux/config
永久关闭selinux防火墙,如图所示进行更改。需要注意的是,linux的防火墙比较多;
[[email protected] ~]# groupadd -g 2001 oinstall
[[email protected] ~]# groupadd -g 2002 dba
[[email protected] ~]# groupadd -g 2003 oper
[[email protected] ~]# useradd -m -u 2001 -g oinstall -G dba,oper -d /home/oracle -s /bin/bash -c "Oracle Software Owner" oracle
[[email protected] ~]# passwd oracle
更改用户 oracle 的密码 。
新的 密码:
无效的密码: 它基于字典单词
无效的密码: 过于简单
重新输入新的 密码:
passwd: 所有的身份验证令牌已经成功更新。
[[email protected] ~]# mkdir -p /u01/app/oracle
[[email protected] ~]# chown -R oracle:oinstall /u01
[[email protected] ~]# chmod -R 775 /u01
[[email protected] ~]#mount /dev/vg_01/lv_01 /u01
将此逻辑券挂载在/u01下
[[email protected] ~]# su - oracle
切换到oracle下更改其家目录下的环境变量
[[email protected] ~]$ vi .bash_profile
将如下代码追加到该文件下,保存退出!
export PATH
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.4/dbhome_1
export ORACLE_SID=VDEDU # (这里注意输入自己设的SID)
export ORACLE_TERM=xterm
export PATH=/usr/sbin:$PATH
export PATH=/u01/app/ogg:$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=/u01/app/ogg:$ORACLE_HOME/lib:/lib:/usr/lib:$LD_LIBRARY_PATH
export CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
export NLS_DATE_FORMAT="yyyy-mm-dd HH24:MI:SS"
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LANG=C
export ORACLE_UNQNAME=VDEDU # 同上
注意SID 与ORACLE_UNONAME都要设置!否则后续oracle安装上后,不能对用户进行解锁。
[[email protected] ~]source .bash_profile 刷新一下文件
[[email protected] ~]su -
重新切换到root用户,
[[email protected] ~]#vi /etc/sysctl.conf
将如下代码追加到该文件下,保存退出!
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048586
[[email protected] ~]# /sbin/sysctl -p
检查配置是否出现问题
[[email protected] ~]# vi /etc/security/limits.conf
将如下代码追加到该文件下。。。
oracle soft nproc 2047 # 警告设定所有用户最大打开进程数为2047
oracle hard nproc 16384 # 严格设定所有用户最大打开进程数为16384
oracle soft nofile 1024 # 警告设定所有用户最大打开文件数为1024
oracle hard nofile 65536 # 严格设定所有用户最大打开文件数为65536
#soft 表示警告的设定,可以超过这个设定值,但是超过会有警告信息
#hard 表示严格的设定,必定不能超过这个设定的值
[[email protected] ~]# vi /etc/pam.d/login
session required /lib64/security/pam_limits.so
#要使 limits.conf 文件配置生效,必须要速确保pam_limits.so文件被加入到启动文件中。
#查看 /etc/pam.d/login 文件中有:
#session required /lib/security/pam_limits.so
禁用防火墙
在root用户下将解压缩后的文件database移动到/u01下
在虚拟机界面->系统->注销root->切换到oracle用户
Cd /u01/database
./runInstaller
开始配置oracle数据库:
若是出现上诉图片问题,则通过快照回到root账户注销之前,从新在线安装yum。
Sqlplus / as sysdba
Select table_name from user_tables;
设置开机自启动:默认的单机oracle数据库中,oracle不会随着操作系统的启动而启动,需要我们手动启动。为了减少麻烦,下面我们通过修改文件,达到开机自启动的效果;
1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用。
[[email protected] ~]# vi /etc/oratab
wushucheng:/u01/app/oracle/product/11.2.4/dbhome_1:Y
在 /etc/init.d/ 下创建文件oracle,内容如下:
[[email protected] ~]# vi /etc/init.d/oracle
#!/bin/sh
# chkconfig: 35 80 10
# description: Oracle auto start-stop script.
#
# Set ORA_HOME to be equivalent to the $ORACLE_HOME
# from which you wish to execute dbstart and dbshut;
#
# Set ORA_OWNER to the user id of the owner of the
# Oracle database in ORA_HOME.
ORA_HOME=/u01/app/oracle/product/11.2.4/dbhome_1
ORA_OWNER=oracle
LOGFILE=/var/log/oracle.log
echo "#################################" >> ${LOGFILE}
date +"### %T %a %D: Run Oracle" >> ${LOGFILE}
if [ ! -f ${ORA_HOME}/bin/dbstart ] || [ ! -f ${ORA_HOME}/bin/dbshut ]; then
echo "Error: Missing the script file ${ORA_HOME}/bin/dbstart or ${ORA_HOME}/bin/dbshut!" >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
exit
fi
start(){
echo "###Startup Database..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbstart ${ORA_HOME}"
echo "###Done."
echo "###Run database control..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl start dbconsole"
echo "###Done."
}
stop(){
echo "###Stop database control..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/emctl stop dbconsole"
echo "###Done."
echo "###Shutdown Database..."
su - ${ORA_OWNER} -c "${ORA_HOME}/bin/dbshut ${ORA_HOME}"
echo "###Done."
}
case "$1" in
'start')
start >> ${LOGFILE}
;;
'stop')
stop >> ${LOGFILE}
;;
'restart')
stop >> ${LOGFILE}
start >> ${LOGFILE}
;;
esac
date +"### %T %a %D: Finished." >> ${LOGFILE}
echo "#################################" >> ${LOGFILE}
echo ""
3.改变文件权限
[[email protected] ~]# chmod 755 /etc/init.d/oracle
4.添加服务
[[email protected] ~]# chkconfig --level 35 oracle on
5.需要在关机或重启机器之前停止数据库,做一下操作
[[email protected] ~]# ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle
[[email protected] ~]# ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle
6.重新启动
[[email protected] ~]#reboot