自动删除日志脚本文件下载地址:
链接:http://pan.baidu.com/s/1mg0EnQo 密码:4uit
第一部分 安装与配置
数据库安装前的准备工作
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-em1 #配置IP地址 DEVICE=em1 #此处实验对象为DELL服务器,对应的网卡设备名为em,IBM为eth HWADDR=00:0C:29:59:6E:BF #当不小心删除了MAC地址后,可通过ip a命令查看 TYPE=Ethernet ONBOOT=yes BOOTPROTO=no IPADDR=172.16.2.20 NETMASK=255.255.0.0 GATEWAY=172.16.1.1 DNS1=202.106.0.20 [root@localhost ~]# vim /etc/sysconfig/network NETWORKING=yes HOSTNAME=db [root@localhost ~]# vim /etc/hosts #添加域名解析 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 172.16.2.20 db [root@localhost ~]#reboot #重启系统
第一步:解压并安装数据库
[root@db ~]#tar -jxpvf /home/ora11.2.0.3.8_cluster.tgj -C / #解压oracle数据库到根目录,大C指定文件解压目录
第二步:配置数据库参数
[root@db ~]# su - oracle #切换到oracle用户 [oracle@db ~]$ sqlplus / as sysdba #进入oracle数据库 SQL*Plus: Release 11.2.0.3.0 Production on Wed Nov 18 15:40:15 2015 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to an idle instance. SQL> create pfile from spfile; #创建pfile文件(pfile文件的作用是方便计算机可读,也就是0和1),第一次进入数据库时均需要创建此文件 File created. SQL> startup ORA-00845: MEMORY_TARGET not supported on this system #启动数据库,若出现以上提示(需要给操作系统预留内存空间,不能让数据库独占内存)请修改initgnnt.ora文件,方法如下 SQL> ! #返回到oracle用户 [oracle@db ~]$ vim /opt/ora11/product/11.2/dbs/initgnnt.ora #修改initgnnt.ora配置文件(大小视物理内存而定,一定不能等于物理内存) .................................................................. *.memory_max_target=8g *.memory_target=8g .................................................................. *.sga_max_size=8g .................................................................. [oracle@db ~]$sqlplus / as sysdba #再次进入oracle数据库 SQL> create spfile from pfile; #创建spfile文件(spfile文件的作用是读取pfile文件的内容并更新修改的内容,也就是更新initgnnt.ora配置文件的内容让计算机可读) SQL> startup #数据库打开成功 ORACLE instance started. Total System Global Area 8551575552 bytes Fixed Size 2245480 bytes Variable Size 5066722456 bytes Database Buffers 3472883712 bytes Redo Buffers 9723904 bytes Database mounted. Database opened. SQL>select status from v$instance; #查看数据库状态,显示‘open’代表正常 STATUS ------------ OPEN
第三步:监听数据库
[oracle@db ~]$lsnrctl start #开启数据库监听服务 SQL>!lsnrctl status 或[oracle@localhost ~]$ lsnrctl status #查看监听状态 #监听数据库,若提示以下内容,请修改listener.ora和tnsnames.ora文件 LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 18-NOV-2015 17:46:36 Copyright (c) 1991, 2011, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 111: Connection refused Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dbi)(PORT=1521))) TNS-12545: Connect failed because target host or object does not exist TNS-12560: TNS:protocol adapter error TNS-00515: Connect failed because target host or object does not exist Linux Error: 111: Connection refused SQL>! #返回到oracle用户 [oracle@localhost admin]$ vim listener.ora # listener.ora Network Configuration File: /opt/ora11/product/11.2/network/admin/listener.ora # Generated by Oracle configuration tools. ......................................................................................... LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = db)(PORT = 1521)) #将HOST改为db ) ) [oracle@localhost admin]$ vim tnsnames.ora # tnsnames.ora Network Configuration File: /opt/ora11/product/11.2/network/admin/tnsnames.ora # Generated by Oracle configuration tools. GNNT = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = db)(PORT = 1521)) #将HOST改为db (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = gnnt) ) ) [oracle@db ~]$lsnrctl start #如果数据库监听已启动,此命令可以省略 SQL>!lsnrctl status #最后一行显示The command completed successfully,代表监听成功 LSNRCTL for Linux: Version 11.2.0.3.0 - Production on 18-NOV-2015 17:28:52 Copyright (c) 1991, 2011, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.3.0 - Production Start Date 18-NOV-2015 12:41:04 Uptime 0 days 4 hr. 47 min. 47 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /opt/ora11/product/11.2/network/admin/listener.ora Listener Log File /opt/ora11/diag/tnslsnr/db/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521))) (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=db)(PORT=1521))) Services Summary... Service "PLSExtProc" has 1 instance(s). Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service... Service "gnnt" has 2 instance(s). Instance "gnnt", status UNKNOWN, has 1 handler(s) for this service... Instance "gnnt", status READY, has 1 handler(s) for this service... Service "gnntXDB" has 1 instance(s). Instance "gnnt", status READY, has 1 handler(s) for this service... The command completed successfully
第四步:添加自动删除日志文件脚本
[root@db ~]#su - oracle [oracle@db]$cp /media/linux/deletearchivelogs.sh /media/linux/rman_cmd /home/oracle #/media/linux/代表U盘中的目录,粘贴的位置为/home/oracle [oracle@db]$chmod +x /home/oracle/deletearchivelogs.sh #给deletearchivelogs.sh文件添加可执行权限 [oracle@db]$ ll /home/oracle 总用量 8 -rwxr-xr-x 1 root root 439 11月 18 16:44 deletearchivelogs.sh -rwxr-xr-x 1 root root 118 11月 18 16:44 rman_cmd [oracle@db]$vim /home/oracle/deletearchivelogs.sh #修改IP地址为本地IP地址 /sbin/ip add show dev bond0 | grep -iq '172.16.2.20' [oracle@db ~]#crontab -e #添加自动删除日志脚本,如果出现计划任务无法保存时,则说明时间不同步,只需同步时间即可 0 5 * * * /home/oracle/deletearchivelogs.sh > /dev/null 2>&1 [root@db home]# crontab -l #查看计划执行任务 0 5 * * * /home/oracle/deletearchivelogs.sh > /dev/null 2>&1 分 时 日 月 周 也就是每天凌晨5点执行删除日志操作
第五步:关闭数据库
[root@db ~]# su - oracle #切换到oracle用户 [oracle@db ~]$ sqlplus / as sysdba #进入oracle数据库 SQL > shutdown immediate; #关闭数据库 Database closed. Database dismounted. ORACLE instance shut down.
第二部分 卸载
1、关闭数据库
[root@db ~]# su - oracle #切换到oracle用户 [oracle@db ~]$ sqlplus / as sysdba #进入oracle数据库 SQL > shutdown abort; #关闭数据库
2、关闭监听
[oracle@db ~]$lsnrctl stop #关闭数据库监听服务
3、删除数据库安装目录
[root@hq20 ~]# cd /opt [root@hq20 opt]# ls ora11 rh [root@hq20 opt]# rm -fr ora11/
补充:
1、使用history查看之前所使用过的命令。
2、如果发现数据库每隔一段时间就会重启,这时候只需要关掉bmc-watchdog服务器
[root@localhost ~]#chkconfig bmc-watcgdog off