liunx下安装SqlPlus并连接远程Oralce服务器

liunx下安装Sql*Plus并连接远程Oralce服务器

  1. 环境

    客户端:Ubuntu18.04LTS

    服务端:Centos7 Oracle12c

  2. 下载oracle sqlplus

    []: https://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html

    根据自己版本信息,下载合适的版本:

    oracle-instantclient18.3-basic-18.3.0.0.0-1.x86_64.rpm

    oracle-instantclient18.3-sqlplus-18.3.0.0.0-1.x86_64.rpm

    oracle-instantclient18.3-devel-18.3.0.0.0-1.x86_64.rpm

  3. 安装alien工具

    alien工具是将rpm包转换为deb包的工具

    $ sudo apt install alien
    
  4. 安装rpm包

    依次安装这三个rpm包:

    sudo alien -i oracle-instantclient18.3-*.rpm

    eric@ray:~/Downloads/sqlplus
    $ sudo alien -i oracle-instantclient18.3-devel-18.3.0.0.0-1.x86_64.rpm 
    	dpkg --no-force-overwrite -i oracle-instantclient18.3-devel_18.3.0.0.0-2_amd64.deb
    (Reading database ... 219747 files and directories currently installed.)
    Preparing to unpack oracle-instantclient18.3-devel_18.3.0.0.0-2_amd64.deb ...
    Unpacking oracle-instantclient18.3-devel (18.3.0.0.0-2) over (18.3.0.0.0-2) ...
    Setting up oracle-instantclient18.3-devel (18.3.0.0.0-2) ...
    
    
  5. 编辑sqlplus配置文件

    成功安装rpm包后,oracle客户端的默认路径为:

    eric@ray:/usr/lib/oracle/18.3/client64/lib
    $ ls
    glogin.sql             libmql1.so       libocijdbc18.so   network
    libclntshcore.so.18.1  libnnz18.so      libons.so         ojdbc8.jar
    libclntsh.so           libocci.so       liboramysql18.so  ottclasses.zip
    libclntsh.so.18.1      libocci.so.18.1  libsqlplusic.so   xstreams.jar
    libipc1.so             libociei.so      libsqlplus.so
    

    编辑配置文件ld.so.conf

    eric@ray:/usr/lib/oracle/18.3/client64/lib
    $ sudo vim /etc/ld.so.conf
    
    #在文件尾部添加--根据自己实际情况
    /usr/lib/oracle/18.3/client64/lib
    
  6. 配置oracle环境变量

    编辑配置文件.bashrc,在文件末尾加上:

    #sqlplus remote configure
    export ORACLE_HOME=/usr/lib/oracle/18.3/client64
    export TNS_ADMIN=$ORACLE_HOME
    export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/loacl/lib:$LD_LIBRARY_PATH
    #export SQLPATH=$ORACLE_HOME
    #export NLS_LANG=AMERICAN_CHINA.ZHS16GBK
    export PATH=$PATH:$ORACLE_HOME/bin 
    

    保存,使生效:source .bashrc

  7. 配置oracle连接文件tnsnames.ora

    最简单的方式就是,在把Oracle服务器上 $ORACLE_HOME/network/admin 下的文件全部copy

    racle@oracle ~]$ ls  $ORACLE_HOME/network/admin
    listener.ora  samples  shrept.lst  sqlnet.ora  tnsnames.ora
    

    注意配置文件中的HOST改成服务器的实际ip地址

    # tnsnames.ora Network Configuration File: /opt/oracle/12c/network/admin/tnsnames.ora
    # Generated by Oracle configuration tools.
    
    LISTENER_ORCL =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.133)(PORT = 1521))
    
    ORCL =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.122.133)(PORT = 1521))
        (CONNECT_DATA =
          (SERVER = DEDICATED)
          (SERVICE_NAME = orcl)
        )
      )
    
  8. 测试

    
    $ sqlplus64 eric/ericpwd@orcl
    
    SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 23 16:41:01 2018
    
    Copyright (c) 1982, 2016, Oracle.  All rights reserved.
    
    Last Successful login time: Fri Nov 23 2018 15:08:36 +08:00
    
    Connected to:
    Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
    
    SQL>
    
  9. 出现问题及解决

    如果无法连接数据库服务器

    • 如果出现下面情况,就是安装包及配置文件有问题,可以将整个oracle目录删除,重新安装(本人装了3次)

      eric@ray:~
      $ sqlplus64
      sqlplus: command not found
      
    • sqlplus安装成功后,可以执行:

      $ sqlplus64
      
      SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 23 16:45:32 2018
      
      Copyright (c) 1982, 2016, Oracle.  All rights reserved.
      
      Enter user-name:
      

      或者

      $ sqlplus64 /nolog
      
      SQL*Plus: Release 12.2.0.1.0 Production on Fri Nov 23 10:51:11 2018
      
      Copyright (c) 1982, 2016, Oracle.  All rights reserved.
      
      SQL> exit
      
      
    • 若TNS报错:

      ORA-12543 - TNS destination host unreachable
      #在客户端测试1521端口,会发现端口不通
      eric@ray:~
      $ telnet server.ip 1521
      
      

      检查服务器的防火墙

      [root@oracle sysconfig]# systemctl status firewalld
      ● firewalld.service - firewalld - dynamic firewall daemon
         Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
         Active: active (running) since Fri 2018-11-23 01:03:34 EST; 22min ago
           Docs: man:firewalld(1)
       Main PID: 686 (firewalld)
         CGroup: /system.slice/firewalld.service
                 └─686 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
      
      Nov 23 01:03:32 oracle systemd[1]: Starting firewalld - dynamic firewall .....
      Nov 23 01:03:34 oracle systemd[1]: Started firewalld - dynamic firewall d...n.
      Hint: Some lines were ellipsized, use -l to show in full.
      
      

      关闭防火墙:由于Centos使用的是firewalld管理,可以禁用掉,然后配置iptables进行管理

      [root@oracle sysconfig]# systemctl stop firewalld
      [root@oracle sysconfig]# systemctl disable firewalld
      

      如果上述都正确安装,就可以愉快的使用sqlplus了.如有问题可以留言

你可能感兴趣的:(Linux,Oracle,编程工具)