Sie sind auf Seite 1von 35

Unix tips and tricks for the

Advanced Developers and DBAs

Sumit Sengupta
EDS, an HP Company
1

Introduction






Tips for Unix common flavors


Does not require root privilege
A few scripts discussed
Often more than one way
Create a toolset for yourself

Find Out Sever


Information - 1



1.

2.

3.
4.

Operating System, patchlevel and


Machine architecture
Uname a ( OS version /kernel level )
SunOS usplvwhro019 5.10 Generic_13711107 sun4v sparc SUNW,SPARC-EnterpriseT5220
Linux bubunel0 2.6.18-92.el5 #1 SMP Fri
May 23 22:17:30 EDT 2008 i686 i686 i386
GNU/Linux
AIX aixdev1 3 5 0024B7FA4C00 ( Aix )
HP-UX sacsadba B.11.00 A 9000/800
1191450531 two-user license
3

Server Information Solaris







prtconf v ( memory, number and type of


cpus, )
/usr/platform/$(uname i)/sbin/prtdiag
Prints cpu core, memory, IO configuration
motherboard sensors !
Everything except network status

Server Information AIX,


HP-UX, Linux








Aix prtconf CPU, Memory, Storage


(including LVM), Network.
Aix genkex | grep 64 ( 64 bit kernel )
Linux under /proc directory: cpuinfo,
meminfo, partitions, filesystems
Linux lshw, lspci, lssci, lsusb
HP-UX print_manifest (requires root!)
5

Who is holding on the


listener port Linux


lsof i :1521 shows Listener PID 6008

COMMAND PID
USER
FD
TYPE DEVICE
SIZE NODE NAME
tnslsnr 6008 oracle
8u IPv4 15091
TCP bubunel0:ncube-lm (LISTEN)


# netstat

-alnp | more

Proto Recv-Q Send-Q Local Address


Foreign Address State PID/Program
tcp
0
0 192.168.15.110:1521
0.0.0.0:*
LISTEN 6008 /tnslsnr
6

Who is holding on the


listener port Aix/
Solaris (8,9)


lsof -i :1525

COMMAND
PID
USER
FD
TYPE
DEVICE SIZE/OFF NODE NAME
tnslsnr 89542 rcoratst
8u IPv4
0x7336de10
0t0 TCP
aixdev1m:prospero-np (LISTEN)


netstat -an | grep 1525 (shows no PID)

tcp4 0 0 192.168.197.34.1525

*.* LISTEN
7

Who is holding on the


listener port Solaris
script
pfiles $f | grep - "port: $ans
(Solaris 10)
Run it for every process
$ port_scan.ksh
When you run it
$ Enter port you would like to know pid for: 1521
--------------------------------------------Port: 1521 is being used by PID:21070 ora_pmon_RTBAPCIS3
$ cat port_scan.ksh

