Friday, September 8, 2017

Connecting to Amazon RDS Oracle instance via Putty.

It was very easy to connect to RDS Oracle instance via SQL Developer tool.

But I wanted to connect to database via a SSH tool like putty, for obvious reason,
I like the black screen.

Took me some time to figure out but here is what I did.

1. Login as root into one of your EC2 servers.
    database access should be open, dbserver must be in the ACL.
    It was already there so no hiccups here.
    Though I did have to generate a private PPK from a pem file I had.
2. Download following two rpms from Oracle website.
    http://docs.oracle.com/database/121/SQPUG/apd.htm#SQPUG157

   oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
   oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm

2.a . Export cookies

This method requires exporting the cookies from you browser to a file and copying that file to the remote server, so that we can use it for the download. The cookies file contains your session’s authentication token as well as the confirmation of the EULA acceptance.

This is a handy method when you have to download multiple files at once.

To use this method it’s necessary to have a tool to export the cookies from the Web browser to a text file. If you don’t already have one, I’d suggest one of the browser extensions below:

For Chrome: https://chrome.google.com/webstore/detail/cookietxt-export/lopabhfecdfhgogdbojmaicoicjekelh

Initiate the download of the file you want (if downloading multiple files, you just need to do this for the first one)
Once the download is initiated, cancel it.
Export the cookies to a file (call it cookies.txt)
If you’re using one of the extensions suggested above, this is how you do it:
On Firefox: click on Tools -> “Export cookies…” and save the file
On Chrome: click on the “cookies.txt export” icon in the toolbar (the icon is a blue “C” with an arrow inside), select the entire contents of the cookies and paste it into a text file.
Copy the cookies.txt file to your remote server.
Download the files you want with one of the following commands:
wget --load-cookies=./cookies.txt --no-check-certificate "file_url" -O

Multiple files can be downloaded using the same cookies.txt file. The cookies are valid for 30 minutes and the download must be initiated during that period. After that you’ll have to repeat the process to re-export the cookies.

2.b wget commands
wget --load-cookies=./cookies.txt --no-check-certificate http://download.oracle.com/otn/linux/instantclient/122010/oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm
 
 
  wget --load-cookies=./cookies.txt --no-check-certificate http://download.oracle.com/otn/linux/instantclient/122010/oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm

3. # install as root
rpm -ivh oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm oracle-instantclient12.2-sqlplus-12.2.0.1.0-1.x86_64.rpm
 
 4. export LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib
export TNS_ADMIN=/usr/lib/oracle/12.2/client64/
export PATH=/usr/lib/oracle/12.2/client64/bin:$PATH

5. connect to oracle
   

sqlplus 'mydbusr@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=dns_name)(PORT=port))(CONNECT_DATA=(SID=database_name)))'                 
           


credits
1. https://wsgzao.github.io/post/oracle-instant-client/
2. http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToOracleInstance.html
3. https://www.pythian.com/blog/how-to-download-oracle-software-using-wget-or-curl/

1 comment: