1.安装centos7
虚拟机配置如下:
安装时必须安装GHOME桌面
安装完成后,以root用户登录,然后执行
#需要联网 yum update yum upgrade
2.安装java 环境
#查询出默认安装java rpm -qa | grep java #删除查询出结果 rpm -e --nodeps #安装java rpm -ivh jdk-7u80-linux-x64.rpm #配置环境变量 vim /etc/profile #在末尾添加 #set java environment JAVA_HOME=/usr/java/jdk1.7.0_80 JRE_HOME=/usr/java/jdk1.7.0_80/jre CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin:/usr/local/mysql/bin export JAVA_HOME JRE_HOME CLASS_PATH PATH
3.安装 Oracle 11R2
首先下载Oracle 11R2 安装包
linux.x64_11gR2_database_1of2.zip ../201807/~0,-4%.html
创建用户和用户组 groupadd oinstall #用户组 groupadd dba #用户组 useradd -g dba -g oinstall -m oracle #创建用户oracle,并加入dba,oinstall passwd oracle #设置密码 创建Oracle安装目录 mkdir -p /oracle/oraInventory #oracle 数据库配置目录 chown -R oracle:oinstall /oracle #设置目录所有者为 oinstall 用户组的 oracle 用户 chown -R oracle:oinstall /oracle/oraInventory 修改系统标识 vim /etc/redhat-release #编辑 把 CentOS Linux release 7.0.1406 (Core) 修改为 #CentOS Linux release 7.0.1406 (Core) Red Hat Enterprise Linux 6 修改系统内核 vim /etc/sysctl.conf #编辑,在最后添加以下代码 fs.aio-max-nr = 1048576 fs.file-max = 6815744 kernel.shmall = 2097152 kernel.shmmax = 536870912 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 = 1048576 net.ipv4.icmp_echo_ignore_broadcasts = 1 vim /etc/security/limits.conf #在末尾添加以下代码 oracle soft nproc 2047 oracle hard nproc 16384 oracle soft nofile 1024 oracle hard nofile 65536 配置Oracle用户环境变量 vim /home/oracle/.bash_profile #在最后添加以下代码 export ORACLE_BASE=/oracle #oracle 数据库安装目录 export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/db_1 #oracle 数据库路径 export ORACLE_SID=orcl #oracle 启动数据库实例名 export ORACLE_UNQNAME=$ORACLE_SID export PATH=$ORACLE_HOME/bin:/user/sbin:$PATH #添加系统环境变量 export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH #添加系统环境变量
安装Oracle数据库所需要的软件包
yum install gcc* gcc-* gcc-c++-* glibc-devel-* glibc-headers-* compat-libstdc* libstdc* elfutilslibelf-devel* libaio-devel* sysstat* unixODBC-* pdksh-*
4.重启下系统,以oracle身份登录系统
5.解压oracle安装包
unzip linux.x64_11gR2_database_1of2.zip ../201807/~0,-4%.html
6.
cd database
7.
export LANG=en_US #防止乱码
8.运行安装程序(不要使用XShell操作,直接在桌面打开终端操作)
./runInstaller
等待......
取消默认选择,点击next
点击yes
点击next
选择server class ,点击next
点击next
选择 Advanced install 点击 next
添加简体中文,点击next
点击next
设置好环境变量了,这里会自动填充路径,点击 next
默认Inventory Directory为/oraInventory,修改为/oracle/oraInventory 点击next
点击yes,弹框可能显示不出来,按方向键左键,按ENTER
点击next
点击next
配置字符集,点击 next
点击next
点击next
点击next
选择统一设置密码,点击 next
点击yes,弹框可能显示不出来,按方向键左键,按ENTER
点击next
勾选Ignore All,点击next
点击finish
进入安装过程
安装到 68%的时候会有如下提示,直接点击 continue,弹框可能无法展示,直接按ENTER
点击ok
以下窗口可能被缩成一条竖线在中间,用鼠标拉开即可看到,安装过程如出现窗口变暗,但是没有弹框弹出,即为此类情况
9.打开命令行窗口
su 输入 root 帐号密码,运行 /oracle/oraInvertory/orainstRoot.sh /oracle/product/11.2.0/dbhome_1/root.sh
10.安装完成后,把系统标识修改回来
vim /etc/redhat-release #编辑 把 #CentOS Linux release 7.0.1406 (Core) Red Hat Enterprise Linux 6 修改为: CentOS Linux release 7.0.1406 (Core)
11.登录Oracle
[oracle@localhost ~]$ lsnrctl stop #先关闭监听服务 [oracle@localhost ~]$ lsnrctl start #开启监听服务 [oracle@localhost ~]$ sqlplus / as sysdba #登入 SQL> shutdown immediate #立即关闭数据库服务(一般是关闭状态) SQL> startup #开启数据库服务(重要,必输) SQL> exit #退出 SQL> sqlplus scott/tiger@192.168.47.131/orcl #连接scott用户 SQL> select * from tab; #test查询表
12,使用PL/SQL连接时,可能会“ORA-12514 TNS 监听程序当前无法识别连接描述符中请求服务”
解决办法简述:
1.修改\oracle\product\11.2.0\db_1\network\admin\listener.ora中的(host)bt-199-039.bta.net.cn改为192.168.47.131
2.修改\oracle\product\11.2.0\db_1\network\admin\tnsnames.ora中的(host)bt-199-039.bta.net.cn 改为192.168.47.131
3.修改后,重启oracle,监听,并注册,主win10上的plsql就可以远程连接虚拟机上的数据库了.
具体操作步骤如下:
一、修改数据库服务器中listener.ora文件内容
[oracle@localhost admin]$ vim /oracle/product/11.2.0/db_1/network/admin/listener.ora 原始内容: # listener.ora Network Configuration File: /oracle/product/11.2.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521)) (ADDRESS = (PROTOCOL = TCP)(HOST = bt-199-039.bta.net.cn)(PORT = 1521)) ) ) ADR_BASE_LISTENER = /oracle
修改为 # listener.ora Network Configuration File: /oracle/product/11.2.0/db_1/network/admin/listener.ora # Generated by Oracle configuration tools. SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = orcl) (ORACLE_HOME = /oracle/product/11.2.0/db_1) (SID_NAME = orcl) ) ) LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.47.131)(PORT = 1521))) ADR_BASE_LISTENER = /oracle
修改数据库服务器中tnsnames.ora文件内容
[oracle@localhost admin]$ vim /oracle/product/11.2.0/db_1/network/admin/tnsnames.ora 原始内容: # tnsnames.ora Network Configuration File: /oracle/product/11.2.0/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. ORCL = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl) ) )
修改后的内容: # tnsnames.ora Network Configuration File: /oracle/product/11.2.0/db_1/network/admin/tnsnames.ora # Generated by Oracle configuration tools. orcl = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.47.131)(PORT = 1521)) ) (CONNECT_DATA = (SID = orcl) ) )
在数据库服务器中启动监听并更新注册
1、命令: [oracle@localhost ~]$ lsnrctl stop #先关闭监听服务 输出: LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-FEB-2017 21:19:42 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.78.130)(PORT=1521))) The command completed successfully [oracle@localhost ~]$ 2、命令: [oracle@localhost ~]$ lsnrctl start #开启监听服务 输出: LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-FEB-2017 21:24:22 Copyright (c) 1991, 2009, Oracle. All rights reserved. Starting /data/oracle/product/11.2.0/db_1/bin/tnslsnr: please wait... TNSLSNR for Linux: Version 11.2.0.1.0 - Production System parameter file is /data/oracle/product/11.2.0/db_1/network/admin/listener.ora Log messages written to /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521))) Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.78.130)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 19-FEB-2017 21:24:22 Uptime 0 days 0 hr. 0 min. 0 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521))) Services Summary... Service "orcl" has 1 instance(s). Instance "orcl", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully [oracle@localhost ~]$ 3、命令: [oracle@localhost ~]$ sqlplus / as sysdba #登入 输出: SQL*Plus: Release 11.2.0.1.0 Production on Sun Feb 19 21:27:40 2017 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SQL> 命令: SQL> shutdown immediate #立即关闭数据库服务 输出: Database closed. Database dismounted. ORACLE instance shut down. SQL> 命令: SQL> startup #开启数据库服务 输出: ORACLE instance started. Total System Global Area 1586708480 bytes Fixed Size 2213736 bytes Variable Size 939526296 bytes Database Buffers 637534208 bytes Redo Buffers 7434240 bytes Database mounted. Database opened. SQL> 命令: SQL> alter system register; #注册 输出: System altered. SQL> 命令: SQL> quit #登出 输出: Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@localhost ~]$ 命令: [oracle@localhost ~]$ lsnrctl status #查看监听状态 输出: LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 19-FEB-2017 21:37:20 Copyright (c) 1991, 2009, Oracle. All rights reserved. Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.78.130)(PORT=1521))) STATUS of the LISTENER ------------------------ Alias LISTENER Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production Start Date 19-FEB-2017 21:24:22 Uptime 0 days 0 hr. 12 min. 57 sec Trace Level off Security ON: Local OS Authentication SNMP OFF Listener Parameter File /data/oracle/product/11.2.0/db_1/network/admin/listener.ora Listener Log File /data/oracle/diag/tnslsnr/localhost/listener/alert/log.xml Listening Endpoints Summary... (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.78.130)(PORT=1521))) Services Summary... Service "orcl" has 1 instance(s). Instance "orcl", status UNKNOWN, has 1 handler(s) for this service... The command completed successfully [oracle@localhost ~]$