M.Kürşad Dara

I believe my mind and became a genius.

Archive for the ‘Linux’ Category

mongoDB data dosyalarının purge edilmesi

leave a comment

mongoDB data dizinine baktığınızda

-rw------- 1 root root  64M 2012-02-21 12:04 xxx.0
-rw------- 1 root root 128M 2012-02-21 12:02 xxx.1
-rw------- 1 root root 256M 2012-02-21 12:02 xxx.2
-rw------- 1 root root 512M 2012-02-21 12:04 xxx.3
-rw------- 1 root root 1.0G 2012-02-21 12:03 xxx.4
-rw------- 1 root root 2.0G 2012-02-21 12:04 xxx.5
-rw------- 1 root root 2.0G 2012-02-21 12:03 xxx.6

şeklinde uzayıp giden dosyalar göreceksiniz.

Bu dosyalar belli zaman sonra artacaktır.

Bunun nedeni şu:

mongoDB belirli büyüklükte (Örn 2GB) data dosyaları tutuyor. Bu alanı kullansanızda kullanmasanız da bu alanı ayırıyor. Siz veritabanı üstünde delete ve insertler yaptığınızda mongoDB’ni bu alanlardaki dataları delete etse bile hala bu alanı ayırmaya devam ediyor.

Bu yüzden belirli aralıklarla bu alanları free etmeniz gerekiyor.

Bunun içinde db.repairDatabase() komutunu çalıştırıp bu alanları free edebilirsiniz.

Komutu;

PRIMARY> use xxx
switched to db xxx

PRIMARY> db.repairDatabase();
{ "ok" : 1 }

şeklinde çalıştırabilirsiniz.

Not : Burada xxx fazlasıyla yer kaplayan veritabanının ismi.

Bu işlem sırasında bu veritabanınızı lock edeceği için production makinesinde yapacaksınız kullanılmadığı bir zamanda yapmanız mantıklı olur.

Yoksa;

Tue Feb 14 15:00:54 [conn78277] warning: ClientCursor::yield can't unlock b/c of recursive lock ns: xxx.xxx top: { opid: 212476020, active: true, lockType: "write", waitingForLock: false, secs_running: 1, op: "query", ns: "xxx", query: { repair
Database: 1.0 }, client: "xxx.xxx.xxx.xxx:38186", desc: "conn", threadId: "0x7f736eacc700", connectionId: 78277, msg: "index: (3/3) btree-middle", numYields: 0 }

şeklinde bir hata göreceksiniz log dosyasında.

Bu işlemler başarılı bir şekilde bittikten sonra gözle görülür şekilde disk kullanımından tasarruf etmiş olacaksınız.

Popularity: 1% [?]

Written by M.Kürşad DARA

February 21st, 2012 at 11:42 am

Anlık mongodb istatistikleri

leave a comment

Anlık olarak mongodb nin istatistiklerini görmek isterseniz:

root@mongodbs1:~# mongostat -h xxx.xxx.xxx.xxx
connected to: xxx.xxx.xxx.xxx
insert  query update delete getmore command flushes mapped  vsize    res faults locked % idx miss %     qr|qw   ar|aw  netIn netOut  conn   set repl       time
     0      0      0      0       1       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   239b     1k     5 myset    M   12:14:35
     0      0      0      0       0       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   192b     1k     5 myset    M   12:14:36
     0      0      0      0       1       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   239b     1k     5 myset    M   12:14:37
     0      0      0      0       0       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   192b     1k     5 myset    M   12:14:38
     0      0      0      0       1       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   239b     1k     5 myset    M   12:14:39
     0      0      0      0       0       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   192b     1k     5 myset    M   12:14:40
     0      0      0      0       1       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   239b     1k     5 myset    M   12:14:41
     0      0      0      0       0       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   192b     1k     5 myset    M   12:14:42
     0      0      0      0       0       2       0  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   192b     1k     5 myset    M   12:14:43
     0      0      0      0       1       2       1  14.2g  29.2g  2.86g      0        0          0       0|0     1|0   239b     1k     5 myset    M   12:14:44

Popularity: 1% [?]

Written by M.Kürşad DARA

