Saturday, March 31, 2018

Oracle RAC Scan Listener - (2)



To get scan name details:
These commands will have to executed by grid user.



bash-4.3$ srvctl config scan
SCAN name: SMDCMBDBL, Network: 1/XX.XX.10.0/255.255.255.0/nxge7
SCAN VIP name: scan1, IP: /xx.xx.xx.106/10.54.10.106
SCAN VIP name: scan2, IP: /xx.xx.xx.108/10.54.10.108
SCAN VIP name: scan3, IP: /xx.xx.xx.107/10.54.10.107


bash-4.3$ srvctl config scan_listener
SCAN Listener LISTENER_SCAN1 exists. Port: TCP:1521
SCAN Listener LISTENER_SCAN2 exists. Port: TCP:1521
SCAN Listener LISTENER_SCAN3 exists. Port: TCP:1521


To get the status of the scan listener:


bash-4.3$ srvctl status  scan_listener
SCAN Listener LISTENER_SCAN1 is enabled
SCAN listener LISTENER_SCAN1 is running on node kdbpprp2
SCAN Listener LISTENER_SCAN2 is enabled
SCAN listener LISTENER_SCAN2 is running on node kdbpprp1
SCAN Listener LISTENER_SCAN3 is enabled
SCAN listener LISTENER_SCAN3 is running on node kdbpprp1


The above command shows the hostname on which the 3 different scan listeners are running.


DNS performs the initial load balancing while scan name is called. As 3 IPs are assigned with the
scan name initially though that can be extended later. While clients send request to DNS, DNS
provided three different IP on different request. I.e while we are trying to fetch the DNS with
scan name, we get IP addresses order in different order.


paul@DBBL-ITDD-PAUL:~$ nslookup kdbpprp
Server: 127.0.1.1
Address: 127.0.1.1#53

Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.162
Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.161
Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.163

paul@DBBL-ITDD-PAUL:~$ nslookup kdbpprp
Server: 127.0.1.1
Address: 127.0.1.1#53

Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.161
Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.163
Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.162

paul@DBBL-ITDD-PAUL:~$ nslookup kdbpprp
Server: 127.0.1.1
Address: 127.0.1.1#53

Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.163
Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.162
Name: kdbpprp.dutchbanglabank.com
Address: XX.XX.XXX.161

paul@DBBL-ITDD-PAUL:~$



Command to get status for the specific listener scan.
bash-4.3$ lsnrctl  status LISTENER_SCAN2

LSNRCTL for HPUX: Version 11.2.0.4.0 - Production on 29-MAR-2018 14:50:55

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN2)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER_SCAN2
Version                   TNSLSNR for HPUX: Version 11.2.0.4.0 - Production
Start Date                24-OCT-2017 17:57:55
Uptime                    155 days 20 hr. 52 min. 59 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orafs/app/11.2.0/grid/network/admin/listener.ora
Listener Log File         /orafs/app/11.2.0/grid/log/diag/tnslsnr/kdbpprp1/listener_scan2/alert/log.xml
Listening Endpoints Summary...
 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER_SCAN2)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XX.XX.XXX.163)(PORT=1521)))
Services Summary...
Service "agentdb" has 2 instance(s).
 Instance "agentdb11", status READY, has 1 handler(s) for this service...
 Instance "agentdb12", status READY, has 1 handler(s) for this service...
Service "agentdb1XDB" has 2 instance(s).
 Instance "agentdb11", status READY, has 1 handler(s) for this service...
 Instance "agentdb12", status READY, has 1 handler(s) for this service...
The command completed successfully



Node VIP: Each Database node in Real Application cluster environment has one node IP and one Node VIP
address, The main difference between these two is Node VIP can move to any other system in case
if current owning system is down but Node IP can't do that. When ever a new connection request is made
the SCAN listener listening on a SCAN IP address and the SCAN port is contracted on a client's behalf.
Because all services on the cluster are registered with the SCAN listener, the SCAN listener replies with the
address of the local listener as Node VIP address on the least-loaded node (Each scan listener keeps updated
cluster load statistics) and connection is routed to that node.


Local Listener on the Database server is registered with Node VIP and Node IP address.


bash-4.3$ lsnrctl status listener

LSNRCTL for HPUX: Version 11.2.0.4.0 - Production on 29-MAR-2018 14:59:48

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER)))
STATUS of the LISTENER
------------------------
Alias                     LISTENER
Version                   TNSLSNR for HPUX: Version 11.2.0.4.0 - Production
Start Date                24-OCT-2017 18:06:15
Uptime                    155 days 20 hr. 53 min. 33 sec
Trace Level               off
Security                  ON: Local OS Authentication
SNMP                      OFF
Listener Parameter File   /orafs/app/11.2.0/grid/network/admin/listener.ora
Listener Log File         /orafs/app/grid/diag/tnslsnr/kdbpprp1/listener/alert/log.xml
Listening Endpoints Summary...
 (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=LISTENER)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XX.XX.XXX.61)(PORT=1521)))
 (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XX.XX.XXX.60)(PORT=1521)))