Port_Scan script
#!/bin/ksh
line='---------------------------------------------'
pids=$(/usr/bin/ps -ef | sed 1d | awk '{print $2}')
if [ $# -eq 0 ]; then
read ans?"Enter port you would like to know pid for: "
else
ans=$1
fi
for f in $pids
do
/usr/proc/bin/pfiles $f 2>/dev/null | /usr/xpg4/bin/grep -q "port: $ans"
if [ $? -eq 0 ]; then
echo $line
echo "Port: $ans is being used by PID:\c"
/usr/bin/ps -ef -o pid -o args | egrep -v "grep|pfiles" | grep $f
fi
9
done

Cannot Unmount a
Filesystem Linux
#

lsof /opt

COMMAND PID
USER
FD
TYPE DEVICE
SIZE
NODE NAME
nmz
6013 oracle txt
REG
22,5
678947 2458262
/opt/oracle/product/11.1.0/db_1/ccr/bin/nmz

Node  File Inode Number


Size  File Size
Device  Filesystem maj/min device number
10

List of Open Files


Solaris1
$ pfiles 19772 ( Solaris, for Aix  procfiles n )
19772:
/u01/app/oracle/product/9.2.0/db_1/bin/
tnslsnr LISTENER -inherit
Current rlimit: 1024 file descriptors


(lines snipped )

3: S_IFREG mode:0644 dev:85,102


ino:126027 uid:201 gid:101
size:81324417|O_CREAT|O_LARGEFILE
FD_CLOEXEC
/u01/app/oracle/product/9.2.0/db_1/netw
ork/log/listener.log
11

List of Open Files


Solaris..2
ino:126027 file inode number 85,102 device no.
$ ls i listener.log
126027d listener.log

Filesystem where the log resides:


/u01/app/oracle/product/9.2.0/db_1/network/log/listener.
log
/dev/md/dsk/d102

25G 6.9G 18G

29%

/u01/app/oracle

/dev/md/dsk/d102->../../../devices/pseudo/md@0:0,102,blk

$ ls -l /devices/pseudo |awk '$5 ~ /85/' |grep 102


brw-r----- 1 root sys 85,102 Nov 21 21:40 md@0:0,102,blk
crw-r----- 1 root sys 85,102 Nov 22 10:20 md@0:0,102,raw

12

Process Hierarchy
Solaris
Shows Process Tree Hierarchy
$ ptree -a 15460
1
/sbin/init
14758 /usr/openwin/bin/xterm -title
14760 -ksh
15460 sqlplus /nolog
15468 oracleRBSTRPD1
(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROT
OCOL=beq)))

Watch Load on Title Bar






Perl script runs in the background


Read /proc/loadavg ( on Linux )
Use uptime for other Unix Flavors

14

The scrip to watch


load
#!/usr/bin/perl -w
use strict;
$|++;
my $host=`/bin/hostname`;
chomp $host;
while (1)
{
open (LOAD,"/proc/loadavg") || die "Could not open /proc/loadavg \n";
my @load=split(/ /,<LOAD>);
close (LOAD);
print "\033]0;";
print "$host: $load[0] $load[1] $load[2] at ", scalar(localtime) ;
print "\007" ;
sleep 2;
}

List Shared Memory Solaris




ipcs -a ( Solaris, shm and sem )

ID
KEY
MODE
OWNER
GROUP CREATOR
CGROUP NATTCH
SEGSZ CPID LPID
ATIME
DTIME
CTIME
Shared Memory:
132
0xa8058568 --rw-r----m
ora10g
dba
ora10g
dba
37
1002455040 9173 13725 4:20:53 4:20:53
9:23:44

16

List Semaphore Solaris


T
OWNER
OTIME

ID
GROUP
CTIME

KEY
CREATOR

MODE
CGROUP NSEMS

Semaphores:
s

196611
0x5831266c --ra-r----ora10g
dba
ora10g
dba
154
4:21:56 9:23:46

No Semaphore for Aix/Tru64

SEM Instance
Mapping
$ sysresv
IPC Resources for ORACLE_SID "prdrpt" :
Shared Memory:
ID
KEY
132
0xa8058568
Semaphores:
ID
KEY
196611
0x5831266c

18

Kernel Parameters
SHMMAX = Max. SGA Segment Size
SHMMNI >= number of instances
SHMSEG = Max number of oracle instances one process can
connect to
SEMMNS >= PROCESSES parameters
SEMMNI >= Total number of oracle instances
SEMMSL >= Max PROCESSES parameter

19

SSH Port Forwarding


Local or Remote
Besides SSH Any protocol can do
SSH encrypts data in transit
Does not encrypt SQLNET Data
Local Traffic for a local port diverted to a
remote port
Remote The other way

20

SSH Port Forward


Example
From our client machine ( 192.168.2.100 )
$ ssh -f -N -C -R 1526:192.168.2.100:1521 -l oracle
192.168.2.111
oracle@192.168.2.111's password:

-f forks ssh into background


-N don't run a command on remote box
-C for compression
-R Remote Port#
-l for login

22

Testing Port
Forwarding..1
Prerequisite Listener on 1526, ssh on 22
Shows up --> netstat -an | egrep 'ESTA|Local'
Proto Local Address
Foreign Address
State
TCP
192.168.2.100:3882
192.168.2.111:22
ESTABLISHED