February 17th, 2012 at 12:20 pm

Posted in Linux,MongoDB

Tagged with ,

ERROR 126 (HY000): Incorrect key file for table ‘/mnt/mysql-tmp/#sql_1a76_2.MYI’; try to repair it hatası

leave a comment

mySQL de bir query çalıştırdığınızda;

ERROR 126 (HY000): Incorrect key file for table '/mnt/mysql-tmp/#sql_1a76_2.MYI'; try to repair it

hatasını alıyorsanız bunun birkaç sebebi olabilir.

1. mySQL’in temp tabloları oluşturduğu dizini RAM üzerinde oluşturacak şekilde ayırdıysanız ve örneğin 2GB alan verdiyseniz ve gönderdiğiniz querynin oluşturduğu temp tablosu 2GB’tan büyük ise bu hatayı alırsınız. Bunun çözümü ya RAM’de temp tablo için ayırdığınız alanı artıracaksınız ya da querynizi optimize edeceksiniz.

/dev/ram1             2.0G     0  2.0G   0% /mnt/mysql-tmp
kursad:/mnt/mysql-tmp # ls -la /mnt/mysql-tmp/
total 2.0G
drwxrwxrwt 2 root  root    80 Feb 16 11:01 .
drwxr-xr-x 9 root  root  4.0K Feb 15 14:16 ..
-rw-rw---- 1 mysql mysql 2.0G Feb 16 11:01 #sql_1a76_0.MYD
-rw-rw---- 1 mysql mysql 1.0K Feb 16 11:01 #sql_1a76_0.MYI

2. İlgili tablo bozuk olabilir. Repair edip sorunu çözebilirsiniz.

Popularity: 1% [?]

Written by M.Kürşad DARA

February 16th, 2012 at 11:06 am

InnoDB: Unable to lock ./xxxxxx/xxxxx.ibd, error: 11 hatası.

leave a comment

InnoDB bir veritabanında sunucuyu resetledikten sonra aşağıdaki hatayı aldık.

120209 05:12:29 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data/
120209  5:12:29 [Note] Plugin 'FEDERATED' is disabled.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
120209  5:12:29  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
InnoDB: Unable to lock ./xxxxxx/xxxxx.ibd, error: 11
InnoDB: Check that you do not already have another mysqld process
InnoDB: using the same InnoDB data or log files.
120209  5:12:29  InnoDB: Assertion failure in thread 47546054463296 in file fil/fil0fil.c line 635
InnoDB: Failing assertion: ret
InnoDB: We intentionally generate a memory trap.
InnoDB: Submit a detailed bug report to http://bugs.mysql.com.
InnoDB: If you get repeated assertion failures or crashes, even
InnoDB: immediately after the mysqld startup, there may be
InnoDB: corruption in the InnoDB tablespace. Please refer to
InnoDB: http://dev.mysql.com/doc/refman/5.1/en/forcing-recovery.html
InnoDB: about forcing recovery.
120209  5:12:29 - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help diagnose
the problem, but since we have already crashed, something is definitely wrong
and this may fail.

key_buffer_size=104857600
read_buffer_size=52428800
max_used_connections=0
max_threads=512
threads_connected=0
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 52536408 K
bytes of memory
Hope that's ok; if not, decrease some variables in the equation.

