jump to navigation

Linux Monitor / Healthcheck script Settembre 3, 2009

Posted by installatore in Varie, linux, networking, script, solaris.
Tags: , , , , , ,
add a comment

In questo articolo,descrivo come tramite l’uso dei comandi della shell di linux possiamo crearci uno script da schedulare successivamente con cron,per monitorare lo stato di salute dei nostri server.La funzionalità dello script è molto semplice ,sicuramente può essere migliorato.

Come prima cosa partirei controllando che il/i filesystem del nostro server non siano pieni .

[root@rac2 ~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/mapper/VolGroup00-LogVol00

14G   13G  775M  95% /

/dev/sda1              99M   19M   76M  20% /boot

tmpfs                 502M  300M  202M  60% /dev/shm

Controlliamo inoltre gli ultimi login effettuati sulla macchina,come si dice….la prudenza non è mai troppa…
[root@rac2 ~]# last | head -20
root     pts/3        192.168.0.8      Tue Aug 18 09:20   still logged in
oracle   pts/3        :0.0             Tue Aug 18 09:17 – 09:20  (00:02)
oracle   pts/3        :0.0             Tue Aug 18 08:19 – 09:16  (00:56)
oracle   pts/2        :0.0             Tue Aug 18 07:08   still logged in
oracle   :0                            Tue Aug 18 07:08   still logged in
oracle   :0                            Tue Aug 18 07:08 – 07:08  (00:00)
root     pts/1        openfiler1       Tue Aug 18 07:04   still logged in
reboot   system boot  2.6.18-128.4.1.e Tue Aug 18 06:57          (02:25)
root     pts/1        :0.0             Tue Aug 18 06:44 – down   (00:11)
root     pts/2        openfiler1       Tue Aug 18 06:22 – down   (00:32)
root     pts/1        :0.0             Tue Aug 18 06:15 – 06:43  (00:28)
root     :0                            Tue Aug 18 06:14 – down   (00:40)
root     :0                            Tue Aug 18 06:14 – 06:14  (00:00)
reboot   system boot  2.6.18-128.4.1.e Tue Aug 18 06:10          (00:45)
root     pts/1        :0.0             Tue Aug 18 05:49 – down   (00:19)
root     pts/1        :0.0             Tue Aug 18 05:47 – 05:48  (00:00)
root     pts/1        :0.0             Sun Aug 16 16:36 – 05:46 (1+13:10)
root     pts/2        :0.0             Sun Aug 16 16:26 – down  (1+13:41)
root     pts/1        :0.0             Sun Aug 16 16:24 – 16:36  (00:12)
root     :0                            Sun Aug 16 16:23 – down  (1+13:45)
Un’altra cosa da controllare soprattutto sui sistemi esposti su internet,è la grandezza della cartella temporanea e relativi file,molto spesso al suo interno si annidano rootkit o altri malware.Nel mio caso la cartella temporanea era /tmp
[root@rac2 ~]# du -h /tmp
8.0K    /tmp/gconfd-root
4.0K    /tmp/keyring-JuVYH2
4.0K    /tmp/.oracle
16K    /tmp
Controlliamo anche lo stato dell’hardware della scheda madre andando a fare un grep su tutte le voci che contegono state o status.
[root@rac2 ~]# dmidecode |grep -B 2 Stat
Serial Number: …..
Asset Tag:
Boot-up State: Safe
Power Supply State: Safe
Thermal State: Safe
Security Status: None
Max Speed: 5200 MHz
Current Speed: 2400 MHz
Status: Populated, Enabled
On Board Device Information
Type: Ethernet
Status: Enabled
On Board Device Information
Type: Sound
Status: Enabled
On Board Device Information
Type: Other
Status: Enabled
Access Method: Memory-mapped physical 32-bit address
Access Address: 0xFFF81000
Status: Valid, Not Full
Handle 0×1800, DMI type 24, 5 bytes.
Hardware Security
Power-On Password Status: Enabled
Keyboard Password Status: Not Implemented
Administrator Password Status: Enabled
Front Panel Reset Status: Not Implemented
Cooling Device
Type: Fan
Status: OK
Cooling Device
Type: Fan
Status: OK
Cooling Device
Type: Fan
Status: OK
Handle 0×2000, DMI type 32, 11 bytes.
System Boot Information
Status: No errors detected
A questo punto diamo un’occhiata allo stato dei pacchetti droppati e agli errori di trasmissione e ricezione sulle interfacce di rete.In linea di massima questi valori non dovrebbero crescere in maniera esorbitante nell’arco della giornata.
[root@rac2 ~]# ifconfig
eth4      Link encap:Ethernet  HWaddr 00:0C:29:2D:6F:3E
inet addr:192.168.0.102  Bcast:192.168.0.255  Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe2d:6f3e/64 Scope:Link
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:2814028 errors:0 dropped:0 overruns:0 frame:0
TX packets:383162 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2263618394 (2.1 GiB)  TX bytes: 372588412946 (347 GiB)
Base address:0×2000 Memory:d8940000-d8960000
Oltre al comando ifconfig per controllare la parte “fisica” del collegamento in rete possiamo usare ethtool.
[root@rac2 ~]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes:   10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes:  10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 0
Transceiver: internal
Auto-negotiation: on
Supports Wake-on: d
Wake-on: d
Current message level: 0×00000007 (7)
Link detected: yes
Tramite lm_sensors possiamo ottenere i valori di elettricità e di temperatura di alcuni componenti della scheda madre della nostra macchina,quindi se non lo avete già fatto bisogna installare lm_sensors e lanciare il comando sensors-detect e seguire la procedura guidata per la prima configurazione.
[root@rac2]# sensors
lm85b-i2c-0-2e
Adapter: SMBus I801 adapter at c400
V1.5: +1.47 V (min = +1.42 V, max = +1.58 V)
VCore: +1.49 V (min = +1.45 V, max = +1.60 V)
V3.3: +3.33 V (min = +3.13 V, max = +3.47 V)
V5: +5.03 V (min = +4.74 V, max = +5.26 V)
V12: +12.25 V (min = +11.38 V, max = +12.62 V)
CPU_Fan: 2386 RPM (min = 4000 RPM) ALARM
fan2: 0 RPM (min = 0 RPM)
fan3: 0 RPM (min = 0 RPM)
fan4: 300 RPM (min = 0 RPM)
CPU: +29°C (low = +10°C, high = +50°C)
Board: +29°C (low = +10°C, high = +35°C)
Remote: +28°C (low = +10°C, high = +35°C)
CPU_PWM: 255
Fan2_PWM: 255
Fan3_PWM: 77
vid: +1.525 V (VRM Version 9.0)
Bisogna inoltre controllare eventuali errori hardware ai dischi tramite dmesg,in dmesg trovate anche altri errori relativi alle periferiche,qui di seguito lo utilizzo con un grep per i dischi,ovviamente potete personalizzare il grep a vostra discrezione.
[root@rac2 ~]# dmesg | grep sda
SCSI device sda: 33554432 512-byte hdwr sectors (17180 MB)
sda: Write Protect is off
sda: Mode Sense: 5d 00 00 00
sda: cache data unavailable
sda: assuming drive cache: write through
SCSI device sda: 33554432 512-byte hdwr sectors (17180 MB)
sda: Write Protect is off
sda: Mode Sense: 5d 00 00 00
sda: cache data unavailable
sda: assuming drive cache: write through
sda: sda1 sda2
sd 0:0:0:0: Attached scsi disk sda
EXT3 FS on sda1, internal journal
Quindi controlliamo il numero di processi “zombie” e quale tra i processi sta consumando più ram e cpu giusto per vedere che non ci siano problemi (il numero dei processi zombie non deve mai essere troppo alto).
[root@rac2]# top -bn 2 >> /tmp/top.txt
top – 09:52:46 up  130 days,  5 users,  load average: 0.13, 0.21, 0.27
Tasks: 159 total,   3 running, 156 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.0%us,  1.0%sy,  0.0%ni, 95.0%id,  3.6%wa,  0.0%hi,  0.3%si,  0.0%st
Mem:   1027004k total,   936852k used,    90152k free,    20292k buffers
Swap:  2064376k total,    71652k used,  1992724k free,   681484k cached
PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
1314 root      15   0 12740 1108  804 R  1.0  0.1   0:00.16 top
1274 root      15   0 88948 3328 2588 R  0.3  0.3   0:00.27 sshd
1 root      15   0 10344  508  476 S  0.0  0.0   0:01.22 init
2 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 migration/0
3 root      34  19     0    0    0 S  0.0  0.0   0:00.05 ksoftirqd/0
4 root      RT  -5     0    0    0 S  0.0  0.0   0:00.00 watchdog/0
5 root      10  -5     0    0    0 S  0.0  0.0   0:05.58 events/0
6 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 khelper
15 root      10  -5     0    0    0 S  0.0  0.0   0:00.01 kthread
19 root      10  -5     0    0    0 S  0.0  0.0   0:08.29 kblockd/0
20 root      20  -5     0    0    0 S  0.0  0.0   0:00.00 kacpid
205 root      15  -5     0    0    0 S  0.0  0.0   0:00.00 cqueue/0
208 root      10  -5     0    0    0 S  0.0  0.0   0:00.00 khubd
A questo punto spiegati tutti i singoli comandi possiamo crearci uno script da lanciare tutti i giorni tramite cron,in modo tale che ci invii anche una mail con il resoconto di tutti i comandi.
#!/bin/sh
# monitor script linux v1
uname -a > /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
df -h >> /tmp/mhc.txt
last |head -10 >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
du -h /tmp >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
ethtool eth0 >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
ifconfig eth0 >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
dmidecode |grep -B 2 Stat >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
sensors >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
top -bn 2 >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
smartctl -d ata -iH /dev/sda >> /tmp/mhc.txt
smartctl -d ata -iH /dev/sdb >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
dmesg |grep sda >> /tmp/mhc.txt
dmesg |grep sdb >> /tmp/mhc.txt
echo “—————————-”>>/tmp/mhc.txt
cat /tmp/mhc.txt |mail -s server-health-check your@email.com
[root@rac2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
14G   13G  775M  95% /
/dev/sda1              99M   19M   76M  20% /boot
tmpfs                 502M  300M  202M  60% /de

Log Rotation For Tomcat under Solaris 10 Aprile 26, 2009

Posted by installatore in Varie, script, solaris.
Tags: , , , ,
add a comment

Penso che almeno una volta tutti quelli che utilizzano Tomcat,si sono trovati davanti a file di log (catalina.out in primis) talmente grandi da non poter nemmeno essere aperti.Così mi sono creato questo breve scriptino che lanciato da crond una volta al giorno mi effettua la rotazione dei log e mi cancella quelli più vecchi di 3 giorni.

#!/bin/sh

logadm /opt/apache-tomcat-6.0.18/logs/cc.log -C 15 -c -p now -t ‘/opt/apache-tomcat-6.0.18/logs/CC_OK.%Y-%m-%d-%H-%M’

logadm /opt/apache-tomcat-6.0.18/logs/catalina.out -C 15 -c -p now -t ‘/opt/apache-tomcat-6.0.18/logs/CATALINA_OK.%Y-%m-%d-%H-%M’

find /opt/apache-tomcat-6.0.18/logs -mtime +3 -exec rm -f {} \;

Ho configurato successivamente lo scriptino nella crontab di root  e riavviato il servizio con

svcadm restart crond

 

Setting Up external ntp source in a Sun Cluster environment Aprile 25, 2009

Posted by installatore in solaris.
Tags: , , ,
add a comment

Ultimamente mi sono trovato davanti a una nuova esperienza quella su Solaris.Un gran bel sistema operativo,un pò ostico all’inizio ma una volta presa la mano si vola :D

In questo articolo vi descrivo come poter impostare il client Ntp di Solaris 10 in un ambiente clusterizzato con Sun Cluster.

Se la parte cluster è già stata installata,dovremmmo prima stoppare il servizio xntpd ì,modificare il file /etc/inet/ntp.cluster,quindi dare un bel ntpdate -B serverntp per sincronizzare il sistema con l’nt,quindi riabilitare il servizio xntpd.Ovviamente queste operazioni,si intendono da fare prima su un nodo e poi su tutti gli altri .

/etc/init.d/xntpd.cluster stop

vi /etc/inet/ntp.cluster

#server serverntp
#server 127.127.1.0
#peer clusternode1-priv prefer
#peer clusternode2-priv
#driftfile /var/ntp/ntp.drift
#filegen peerstats file peerstats type day enable
#filegen loopstats file loopstats type day enable
#filegen clockstats file clockstats type day enable

ntpdate -B serverntp

/etc/init.d/xntpd.cluster start

Et voilà….la sincronizzazione è servita!

All’interno del file ntp.cluster notiamo bene come se avessimo avuto all’interno della nostra lan più di un server ntp potevamo omettere la riga  #server 127.127.1.0 in quanto dice solamente che in mancanza del primo server usa se stesso come fonte attendibile per la sincronizzazione.