23

Testing Port
Forwarding..2
$ tnsping pd10_eth0
Used TNSNAMES adapter to resolve the
alias
Attempting to contact (DESCRIPTION =
(ADDRESS_LIST = (ADDRESS = (PROTOCOL
= TCP)(HOST = 192.168.2.111)(PORT =
1526))) (CONNECT_DATA
= (SERVICE_NAME = pd10)))
OK (130 msec)

24

Testing Port
Forwarding..3
sqlplus hr/hr@pd10_eth0
results in
Proto Local Address
Foreign
Address
State
TCP
192.168.2.100:3882
192.168.2.111:22
ESTABLISHED
TCP
192.168.2.100:3887
192.168.2.111:1526
ESTABLISHED (NEW)

25

Lessons From Port


Forwarding







SQLNET.EXPIRE_TIME = 5 ( Client )
Else client gets ORA-3135
May need TCP Valid Node Checking on
Client/Server
( Not on 11G Windows client/Linux Server )
For TCP node checking, server needs itself
included
See MetaLink note# 465572.1 and 454252.1

26

Oracle Connection
Manager

SQL*Net Proxy
Session Multiplexing
Client access control
Very useful with firewalls
Not part of default EE install (10g/11g)
like label security and data mining score
engine
27

Setup CM..1

$ cat cman.ora

CMAN= (CONFIGURATION=
(address=(protocol=tcp)(host=bubunel0)(port=
1522))
(rule_list=
(rule=(src=*)(dst=192.168.15.2)(srv=*)(act=a
ccept)(ACTION_LIST=(AUT=on)(MCT=120)(MIT=
30)))
(rule=(src=bubunel0)(dst=127.0.0.1)(srv=cmon
)(act=accept)))
28

Setup CM..2
(PARAMETER_LIST=
(MAX_GATEWAY_PROCESSES=1)
(MIN_GATEWAY_PROCESSES=1)
(trace_level=off) (log_level=off)
(connection_statistics=On) ) )
CMCTL> administer cman
Connections refer to
(address=(protocol=tcp)(host=bubunel0)(p
ort=1522)).
CMCTL:cman> start

Look up Note# 733421.1 for Syntax


29

Database Setup for CM


Set Local_Listener ( if not default )
Remote_Listener = Listener_cman_eth1 (
TNS entry )
Listener_cman_eth1 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST =
192.168.15.110)(PORT = 1522))
)
)
30

Running CM
CMCTL:cman> show services
... lines snipped
Service "sumit" has 1 instance(s).
REMOTE SERVER
(ADDRESS=(PROTOCOL=TCP)(HOST=<DB_SERVER_NAME>
)(PORT=1521))

SQLPLUS connects to oracle_sid on the


CMAN host on CMAN port.
31

Immutable Files in Linux


Ext2/3
$ mv rigid.txt trash
mv: cannot move `rigid.txt' to `trash': Operation not
permitted
$ cat /dev/null >rigid.txt
bash: rigid.txt: Permission denied
$ >rigid.txt
bash: rigid.txt: Permission denied

32

Test Immutable File


$ ln rigid.txt hlink.txt
ln: creating hard link `hlink.txt' to
`rigid.txt': Operation not permitted
$ echo "add a line to it " >>rigid.txt
bash: rigid.txt: Permission denied
$ whoami
oracle
$ ls -lad .
drwxr-x--- 2 oracle oinstall 4096 Jan
$ ls la rigid.txt
-rwxr-x--- 2 oracle oinstall 230 Jan
rigid.txt

3 19:18 .
1 09:45

33

Fix Immutable file


$ lsattr rigid.txt
----i-------- rigid.txt
$ chattr -i rigid.txt
chattr: Operation not permitted while
setting flags on rigid.txt
( Need to be root )
Another flag -a file is allowed to be
modified with append only Great for
Alert logs !
34

Thank You !


Please Fill Out The Evaluation Form !

35

Das könnte Ihnen auch gefallen