thd: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = (nil) thread_stack 0x40000
/usr/local/mysql/bin/mysqld(my_print_stacktrace+0x2e)[0x8ad46e]
/usr/local/mysql/bin/mysqld(handle_segfault+0x322)[0x5e05c2]
/lib64/libpthread.so.0[0x39a0a0e4c0]
/lib64/libc.so.6(gsignal+0x35)[0x39a0230215]
/lib64/libc.so.6(abort+0x110)[0x39a0231cc0]
/usr/local/mysql/bin/mysqld[0x7acc5c]
/usr/local/mysql/bin/mysqld[0x7acdf9]
/usr/local/mysql/bin/mysqld(fil_space_get_size+0xde)[0x7b407e]
/usr/local/mysql/bin/mysqld(fil_check_adress_in_tablespace+0x9)[0x7b4159]
/usr/local/mysql/bin/mysqld(trx_sys_doublewrite_init_or_restore_pages+0x2d5)[0x82b6d5]
/usr/local/mysql/bin/mysqld(recv_recovery_from_checkpoint_start+0x175b)[0x7dbe0b]
/usr/local/mysql/bin/mysqld(innobase_start_or_create_for_mysql+0x115f)[0x81b8cf]
/usr/local/mysql/bin/mysqld[0x777d64]
/usr/local/mysql/bin/mysqld(_Z24ha_initialize_handlertonP13st_plugin_int+0x31)[0x6cf411]
/usr/local/mysql/bin/mysqld[0x75513a]
/usr/local/mysql/bin/mysqld(_Z11plugin_initPiPPci+0x875)[0x757c95]
/usr/local/mysql/bin/mysqld[0x5e0d95]
/usr/local/mysql/bin/mysqld(main+0x1c1)[0x5e50b1]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x39a021d974]
/usr/local/mysql/bin/mysqld(fmod+0x62)[0x513c0a]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
120209 05:12:29 mysqld_safe mysqld from pid file /usr/local/mysql/data//xxxxxx.pid ended

Çözüm olarak mysql i durdurup *.ibd dosyalarını taşıyıp tekrar cp -a ile kopyaladık ve mysql i çalıştırdık sorunumuz düzeldi.

Basit shell script şöyle :

#!/bin/bash
for i in `ls -a *.ibd`
do
  mv $i $i.bak
  cp -a $i.bak $i
done

Popularity: 1% [?]

Written by M.Kürşad DARA

February 9th, 2012 at 10:25 am

Posted in Linux,MySQL

Tagged with , , ,

stdin: is not a tty hatası

leave a comment

ssh ile remote olarak bir komut çalıştırmak istediğimde “stdin: is not a tty” hatası aldım.

Çözümü şöyle :

/etc/bashrc içindeki mesg y satırının başına # koyup iptal ettim.

Sonrada

source /etc/bashrc

komutunu çalıştırdım.

Sorun çözüldü.

Popularity: 1% [?]

Written by M.Kürşad DARA

February 2nd, 2012 at 2:03 pm

Posted in Linux

Tagged with , , ,

mySQL `ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction` hatası

leave a comment

Herhangi bir mySQL’de InnodB olan bir veritabanında update gibi table-lock koyan sorgusu çalıştırırken

ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction

hatasını alıyorsanız, konfigürasyon dosyasından

innodb_lock_wait_timeout=300

ekleyip mySQL i yeniden başlatırsanız sorununuz çözülecektir. Parametrenin değeri olan 300 saniye cinsindendir ve varsayılan değeri 50 sn. dir.

Bakınız : http://dev.mysql.com/doc/refman/5.0/en/innodb-parameters.html#sysvar_innodb_lock_wait_timeout

Popularity: 1% [?]

Written by M.Kürşad DARA

January 9th, 2012 at 2:30 pm

Text dosyasının başına satır numarası ekleme.

leave a comment

[root@efffe ~]# cat kursad.txt
satir 1
satir 2
satir 3
satir 4
satir 5

gibi bir text dosyanız var ve bütün satırların başına satır numarası koymak istiyorsunuz.
Bunun için linuxte nl isimli bir komut var

[root@efffe ~]# nl kursad.txt
     1  satir 1
     2  satir 2
     3  satir 3
     4  satir 4
     5  satir 5

veya

[root@efffe ~]# less -N kursad.txt
      1 satir 1
      2 satir 2
      3 satir 3
      4 satir 4
      5 satir 5

kullanabilirsiniz.

Fakat daha özelleştirilmiş birşeyler isterseniz awk ile bunu yapabilirsiniz.

[root@efffe ~]# awk 'BEGIN{FS=",";OFS="|"} {$1=$1; print NR,$0}' kursad.txt  > satirnumarali.txt

komutunu verdiğinizde satirnumarali.txt dosyasına satır numaralı şekilde yazacaktır.

[root@efffe ~]# cat satirnumarali.txt
1|satir 1
2|satir 2
3|satir 3
4|satir 4
5|satir 5

Popularity: 1% [?]