Services Summary...
Service "+ASM" has 1 instance(s).
 Instance "+ASM1", status READY, has 1 handler(s) for this service...
Service "agentdb" has 1 instance(s).
 Instance "agentdb11", status READY, has 1 handler(s) for this service...
Service "agentdb1XDB" has 1 instance(s).
 Instance "agentdb11", status READY, has 1 handler(s) for this service...
The command completed successfully


Local_Listener: This is a database parameter which is used to provide detail of local listener running on
database node itself. In Real Application Cluster environment this has Node VIP address as value.


When a new connection request is made my SCAN Listener, This address is returned to the SCAN Listener and
then connection is made to database local listener. The difference between SCAN Listener and Local Listener
is SCAN listener runs corosponding to SCAN VIP's while Local Listener runs with Node VIP or Node IP address.
SCAN Listener can move to another database node in case of node failure but local Listener doesn't have this
kind of behavior.


SQL> show parameter local_listener

NAME                                 TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener                       string (ADDRESS=(PROTOCOL=TCP)(HOST=XX.XX.XXX.60)(PORT=1521))


Remote_Listener: Each database instance has this parameter set to SCAN NAME of the cluster environment.
SCAN NAME in turn has one or more IP address further called SCAN VIP and each SCAN VIP has SCAN Listener
running on it, so finally each database instance register itself with all SCAN Listeners running across the
clusterware.


SQL> show parameter remote_listener

NAME                                 TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_listener                      string kdbpprp:1521



The solo purpose of remote_listener parameter is to register each database instance with all SCAN Listeners
in RAC. This provide information on what services are being provided by the instance,the current load, and a
recommendation on how many incoming connections should be directed to the instance.


Stopping scan listener:
srvctl stop scan_listener [-scannumber ordinal_number] [-force]

Example:
srvctl stop scan_listener -scannumber 1


Relocate scan listener:
bash-4.3$ srvctl status scan
SCAN VIP scan1 is enabled
SCAN VIP scan1 is running on node kdbpbrp2
SCAN VIP scan2 is enabled
SCAN VIP scan2 is running on node kdbpbrp1
SCAN VIP scan3 is enabled

SCAN VIP scan3 is running on node kdbpbrp1

srvctl relocate scan -i -n  

Example:
srvctl relocate scan -i 3 -n kdbpbrp2

bash-4.3$ srvctl status scan
SCAN VIP scan1 is enabled
SCAN VIP scan1 is running on node kdbpbrp2
SCAN VIP scan2 is enabled
SCAN VIP scan2 is running on node kdbpbrp1
SCAN VIP scan3 is enabled

SCAN VIP scan3 is running on node kdbpbrp2



Thursday, March 29, 2018

Scan Listener of Oracle RAC

SCAN: (Single Client Access Name) -- It allows clients to access whole cluster/grid through one name, rather specifying all VIP addresses individually. It is an automatic load balancing tool that uses a relatively primitive least-recently-loaded algorithm. 

Basically SCAN Listeners are introduced to create another connection handler on top of existing node listeners to overcome the failover and load balancing issues till 11gR1 architecture for RAC. Till 11gR1 Node listeners were defined on VIPs to facilitate NACK (Negative Acknowledgement) to resolve the issue of TCP timeouts.

SCAN Requirement: To be able to get SCAN Functionality, We need some service through which one name is resolved to multiple IPs/hosts. This is what we often call "DNS", Domain name service or if you don't have DNS in your environment then you can use Oracle's "GNS (Grid Naming Service)"

SCAN Implementation/Configuration: In Our DNS We defined a ScanName and assigned three Virtual IPs e.g (OraDbScan=X.X.X.7, X.X.X.8 and X.X.X.9), Now when we do nslookup OraDbScan from our client it will give us list of three IPs specified as above and important thing, every time you do nslookup it will give you the IP addresses in round robin, So every request to resolve the OraDbScan name will give different IP every time. One kind of load balancing at first place to reach to SCAN Listener so requests will be distributed on available SCAN Listeners.

SCAN Usage: During Oracle Grid Installation, Specify mentioned IPs, Each VIP Listener on each node will register itself will Every SCAN Listener on whatever node the SCAN Listener is running.


Number of RAC Nodes: 4 
Physical IPs: 4, One for each node 
Private IPs: at least 4, One for each node (You can have two for each for redundancy) 
Virtual IPs: 4, One assigned to each node [Word "assigned" is important] 
Number of VIP Listeners: 4, Each Bound to certain Node [word "bound"/"assigned"] 
Number of SCAN Listeners: 3[ Still if you feel that default 3 SCAN listeners are not enough for your environment then you have an option to add few more scan listeners.], Grid will decide which nodes SCAN Listeners will be Allocated 

