您的位置:首页 > 数据库 > Oracle

oracle在centos7中配置自启动和远程连接(plsql)

2017-03-11 22:29 639 查看
先把几个常见命令贴出来:

启动监听:lsnrctl start
查看监听:lsnrctl status
停止监听:lsnrctl stop

sqlplus "/as sysdba"
或者
sqlplus /nolog;
connect /as sysdba

然后输入startup
就可以正常的启动资料库了。

另外停止资料库的指令如下:
shutdown immediate


oracle 远程连接配置

我先把用到的命令都放在这了,如果整个安装oracle都是没有问题的,其实你就可以如下操作。说实话我是被网上的资料害惨了,各种改配置的,其实没必要,我第二次安装的时候发现其实并没有那么麻烦,就是如下几步。

1、启动监听;lsnrctl start

2、打开oracle连接

sqlplus /nolog;

connect /as sysdba

测试:

lsnrctl status

见到如下信息就可以了



3、oracle客户端配置

找到这个位置

F:\dev\plsql developer\oracle\OraClient Lite\product\11.2.0\client_lite\network\admin

修改这个文件

tnsnames.ora

目录下其他的文件可以不在意,我的那些都是空。

LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.186.133)(PORT = 1521))

ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.186.133)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
)
)


4、plsql 的配置

打开plsql

点击cancel

接着配置如下 配置你的oracle_home,就是你oracle客户端地址



接着如下操作database有下拉选择



帐号和密码填好后即可以使用了。

我以前也查了不少资料,很复杂,这也要那也要,但是我重装oracle这次就是这么简单!

oracle自启动配置

下面就是让oracle在centos7中自启动,其实就是将上面的监听和oracle启动一同写到自启动服务中。

1、键入如下命令

vi /etc/oratab


没有oratab文件的添加如下

#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.
#
ORCL:/usr/local/oracle/oracle/product/11.2.0/db_1:Y


2、键入命令“vi /etc/rc.d/rc.local”添加如下

su oracle -lc "/usr/local/oracle/oracle/product/11.2.0/db_1/bin/lsnrctl start"
su oracle -lc "/usr/local/oracle/oracle/product/11.2.0/db_1/bin/dbstart"


3、新建Oracle服务启动脚本

vi /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=/usr/local/oracle/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_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


切记不要少如下内容,否则chkconfig 不可使用

#!/bin/sh
# chkconfig: 345 61 61


4、增加 oracle服务控制脚本执行权限

chmod +x /etc/rc.d/init.d/ oracle


5、将 oracle服务加入到系统服务

chkconfig --add  oracle


检查 oracle服务是否已经生效

chkconfig --list  oracle




启动oracle

service oracle start


停止oracle服务

service oracle stop
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息