目录
一、oracle自启动
下面就是让oracle在centos7中自启动
1、修改/etc/oratab文件
以root身份登录到linux系统,编辑/etc/oratab文件
[root@oracle ~]# vi /etc/oratab
修改前
修改后
2、修改/etc/rc.d/rc.local文件
[root@oracle ~]# vi /etc/rc.d/rc.local
添加下列参数:
su oracle -lc "/opt/oracle/12c/bin/lsnrctl start"
su oracle -lc "/opt/oracle/12c/bin/bin/dbstart"
其中第一行因为lsnrctl之后有空格,需要引号,第二行加不加引号都可以。修改完保存退出即可。
如果是在以前的centos版本中,这样就可以了。但是centos7 的/etc/rc.local不会开机执行,认真查看/etc/rc.local文件的内容就发现问题的原因了
[root@oracle ~]# cat /etc/rc.d/rc.local
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
翻译一下:
这个文件是为了兼容性的问题而添加的。
强烈建议创建自己的systemd服务或udev规则来在开机时运行脚本而不是使用这个文件。
与以前的版本引导时的并行执行相比较,这个脚本将不会在其他所有的服务后执行。
请记住,你必须执行“chmod +x /etc/rc.d/rc.local”来确保确保这个脚本在引导时执行。
查看一下/etc/rc.d/rc.local的权限
[root@oracle ~]# ll /etc/rc.d/rc.local
-rw-r--r-- 1 root root 571 7月 19 17:39 /etc/rc.d/rc.local
发现没有执行权限,按照说明的内容执行命令:
[root@oracle ~]# chmod +x /etc/rc.d/rc.local
[root@oracle ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 571 7月 19 17:39 /etc/rc.d/rc.local
重启机器
[root@oracle ~]# reboot #重启机器,确认结果
3、重启机器,确认自启动结果
以oracle用户,打开一个终端,su - oralce 切换用户的时候,中间要有-,而且-的两边有空格,才能正确切换到oracle用户,否则会出现用户为找到,用户不存在错误,或报lsnrctl start 命令未找到 或者bash:lsnrctl:command not found.
[root@oracle ~]# su - oracle
上一次登录:四 7月 19 17:54:21 CST 2018pts/1 上
[oracle@oracle ~]$ lsnrctl status # 查看监听状态
LSNRCTL for Linux: Version 12.1.0.2.0 - Production on 19-JUL-2018 17:56:13
Copyright (c) 1991, 2014, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracle)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.1.0.2.0 - Production
Start Date 19-JUL-2018 17:52:43
Uptime 0 days 0 hr. 4 min. 21 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /opt/oracle/12c/network/admin/listener.ora
Listener Log File /opt/oracle/diag/tnslsnr/oracle/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=oracle)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))
The listener supports no services
The command completed successfully
查看oracle服务状态
[oracle@oracle ~]$ ps -ef |grep ora
oracle 1416 1 0 17:52 ? 00:00:00 /opt/oracle/12c/bin/tnslsnr LISTENER -inherit
root 1570 1505 0 17:54 pts/1 00:00:00 su oracle
oracle 1572 1570 0 17:54 pts/1 00:00:00 bash
root 1663 1635 0 17:55 pts/1 00:00:00 su - oracle
oracle 1664 1663 0 17:55 pts/1 00:00:00 -bash
oracle 1823 1664 0 17:58 pts/1 00:00:00 ps -ef
oracle 1824 1664 0 17:58 pts/1 00:00:00 grep --color=auto ora
确认自启动成功。另外再说一下,虽然此方法实现了自启动,但在学习的过程中,还看到了其他的方法实现自启动,可自己进行实践和总结。谢谢!