Client Connection String: Mentioning the name of SCAN "OraDbScan"


Connection Establishment: Client sends request to DNS using SCAN Name "OraDbScan", DNS will return one of three IPs, Client Sends request on that IP to the SCAN Listener, the SCAN Listener will route the request to one of the VIP Listeners among 4 VIP listeners in this case because each VIP listener has already registered itself with every SCAN Listener. Finally direct connection is established between client and one of the VIP Listeners. 
You see flexibility, adding/removing as many nodes in Grid/RAC doesn't require any change. 



Newspaper module of Python



In python, there is an awesome module to extract and parse newspaper arcticles named newspaper. This artcile is to get the initial taste of that module.

IMPORT NEWSPAPER Module

we assume newspaper is installed as a Python module (in my case I'm using Newspaper3k on Python3). Now we will import the module:

import newspaper

SET THE TARGET PAPER

For our testing purpose, we want to look at articles published in the Technology section of the Guardian. The first step was to build the newspaper object, like so:

techno = newspaper.build('https://www.theguardian.com/uk/technology')

ARTICLE EXTRACTION

We just wanted to extract a recent article, using the following code  :

target_article = techno.articles[1] 
target_article.download()

The first line stores the first article in a variable called target_article. The second line downloads the article stored in that variable. 

Printing the result with print(target_article.html) just spews out the entire HTML to the console, which isn't very helpful. But, the brilliant thing about newspaper is that it allows us to parse to article and then run some simple natural language processing against it. 

PARSING ARTICLE

Now that we've downloaded the article, we're in a position to parse it:

target_article.parse()

This in turn enables us to target specific sections of the article, like the body text, title or author. Here's how to scrape body text:

print(target_article.text)
This will print only the body text to the console. 

WRITING THE BODY TEXT TO A FILE

The body text isn't that helpful to us sitting there in the console output, so let's write the output of target_article.text to a file:

First off, import sys

import sys
Then,

f = open( 'article.txt', 'w')
f.write(target_article.text)

Wednesday, March 28, 2018

Python: Installation of newspaper3k module


The Newspaper library, developed and maintained by Lucas Ou-Yang, is specially designed for extracting information from the websites of newspapers and magazines. The objective of this library is to extract and curate the articles from the newspapers and similar websites. To install Newspaper, use the following commands.
  • Install pip3 command needed to install newspaper3k package:
    $ sudo apt-get install python3-pip
    
  • Python development version, needed for Python.h:
    $ sudo apt-get install python-dev
    
  • lxml requirements:
    $ sudo apt-get install libxml2-dev libxslt-dev
    
  • For PIL to recognize .jpg images:
    $ sudo apt-get install libjpeg-dev zlib1g-dev libpng12-dev
    
NOTE: If you find problem installing libpng12-dev, try installing libpng-dev.
  • Download NLP related corpora:
    $ curl https://raw.githubusercontent.com/codelucas/newspaper/master/download_corpora.py | python3
    
  • Install the distribution via pip:
    $ pip3 install newspaper3k

Tuesday, March 27, 2018

Finding all files in a directory containing a specific text in Linux

grep -rnw '/path/to/target/location/' -e 'search_string'

-r or -R is recursive,

-n is line number, and
-w stands for match the whole word.
-l (lower-case L) can be added to just give the file name of matching files.

Along with these, --exclude, --include, --exclude-dir flags could be used for efficient searching:



This will only search through those files which have .log or .out extensions:
grep --include=\*.{log,out} -rnw '/path/to/target/location/' -e "search_string"

This will exclude searching all the files ending with .txt extension:
grep --exclude=*.txt -rnw '/path/to/target/location/' -e "search_string"

For directories it's possible to exclude a particular directory(ies) through --exclude-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:

grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/target/location/' -e "search_string"

This works very well for me, to achieve almost the same purpose like yours.

Monday, March 26, 2018

Displaying lines numbers in Cat command

The syntax is:
cat -n fileName

OR
cat --number paul.txt

or  we cab use the more command/less command as filter when text can not be fitted on the screen:
cat --number foo.c | more
cat --number foo.c | less

The -b / --number-nonblank option number all nonempty output lines, starting with one and the syntax is:
cat -b fileName

OR
cat --number--nonblank filename

Finally, we can suppress or remove repeated empty output lines with the -s / --squeeze-blank option:
cat -s -n fileName
cat -s -n /etc/hosts




we can use the cat or nl command to display line numbers:

cat -n hello.c
nl hello.c



A note about sed
In the case just to print 7th and 9th line we can use the sed command:



sed -n -e 7p -e 9p /etc/resolv.conf