Written by M.Kürşad DARA

December 8th, 2011 at 2:04 pm

Posted in Linux,Scripting

Tagged with , , , ,

sudo komutu geç cevap veriyorsa

leave a comment

[kursad@kursad ~]$ sudo su -

komutunu girdiğinizde root olmanız çok uzun zaman alıyorsa çözümü basit.

[root@kursad ~]# hostname
kursad

komutu ile çıkan makine ismini öğrenin.

Daha sonra bu makine ismini /etc/hosts dosyasında 127.0.0.1 satırının en sonuna ekleyin.

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 kursad
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Şimdi tekrar tekrar normal bir kullanıcı ile sudo su – komutunu denediğinizde hemen root olacaksınız vakit almadan.

Popularity: 1% [?]

Written by M.Kürşad DARA

September 29th, 2011 at 2:19 pm

Posted in Linux

Tagged with , , , ,

Clickatell API’sini kullanarak nagios ile sms uyarısı gönderme

leave a comment

Bunun için öncelikle Clickatel firmasından gerekli üyeliği almalısınız.

Size verilen kullanıcı ve api bilgilerini aşağıdaki gibi /etc/nagios3/commands.cfg dosyasına yazın.

define command{
command_name host-notify-by-sms
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http:/
/api.clickatell.com/http/sendmsg?user=USERNAME&password=PASSWORD&&api_id=API_ID&to=$CONTACTEMAIL$&text='** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ @ $LONGDATETIME$ **'"
}

define command{
command_name service-notify-by-sms
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$ \nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | wget "http:/
/api.clickatell.com/http/sendmsg?user=USERNAME&password=PASSWORD&&api_id=API_ID&to=$CONTACTEMAIL$&text='** $NOTIFICATIONTYPE$ Service Alert: $SERVICEDESC$ on $HOSTNAME$ State: $SERVICESTATE$ @ $LONGDATETIME$ **'"
}

Daha sonra /etc/nagios3/conf.d/contacts_nagios2.cfg dosyası içine aşağıdaki gibi notification komutlarını girin. ( Kırmızı renkteki satırlar )

# Kursad DARA
####################

define contact{
contact_name                    swn_kursadd_sms
alias                           Kursad DARA
service_notification_period     nonworkhours
host_notification_period        nonworkhours
service_notification_options    w,c,r
host_notification_options       d,u,r
service_notification_commands   service-notify-by-sms
host_notification_commands      host-notify-by-sms
pager                           532xxxxxxx
}

Sonrasında

/usr/sbin/nagios3 -v /etc/nagios3/nagios.cfg

komutu ile nagios konfigürasyonunuzu kontrol edip hata yapmadığınızdan emin olun. Hata varsa düzeltmeniz gerekecek.

Hata yok ise

service nagios3 restart

ile nagios servisini tekrar başlatın.

Artık herhangi bir uyarı durumunda nagios size sms ile bilgi verecektir.

Popularity: 1% [?]

Written by M.Kürşad DARA

September 16th, 2011 at 4:42 pm

Posted in Linux,Nagios

Tagged with , ,

Apache’de Rewrite modülü ve htaccess kullanımının aktif edilmesi

leave a comment

Yapmanız gereken httpd.conf dosyasında aşağıdaki satırın başındaki # i kaldırmak ya da yoksa bu satırı eklemek.

LoadModule rewrite_module modules/mod_rewrite.so

Ardından,

Rewrite modülünü hangi dizin altında kullanacaksanız onun için aşağıdaki konfigürasyonu eklemek.

<Directory /webdizini/>
   Options FollowSymLinks
    AllowOverride ALL
    Order allow,deny
    Allow from all
</Directory>

Bunu da ekledikten sonra apache’yi yeniden başlatmanız (restart) veya konfigürasyonu tekrar yüklemeniz (reload) gerekmektedir.

Sonrasında nerde .htaccess kullanmak istiyorsanız orada bu dosyayı oluşturup kurallarınızı yazabilirsiniz.

Detaylı bilgi için : http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Popularity: 3% [?]

Written by M.Kürşad DARA

December 9th, 2010 at 9:22 am