Web ve daha önemlisi bütün otomasyon verilerinin üzerinde bulunduğu sunucunun her gece yedeğini alıyorum. Ancak gün içinde onca işlem yapılmışken akşam üstü bir sorun yaşanması oldukça kötü bir senaryo.
Bunun için gün içinde değişen dosyaları kaybetmek göze alınsa bile, mysql verileri için bu olası olamayacağından, mysql i yedek sunucu ile replike (paralel) olarak çalıştırmaya karar verdim.
Şu şekilde;
Öncelike benim kurduğum tek yönlü mysql replication işinin mantığı şu;
0-İki tane sunucum var; master (asıl sunucu (master), veriler burada değiştirilir, ve diğer sunucu (slave) burada verileri değiştirilmez, ama istenirse select işlemleri yapılabilir ). Slave sunucu master sunucunun mysql'ine ulaşabiliyor olmalı, firewall kontrol et.
1-Mater sunucuya, sen mastersin, artık dur yeni bir update işlemi yapma, ayrıca bundan sonra şu databaseler için yaptığın işlemleri logla deriz.
2-Master sunucudan verileri slave gönder.
3-Slave (yedek makinası) sunucuya sen slave'sin, master sunucu şu, ip'si şu, dikkate alacağın databaseler iu ve oradaki verilere ulaşmak için gerekli mysql kullanıcısı ve şifresi şu deriz.
4- master dan aldığımız veriyi slave de açarız.
5-Master'ın durumunu slave'e haber verip ikisine de hadi normal çalışmaya başlayın diyelim.
6-Master makina eşit olarak başlanan noktadan itibaran yapılan her değişikliği bir yere loglar, sonra da gider bunu slave makinada işletir. Masterdaki verilerin aynısı, anlık olarak slave'de de bulunur.
Şunu söylemek ihtiyacı duydum ki, mysql in resmi sitesinde de söylediği üzere bu bir yedekleme çözümü değil, bir parçası. Çünkü yetkisiz bir kişi master sunucuya erişim sağlayıp verileri bozarsa veya siz yanlışlıkla verilere zarar verirseniz, slave makinada da aynı bozukluğu göreceksiniz.
Başta dediğim gibi, amacım gün içinde master makinanın bir daha konuşmamak üzere "susması" durumunda kaldığım yerden devam etmek.
Şimdi yukarıdaki numaralarda gidersek;
0-
master makina'nın adresi: 23.23.23.23 olsun
Slave master'a ulaşabiliyor mu ona bakalım.
slave makinada;
telnet 23.23.23.23 3306
Sonuç olumlu olmalı.
1- Öncelikle master sunucuda gerekli ayarları yapalım.
log-bin = /var/lib/mysql/logs/mysql-bin.log
server-id=1
binlog-do-db=replike_edilecek_database
Açıklamaya gerek yok sanırım.
Şimdi master sunucuda slave sunucunun bağlanabilmesi için bir kullanıcı açalım. Bu kullanıcının yetkisinin sadece REPLICATION SLAVE olması yeterli. Tabiki ALL yetkisi de olur ama olmaması daha iyi.
Bu arada benim verileri eşitlemek için kullandığım yöntem dışında bir de verileri taşımakla uğraşmayıp, "hadi verileri master dan al gel" yöntemi var ama onun için ALL yetkisi vermek gerekiyor yeni kullanıcıya, ben de bundan hoşlanmadım, o yüzden bunu kullanıyorum.
Neyse, kullanıcıyı açalım;
mysql>GRANT REPLICATION SLAVE ON *.* TO 'replication_kullanicisi'@'%' IDENTIFIED BY 'sifre';
yetkileri güncelleyelim.
mysql>FLUSH PRIVILEGES;
Şimdi master database'in ayarları hazır, yeni ayarları yüklemek için mysql i tekrar başlatalım.
/etc/rc.d/init.d/mysqld restart
Artık bir süre master sunucuya yeni bir veri girilemesin.
mysql>FLUSH TABLES WITH READ LOCK;
2-Verileri taşıyalım. Ben mysqldump ile alıp scp ile taşıyıp diğer tarafta da açmayı tercih ediyorum.
mysqldump replike_edilecek_database -u root -p > /home/ben/replike_edilecek_database.sql;
scp /home/ben/replike_edilecek_database.sql ben@yedeksunucum.domainim.com:/home/ben
Veri orada dursun birazdan alacam.
3-slave sunucuda gerekli ayarları yapalım.
server-id=2
master-host=23.23.23.23 #master sunucumun adresi
master-connect-retry=60
master-user=replication_kullanicisi
master-password=sifre
relay-log = /var/lib/mysql/slave-relay.log
relay-log-index = /var/lib/mysql/slave-relay-log.index
replicate-do-db=replike_edilecek_database
Herşey açık.
Bu aşamadan şunu kontrol etmekte fayda var, masterda da slave de de /var/lib/mysql/log klasörünü tamamen boşaltmak lazım, yeni bir sunucu ise sorun yok ama daha önce bir kere denenmiş ise sorun çıkıyor, kaynaklara bakınız.
4-
mysql>create database replike_edilecek_database;
mysql -u root -p replike_edilecek_databese sql
Not: Şu anda iki sunucuda da veriler eşit durumda
5- Master'ın durumunu slave'e haber verip ikisine de hadi normal çalışmaya başlayın diyelim.
master makinada;
mysql>SHOW MASTER STATUS;
Sonuç şu şekilde olacak;
+---------------------+----------+-------------------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------------+----------+-------------------------------+------------------+
| mysql-bin.000001 | 98 | replike_edilecek_database | |
+---------------------+----------+-------------------------------+------------------+
Slave makinada;
mysql>slave stop;
mysql>CHANGE MASTER TO MASTER_HOST='23.23.23.23', MASTER_USER='replication_kullanicisi', MASTER_PASSWORD='sifre', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=98;
mysql>slave start;
Master makinada;
mysql>unlock tables;
6- Master sunucuda yapılan bir değişiklik slave de olmalı.
Kaynaklar:
http://www.howtoforge.com/mysql_database_replication
http://aciddrop.com/2008/01/10/step-by-step-how-to-setup-mysql-database-replication/
http://www.issociate.de/board/post/17960/Problems_with_permissions_when_replicating_mysqldb_(possibly_only_a_doc_error?).html
http://wiki.kolmisoft.com/index.php/MySQL_Replication
http://dev.mysql.com/doc/refman/5.0/en/replication.html
Performans ile ilgili;
http://jcole.us/blog/archives/2006/05/25/on-disk-performance-and-mysql-replication/
http://www.mysqlperformanceblog.com/2006/05/27/jeremy-cole-on-mysql-replication/
28 Ekim 2009 Çarşamba
subscription dosyasında hata
Mail hizmeti verilen ve kullanıcıların sistem kullanıcısı olduğu, Maildir yapısı kullanan sunucuda bazı kullanıcıalrın .Giden .Cop .Taslaklar klasorleri ve subscriptions dosyasinda bunlara ilişkin kayıtlar oluşmamış. Yazık!
Neyse, bırakıp gitmek olmaz, bunları düzeltelim.
########################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# serkan.capkan@gmail.com - 23.10.2009
#
########################################################################################
#!/bin/sh
#sabitler
tmp_passwd="/tmp/$0_passwd_gecici"
tmp_passwd_tmp="/tmp/$0_passwd_gecici_tmp"
klasor="/home/vmail"
subs_tmp="/tmp/$0_subs_tmp"
sistem_users="root bin daemon adm lp sync shutdown halt mail news uucp operator games gopher ftp nobody nscd vcsa pcap rpc mailnull smmsp rpcuser nfsnobody sshd dbus avahi haldaemon avahi-autoipd apache ntp mysql dovecot postfix clamav distcache named mailman amavis xfs"
date; echo "BASLADI ------------------------------------------------------"
#passwd dosyasini al
cp /etc/passwd $tmp_passwd
#kullanicinin sadece adi kalsin
sed -e s_:x:.*__g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#sistem kulanicilerini yok et
for i in $sistem_users
do
sed -e s/^$i$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
done
#mailnull adındaki kullanici kaliyor, onu da silelim
sed -e s/^mailnull$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#bos satirlari sil
sed '/^$/d' $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#islemleri yapmak uzere kullanicilari sirala
for username in `cat $tmp_passwd`
do
nokta_varmi=`echo $username |grep "\."`
if [ "$nokta_varmi" ]
then
harf=`echo $username | sed -e 's/.*\.//' | cut -c1`
else
harf=`echo $username | cut -c1`
fi
#subs dosyasinde su zorunlu kelimeler var mi
#subs dosyasi olmayanlarda olusturalim, yetkisini ayarlayalim
touch $klasor/$harf/$username/Maildir/subscriptions
chown $username $klasor/$harf/$username/Maildir/subscriptions
chgrp users $klasor/$harf/$username/Maildir/subscriptions
gidenler_var=`cat $klasor/$harf/$username/Maildir/subscriptions | grep -e Gidenler$`
taslaklar_var=`cat $klasor/$harf/$username/Maildir/subscriptions | grep -e Taslaklar$`
cop_var=`cat $klasor/$harf/$username/Maildir/subscriptions | grep -e Cop$`
#cop girdisi yoksa sorun var
if [ ! "$cop_var" ]
then
echo "$username --------------------------------------cop yoktu eklendi ----"
#subscriptions dosyasina ilgili kaydi ekle
tac $klasor/$harf/$username/Maildir/subscriptions>$subs_tmp
echo "Cop" >> $subs_tmp
tac $subs_tmp >$klasor/$harf/$username/Maildir/subscriptions
rm -f $subs_tmp
fi
#taslaklar girdisi yoksa sorun var
if [ ! "$taslaklar_var" ]
then
echo "$username --------------------------------------taslaklar yoktu eklendi ----"
#subscriptions dosyasina ilgili kaydi ekle
tac $klasor/$harf/$username/Maildir/subscriptions>$subs_tmp
echo "Taslaklar" >> $subs_tmp
tac $subs_tmp >$klasor/$harf/$username/Maildir/subscriptions
rm -f $subs_tmp
fi
#gidenler girdisi yoksa sorun var
if [ ! "$gidenler_var" ]
then
echo "$username --------------------------------------gidenler yoktu eklendi----"
#subscriptions dosyasina ilgili kaydi ekle
tac $klasor/$harf/$username/Maildir/subscriptions>$subs_tmp
echo "Gidenler" >> $subs_tmp
tac $subs_tmp >$klasor/$harf/$username/Maildir/subscriptions
rm -f $subs_tmp
fi
#hepsinin yetkisini gozden gecirelim
chmod 600 $klasor/$harf/$username/Maildir/subscriptions
#home klasorunde su zorunlu klasorler var mi, olmada olmasa da -p parametresi ile bu klasörleri yarat ve perm set et
mkdir -p $klasor/$harf/$username/Maildir/.Cop
mkdir -p $klasor/$harf/$username/Maildir/.Taslaklar
mkdir -p $klasor/$harf/$username/Maildir/.Gidenler
chmod 700 $klasor/$harf/$username/Maildir/.Cop
chmod 700 $klasor/$harf/$username/Maildir/.Taslaklar
chmod 700 $klasor/$harf/$username/Maildir/.Gidenler
chown $username $klasor/$harf/$username/Maildir/.Cop
chown $username $klasor/$harf/$username/Maildir/.Taslaklar
chown $username $klasor/$harf/$username/Maildir/.Gidenler
chgrp users $klasor/$harf/$username/Maildir/.Cop
chgrp users $klasor/$harf/$username/Maildir/.Taslaklar
chgrp users $klasor/$harf/$username/Maildir/.Gidenler
done
rm -f $tmp_passwd $tmp_passwd_tmp $subs_tmp
date; echo "BITTI ------------------------------------------------------"
Neyse, bırakıp gitmek olmaz, bunları düzeltelim.
########################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
#
# serkan.capkan@gmail.com - 23.10.2009
#
########################################################################################
#!/bin/sh
#sabitler
tmp_passwd="/tmp/$0_passwd_gecici"
tmp_passwd_tmp="/tmp/$0_passwd_gecici_tmp"
klasor="/home/vmail"
subs_tmp="/tmp/$0_subs_tmp"
sistem_users="root bin daemon adm lp sync shutdown halt mail news uucp operator games gopher ftp nobody nscd vcsa pcap rpc mailnull smmsp rpcuser nfsnobody sshd dbus avahi haldaemon avahi-autoipd apache ntp mysql dovecot postfix clamav distcache named mailman amavis xfs"
date; echo "BASLADI ------------------------------------------------------"
#passwd dosyasini al
cp /etc/passwd $tmp_passwd
#kullanicinin sadece adi kalsin
sed -e s_:x:.*__g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#sistem kulanicilerini yok et
for i in $sistem_users
do
sed -e s/^$i$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
done
#mailnull adındaki kullanici kaliyor, onu da silelim
sed -e s/^mailnull$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#bos satirlari sil
sed '/^$/d' $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#islemleri yapmak uzere kullanicilari sirala
for username in `cat $tmp_passwd`
do
nokta_varmi=`echo $username |grep "\."`
if [ "$nokta_varmi" ]
then
harf=`echo $username | sed -e 's/.*\.//' | cut -c1`
else
harf=`echo $username | cut -c1`
fi
#subs dosyasinde su zorunlu kelimeler var mi
#subs dosyasi olmayanlarda olusturalim, yetkisini ayarlayalim
touch $klasor/$harf/$username/Maildir/subscriptions
chown $username $klasor/$harf/$username/Maildir/subscriptions
chgrp users $klasor/$harf/$username/Maildir/subscriptions
gidenler_var=`cat $klasor/$harf/$username/Maildir/subscriptions | grep -e Gidenler$`
taslaklar_var=`cat $klasor/$harf/$username/Maildir/subscriptions | grep -e Taslaklar$`
cop_var=`cat $klasor/$harf/$username/Maildir/subscriptions | grep -e Cop$`
#cop girdisi yoksa sorun var
if [ ! "$cop_var" ]
then
echo "$username --------------------------------------cop yoktu eklendi ----"
#subscriptions dosyasina ilgili kaydi ekle
tac $klasor/$harf/$username/Maildir/subscriptions>$subs_tmp
echo "Cop" >> $subs_tmp
tac $subs_tmp >$klasor/$harf/$username/Maildir/subscriptions
rm -f $subs_tmp
fi
#taslaklar girdisi yoksa sorun var
if [ ! "$taslaklar_var" ]
then
echo "$username --------------------------------------taslaklar yoktu eklendi ----"
#subscriptions dosyasina ilgili kaydi ekle
tac $klasor/$harf/$username/Maildir/subscriptions>$subs_tmp
echo "Taslaklar" >> $subs_tmp
tac $subs_tmp >$klasor/$harf/$username/Maildir/subscriptions
rm -f $subs_tmp
fi
#gidenler girdisi yoksa sorun var
if [ ! "$gidenler_var" ]
then
echo "$username --------------------------------------gidenler yoktu eklendi----"
#subscriptions dosyasina ilgili kaydi ekle
tac $klasor/$harf/$username/Maildir/subscriptions>$subs_tmp
echo "Gidenler" >> $subs_tmp
tac $subs_tmp >$klasor/$harf/$username/Maildir/subscriptions
rm -f $subs_tmp
fi
#hepsinin yetkisini gozden gecirelim
chmod 600 $klasor/$harf/$username/Maildir/subscriptions
#home klasorunde su zorunlu klasorler var mi, olmada olmasa da -p parametresi ile bu klasörleri yarat ve perm set et
mkdir -p $klasor/$harf/$username/Maildir/.Cop
mkdir -p $klasor/$harf/$username/Maildir/.Taslaklar
mkdir -p $klasor/$harf/$username/Maildir/.Gidenler
chmod 700 $klasor/$harf/$username/Maildir/.Cop
chmod 700 $klasor/$harf/$username/Maildir/.Taslaklar
chmod 700 $klasor/$harf/$username/Maildir/.Gidenler
chown $username $klasor/$harf/$username/Maildir/.Cop
chown $username $klasor/$harf/$username/Maildir/.Taslaklar
chown $username $klasor/$harf/$username/Maildir/.Gidenler
chgrp users $klasor/$harf/$username/Maildir/.Cop
chgrp users $klasor/$harf/$username/Maildir/.Taslaklar
chgrp users $klasor/$harf/$username/Maildir/.Gidenler
done
rm -f $tmp_passwd $tmp_passwd_tmp $subs_tmp
date; echo "BITTI ------------------------------------------------------"
kullanıcı kota hesapla, klasore yaz mail at
Mail ve ftp hizmeti verilen ve kullanıcıların sistem kullanıcısı olduğu sunucuda, mailler /home/vmail/s/ad.soyad/Maildir, ftp hesapları /home/vmail/s/ad.soyad/ftp altında duruyor.
Amcaların kotalarını hesaplayıp ftp klasörlerine yazıp, kotası dolmaya yakın olanlara mail atalım.
########################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# serkan.capkan@gmail.com 21.10.2009
#
########################################################################################
#!/bin/bash
#sabitler
tmp_passwd="/tmp/passwd_gecici_$0"
tmp_passwd_tmp="/tmp/passwd_gecici_tmp_$0"
user_quota="/tmp/user_quota_$0"
user_quota2="/tmp/user_quota2_$0"
byte_katsayi=1024
uyari_siniri=80
uyari_konu="KOTA UYARISI (beta)"
klasor="/home/vmail"
sistem_users="root bin daemon adm lp sync shutdown halt mail news uucp operator games gopher ftp nobody nscd vcsa pcap rpc mailnull smmsp rpcuser nfsnobody sshd dbus avahi haldaemon avahi-autoipd apache ntp mysql dovecot postfix clamav distcache named mailman amavis xfs"
date=`date +%d.%m.%Y\ %H:%M`
date; echo "BASLADI ------------------------------------------------------"
#passwd dosyasini al
cp /etc/passwd $tmp_passwd
#kullanicinin sadece adi kalsin
sed -e s_:x:.*__g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#sistem kulanicilerini yok et
for i in $sistem_users
do
sed -e s/^$i$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
done
#mailnull adındaki kullanici kaliyor, onu da boyle silelim silelim
sed -e s/^mailnull$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#bos satirlari sil
sed '/^$/d' $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#islemleri yapmak uzere kullanicilari sirala
for username in `cat $tmp_passwd`
do
quota $username>$user_quota
#kotası olmayan bir kullanıcı ise donguyu kes,
quota_hata_verdimi=`cat $user_quota | grep 'none'`
if [ "$quota_hata_verdimi" ]
then
echo $username: Hata verdi; $quota_hata_verdi
continue;
fi
tail -n 1 $user_quota > $user_quota2 ; mv $user_quota2 $user_quota
kullanim=`cat $user_quota | awk '{print $1}'`
kota=`cat $user_quota | awk '{print $2}'`
let "kota_mb=$kota/$byte_katsayi"
let "kullanim_mb=$kullanim/$byte_katsayi"
yuzde=`echo "$kullanim*100/$kota" | bc`
#orani asti ise mail at
uyari_mesaj="$username Kullanici Hesabi kota kullaniminiz % $yuzde degerine ulasmistir.\r\ne-Posta ve FTP Dosya Alani kullaniminda sorun yasamamak icin lutfen e-Posta kutunuzu veya FTP Dosya Alaninizi bosaltiniz.\r\n\r\n Mevcut kotaniz: $kota_mb MB\r\n Kota kullaniminiz: $kullanim_mb MB ( %$yuzde )\r\n\r\nBu mesaj otomatik olarak gonderilmektedir, lutfen bu e-Posta'ya yanit yazmayiniz.\r\n\r\n"
#siniri gecti ise mail at
if [ $yuzde -gt $uyari_siniri ]
then
echo -e $uyari_mesaj | mail -s "$uyari_konu" $username bim@domainim.com -- -r noreply@domainim.com
fi
#ftp alanina kota kullanimini yaz
nokta_varmi=`echo $username |grep "\."`
if [ "$nokta_varmi" ]
then
harf=`echo $username | sed -e 's/.*\.//' | cut -c1`
else
harf=`echo $username | cut -c1`
fi
#gidip klasorlerine yaz
echo "KOTA:$kota_mb MB
KULLANIM:$kullanim_mb MB
KULANIM ORANI:%$yuzde
Not:Bu dosya $date tarihinde olusturulmustur." > $klasor/$harf/$username/ftp/KOTA_KULLANIMI.txt
done
#olusturulan gecici dosyalari sil
rm -f $tmp_passwd $passwd_tmp $user_quota $user_quota2
date; echo "BITTI ------------------------------------------------------"
Amcaların kotalarını hesaplayıp ftp klasörlerine yazıp, kotası dolmaya yakın olanlara mail atalım.
########################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
#
# serkan.capkan@gmail.com 21.10.2009
#
########################################################################################
#!/bin/bash
#sabitler
tmp_passwd="/tmp/passwd_gecici_$0"
tmp_passwd_tmp="/tmp/passwd_gecici_tmp_$0"
user_quota="/tmp/user_quota_$0"
user_quota2="/tmp/user_quota2_$0"
byte_katsayi=1024
uyari_siniri=80
uyari_konu="KOTA UYARISI (beta)"
klasor="/home/vmail"
sistem_users="root bin daemon adm lp sync shutdown halt mail news uucp operator games gopher ftp nobody nscd vcsa pcap rpc mailnull smmsp rpcuser nfsnobody sshd dbus avahi haldaemon avahi-autoipd apache ntp mysql dovecot postfix clamav distcache named mailman amavis xfs"
date=`date +%d.%m.%Y\ %H:%M`
date; echo "BASLADI ------------------------------------------------------"
#passwd dosyasini al
cp /etc/passwd $tmp_passwd
#kullanicinin sadece adi kalsin
sed -e s_:x:.*__g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#sistem kulanicilerini yok et
for i in $sistem_users
do
sed -e s/^$i$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
done
#mailnull adındaki kullanici kaliyor, onu da boyle silelim silelim
sed -e s/^mailnull$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#bos satirlari sil
sed '/^$/d' $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#islemleri yapmak uzere kullanicilari sirala
for username in `cat $tmp_passwd`
do
quota $username>$user_quota
#kotası olmayan bir kullanıcı ise donguyu kes,
quota_hata_verdimi=`cat $user_quota | grep 'none'`
if [ "$quota_hata_verdimi" ]
then
echo $username: Hata verdi; $quota_hata_verdi
continue;
fi
tail -n 1 $user_quota > $user_quota2 ; mv $user_quota2 $user_quota
kullanim=`cat $user_quota | awk '{print $1}'`
kota=`cat $user_quota | awk '{print $2}'`
let "kota_mb=$kota/$byte_katsayi"
let "kullanim_mb=$kullanim/$byte_katsayi"
yuzde=`echo "$kullanim*100/$kota" | bc`
#orani asti ise mail at
uyari_mesaj="$username Kullanici Hesabi kota kullaniminiz % $yuzde degerine ulasmistir.\r\ne-Posta ve FTP Dosya Alani kullaniminda sorun yasamamak icin lutfen e-Posta kutunuzu veya FTP Dosya Alaninizi bosaltiniz.\r\n\r\n Mevcut kotaniz: $kota_mb MB\r\n Kota kullaniminiz: $kullanim_mb MB ( %$yuzde )\r\n\r\nBu mesaj otomatik olarak gonderilmektedir, lutfen bu e-Posta'ya yanit yazmayiniz.\r\n\r\n"
#siniri gecti ise mail at
if [ $yuzde -gt $uyari_siniri ]
then
echo -e $uyari_mesaj | mail -s "$uyari_konu" $username bim@domainim.com -- -r noreply@domainim.com
fi
#ftp alanina kota kullanimini yaz
nokta_varmi=`echo $username |grep "\."`
if [ "$nokta_varmi" ]
then
harf=`echo $username | sed -e 's/.*\.//' | cut -c1`
else
harf=`echo $username | cut -c1`
fi
#gidip klasorlerine yaz
echo "KOTA:$kota_mb MB
KULLANIM:$kullanim_mb MB
KULANIM ORANI:%$yuzde
Not:Bu dosya $date tarihinde olusturulmustur." > $klasor/$harf/$username/ftp/KOTA_KULLANIMI.txt
done
#olusturulan gecici dosyalari sil
rm -f $tmp_passwd $passwd_tmp $user_quota $user_quota2
date; echo "BITTI ------------------------------------------------------"
Disk dolmaya yakın bana mail gelsin..
########################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
#
# serkan.capkan@gmail.com - Oct. 2009
#
########################################################################################
#!/bin/bash
#sabitler
var_bi_durum=`df | egrep -i "95%|96%|97%|98%|99%|100%"`
uyari_adresi="mail@domain.com"
konu="disk kapasite problemi !"
mesaj=`hostname`" disk kapasite problemi ! "`df | egrep -i "95%|96%|97%|98%|99%|100%"`
if [ "$var_bi_durum" ]
then
echo $mesaj | mail -s "$konu" $uyari_adresi
fi
########################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
#
# serkan.capkan@gmail.com - Oct. 2009
#
########################################################################################
#!/bin/bash
#sabitler
var_bi_durum=`df | egrep -i "95%|96%|97%|98%|99%|100%"`
uyari_adresi="mail@domain.com"
konu="disk kapasite problemi !"
mesaj=`hostname`" disk kapasite problemi ! "`df | egrep -i "95%|96%|97%|98%|99%|100%"`
if [ "$var_bi_durum" ]
then
echo $mesaj | mail -s "$konu" $uyari_adresi
fi
27 Ekim 2009 Salı
4 saatte dns
Bunu arada yapıp, sonra ders çıkarıp sonra tekrar yapıyorum.
gateway olan ve içerine 30 makinaya internet sağlanyan sunucu dışardaki dns sunuculara bakıyordu, ben de dedim kendi sunucumu kurayım, uğraşmasın ikide bir.
Fazla hafife almışım, önce ezbere denedim, sonra bloglardan bişeyler baktım yine olmadı.
Sonra müziği değiştirdim, Eleni Karaindrou'dan The Weeping Meadow u açtım sakinleştim.
Sonra da şöyle yaptım;
Öncelikle güvenlik gereği chroot yapısını kullanacaktım.
yum install bind bind-utils bind-chroot kurdum.
Bunların conf dosyaları eksik geliyor.
/var/named/chroot/etc/named.conf (sample lardan)
dosyası;
options {
directory "/var/named/data";
allow-recursion { 192.168.2.0/24; localhost; }; //kendisi ve içerdeki makinalar dns den faydalansın
};
logging{
channel "simple_log" {
file "/var/log/bind.log" versions 3 size 5m;
print-time yes;
print-category yes;
severity notice;
};
category default{
"simple_log";
};
};
zone "." IN {
type hint;
file "named.root.hints";
};
ve
/var/named/chroot/var/named/data/named.root.hints
dosyalarını oluşturdum.
Firewall a 192.168.2.0/24 ağından 53 tcp bağlantılarını kabul et dedim.
bind başlangıçta başlasın diye /etc/rc3.d/K87named dosyasını adını S87 yaptım.
/etc/init.d/named start ile servisi başlattım.
dhcpd sunucusuna artık bu dns i kullan dedim;
option domain-name-servers 192.168.2.1;
herhangi bir client dan;
nslookup www.bbc.com
dedim.
Sonuç şu şekilde oldu.
se@bi:~$ nslookup www.bbc.com
Server: 192.168.2.1
Address: 192.168.2.1#53
Non-authoritative answer:
www.bbc.com canonical name = www.bbc.net.uk.
Name: www.bbc.net.uk
Address: 212.58.251.197
Peki ben niye bunla 4 saat uğraştım?
Çünkü http://www.belgeler.org/howto/bind-ile-dns-howto_bind.html dosyasını okumakla işe başlamadım.
gateway olan ve içerine 30 makinaya internet sağlanyan sunucu dışardaki dns sunuculara bakıyordu, ben de dedim kendi sunucumu kurayım, uğraşmasın ikide bir.
Fazla hafife almışım, önce ezbere denedim, sonra bloglardan bişeyler baktım yine olmadı.
Sonra müziği değiştirdim, Eleni Karaindrou'dan The Weeping Meadow u açtım sakinleştim.
Sonra da şöyle yaptım;
Öncelikle güvenlik gereği chroot yapısını kullanacaktım.
yum install bind bind-utils bind-chroot kurdum.
Bunların conf dosyaları eksik geliyor.
/var/named/chroot/etc/named.conf (sample lardan)
dosyası;
options {
directory "/var/named/data";
allow-recursion { 192.168.2.0/24; localhost; }; //kendisi ve içerdeki makinalar dns den faydalansın
};
logging{
channel "simple_log" {
file "/var/log/bind.log" versions 3 size 5m;
print-time yes;
print-category yes;
severity notice;
};
category default{
"simple_log";
};
};
zone "." IN {
type hint;
file "named.root.hints";
};
ve
/var/named/chroot/var/named/data/named.root.hints
dosyalarını oluşturdum.
Firewall a 192.168.2.0/24 ağından 53 tcp bağlantılarını kabul et dedim.
bind başlangıçta başlasın diye /etc/rc3.d/K87named dosyasını adını S87 yaptım.
/etc/init.d/named start ile servisi başlattım.
dhcpd sunucusuna artık bu dns i kullan dedim;
option domain-name-servers 192.168.2.1;
herhangi bir client dan;
nslookup www.bbc.com
dedim.
Sonuç şu şekilde oldu.
se@bi:~$ nslookup www.bbc.com
Server: 192.168.2.1
Address: 192.168.2.1#53
Non-authoritative answer:
www.bbc.com canonical name = www.bbc.net.uk.
Name: www.bbc.net.uk
Address: 212.58.251.197
Peki ben niye bunla 4 saat uğraştım?
Çünkü http://www.belgeler.org/howto/bind-ile-dns-howto_bind.html dosyasını okumakla işe başlamadım.
24 Ekim 2009 Cumartesi
Eskişehir'den gelirken...
"sayın yolcularimiz, Ankara'ya yaklaşmış bulunmaktayiz."
(Hizli Tren Eskisehir kalkış anansu..)
"Yuksek Hizli Tren"
(Niye yüksek, çok da hızlı değil bence)
"Sonraki istasyon, Ankara"
(tek istasyon var zaten)
Olmayan seylerin, varmış gibi olduğu ülke...
(Hizli Tren Eskisehir kalkış anansu..)
"Yuksek Hizli Tren"
(Niye yüksek, çok da hızlı değil bence)
"Sonraki istasyon, Ankara"
(tek istasyon var zaten)
Olmayan seylerin, varmış gibi olduğu ülke...
23 Ekim 2009 Cuma
/etc/passwd dosyasindaki kullanicilarim var bunları nasıl siralar islemler yaparım?
#!/bin/sh
#sabitler
tmp_passwd="/tmp/$0_passwd_gecici"
tmp_passwd_tmp="/tmp/$0_passwd_gecici_tmp"
klasor="/home/vmail"
subs_tmp="/tmp/$0_subs_tmp"
sistem_users="root bin daemon adm lp sync shutdown halt mail news uucp operator games gopher ftp nobody nscd vcsa pcap rpc ma
ilnull smmsp rpcuser nfsnobody sshd dbus avahi haldaemon avahi-autoipd apache ntp mysql dovecot postfix"
date; echo "BASLADI ------------------------------------------------------"
#passwd dosyasini al
cp /etc/passwd $tmp_passwd
#kullanicinin sadece adi kalsin
sed -e s_:x:.*__g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#sistem kulanicilerini yok et
for i in $sistem_users
do
sed -e s/^$i$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
done
#mailnull adındaki kullanici kaliyor, onu da silelim
sed -e s/^mailnull$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#bos satirlari sil
sed '/^$/d' $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#islemleri yapmak uzere kullanicilari sirala
for username in `cat $tmp_passwd`
do
echo islemler
done
#!/bin/sh
#sabitler
tmp_passwd="/tmp/$0_passwd_gecici"
tmp_passwd_tmp="/tmp/$0_passwd_gecici_tmp"
klasor="/home/vmail"
subs_tmp="/tmp/$0_subs_tmp"
sistem_users="root bin daemon adm lp sync shutdown halt mail news uucp operator games gopher ftp nobody nscd vcsa pcap rpc ma
ilnull smmsp rpcuser nfsnobody sshd dbus avahi haldaemon avahi-autoipd apache ntp mysql dovecot postfix"
date; echo "BASLADI ------------------------------------------------------"
#passwd dosyasini al
cp /etc/passwd $tmp_passwd
#kullanicinin sadece adi kalsin
sed -e s_:x:.*__g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#sistem kulanicilerini yok et
for i in $sistem_users
do
sed -e s/^$i$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
done
#mailnull adındaki kullanici kaliyor, onu da silelim
sed -e s/^mailnull$//g $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#bos satirlari sil
sed '/^$/d' $tmp_passwd>$tmp_passwd_tmp ; mv $tmp_passwd_tmp $tmp_passwd
#islemleri yapmak uzere kullanicilari sirala
for username in `cat $tmp_passwd`
do
echo islemler
done
Kaydol:
Kayıtlar (Atom)