Skip to main content

Posts

Showing posts from May, 2013

What to do if a query is logged in mysql slow query log.

On a mysql server there are a lot of queries to optimize and a lot of load generated by them. I’ll try to present the most usual optimization issues and how to identify them. First you’ll have to check mysql service settings . You can check them manually by following commands in mysql command line: mysql>show variables; or mysql>show variables like ‘%cache%’; and mysql> show status; you can check the counters and increase or decrease them according to their usage and limits. The more easy way is to use some scripts to check mysql settings like : MySQL performance tuning primer script (tuning-primer.sh). First and most important optimization is to activate and set query_cache and query_cache_size to lower disk IO usage. After that you will have to check the running queries . For that you’ll need to enable first : log-slow-queries= /var/lib/mysql/mysql-slow.log long-query-time=3 in my.cnf then touch /var/lib/mysql/mysql-slow.log and set owner as

PHP commands to get Php memory informations

You can put the below code in a memory.php file and then view the result from browser by http://yourdomain.com/memory.php echo 'Current Memory Usage: '.number_format(memory_get_usage()/1024/1024,"2",".",",").' MB'."\r\n"; echo 'Current Memory Allocted: '.number_format(memory_get_usage(true)/1024/1024,"2",".",",").' MB'."\r\n"; echo 'Peak Memory Usage: '.number_format((memory_get_peak_usage()/1024/1024),"2",".",",").' MB'."\r\n"; echo 'Peak Memory Allocated: '.number_format((memory_get_peak_usage(true)/1024/1024),"2",".",",").' MB';

Download file with cURL & PHP

CURLOPT_RETURNTRANSFER is a simple way of copying a file from a remote server onto your own. However, if you’re downloading a large file you may hit memory limits because the entire contents of the download have to be read to memory before being saved. Note: Even if your memory limit is set extremely high, you would be putting unnecessary strain on your server by reading in a large file straight to memory. Instead you can write the download straight to a file stream using CURLOPT_FILE. Download file with cURL & PHP $url = 'http://www.example.com/a-large-file.zip'; $path = '/path/to/a-large-file.zip'; $fp = fopen($path, 'w'); $ch = curl_init($url); curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp);

command to delete the resulting files of Clamscan.

It will be very difficult to delete all the files of the result of Clamscan. In some cases the infected files will be more than 2000. The command for clamscan is # clamscan -r -i /home/username/public_html/ -l clamscan_username.txt # cat clamscan_username.txt Will show the content as : /home/username/public_html/.guestbook/baru.txt: Exploit.E107-1 FOUND /home/username/public_html/newlog/hideme: Hacktool.Fakeproc FOUND /home/username/public_html/newlog/.log/hideme: Hacktool.Fakeproc FOUND /home/username/public_html/newlog/.log/t3394: Linux.RST.B FOUND /home/username/public_html/newlog/.log/guard: Linux.RST.B FOUND You can delete all the files listed there by using the below command in a split of second. # for i in `cat /root/clamscan_username.txt | gawk -F ': ' '{print $1}'`; do rm -rf $i; done Make sure that you have got confirmation from the customer before deleting all his infected files. :-)

Script to find and replace only the MX entries of Specified dns zone files, with SpamExperts MX entries.

#!/bin/bash for i in `cat domains.lst`; do FileName=$i.db; FileBack=$FileName"_bk"; if [ -f $FileName ]; then find . -maxdepth 1 -type f -name $FileName | xargs sed 's/.*MX.*/'"$i."' 14400 IN MX 10 mx.spamexperts.com.\n'"$i."' 14400 IN MX 20 fallbackmx.spamexperts.eu.\n'"$i."' 14400 IN MX 30 lastmx.spamexperts.net./g' > $FileBack; mv -f $FileBack $FileName else echo $FileName " Doesnt Exists...................!!!!! "; fi done Note: Where domains.lst contains the domain names that needs to be replaced the MX entries with SpamExperts MX entries.

How to Upgrade Redmine to 2.3

Step 1 - Check requirements The first step to upgrading Redmine is to check that you meet the requirements for the version you're about to install. Ruby Version: ruby -v Rails Version : rails -v Rubygems Version : gem -v * Ruby should be 1.8.7 or higher. * Rails should be 3.2.13 * Gems should be 1.8 or higher. If rails are not uptodate, you can install the rails with version specific, using the below command: # gem install rails -v=3.2.13 --no-ri --no-rdoc Step 2 - Backup It is recommended that you backup your database and file uploads. Most upgrades are safe but it never hurts to have a backup just in case. A. Backup the files. All file uploads are stored to the files/ directory. You can copy the contents of this directory to another location to easily back it up. B. Backup the database. mysqldump -u redmine_user -predmine123# redmine | gzip > /var/www/redmine_`date +%y_%m_%d`.gz Step 3 - Download the 2.3 stable version # cd /var/www/ # mv rai