Saturday, 26 November 2011

Enabling the slow query log

MySQL reports how much time it took to execute a query.

Step 1: Enable slow log query, set a slow log query log file, and set the log_query_time in my.cnf.
Edit the MySQL configuration file.


vi /etc/my.cnf



 

In the [mysqld] section add/edit the following variables


long_query_time = 0
slow_query_log = 1
slow_query_log_file=/var/log/mysqld.slow.query.log



We are setting the log_query_time variable to 0. Any MySQL query taking more than 0 seconds will be logged.

 

Step 2: Create the file /var/log/mysqld.slow.query.log and set the system user mysql as the owner.


touch /var/log/mysqld.slow.query.log
chown mysql.mysql /var/log/mysqld.slow.query.log



 

Step 3: Restart MySQL server


/etc/init.d/mysqld restart



 

Step 4: Watch the slow query log using the tail command.


tail -f /var/log/mysqld.slow.query.log



 

A sample entry on my server looks like this:

[root@localhost ~]# tail -f /var/log/mysqld.slow.query.log 
SET timestamp=1255345490;
SELECT `privilege`.* FROM `privilege` WHERE ( name = 'view service invoices"') LIMIT 1;
# User@Host: biz_1[biz_1] @ localhost []
# Query_time: 0.000273 Lock_time: 0.000104 Rows_sent: 1 Rows_examined: 1
SET timestamp=1255345490;
SELECT * FROM organization_details;
# User@Host: biz_1[biz_1] @ localhost []
# Query_time: 0.000048 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 1
SET timestamp=1255345490;
# administrator command: Quit;


If you observe the log entry, the last query took 0.000048 seconds.

Enable MySQL General Query

Enabling the general query log


Step 1: Set your log file in /etc/my.cnf


vi /etc/my.cnf



In the [mysqld] section specify the general log file name:


log=/var/log/mysqld.general.log



 

Step 2: Create the file and make sure it is owned by the system user mysql


touch /var/log/mysqld.general.log
chown mysql.mysql /var/log/mysqld.general.lo



 

Step 3: Enable the general log in the MySQL client. Connect to the MySQL server using the MySQL client and execute this query.


SET GLOBAL general_log = 'ON';



 

Step 4: Restart mysqld and watch the logs


/etc/init.d/mysqld restart



 

To watch the logs use the tail command.


tail -f /var/log/mysqld.general.log



 

A sample entry in my general query log looks like:

[root@localhost ~]# 
[root@localhost ~]# tail -f /var/log/mysqld.general.log
091012 13:52:53 2 Query SELECT `profile`.* FROM `profile` WHERE (user_id = 1) LIMIT 1
2 Query SELECT `u`.`user_id`, `u`.`email`, `u`.`status`, `u`.`mode`, `u`.`hash`, `u`.`created`, `u`.`alt_email`, `u`.`host_created`, `u`.`ip_created`, `u`.`user_timezone`, `p`.*, `r`.`name` AS `primaryRoleName`, `urp`.`email` AS `reportsToEmail`, `b`.`branch_name` FROM `user` AS `u`
LEFT JOIN `profile` AS `p` ON p.user_id = u.user_id
LEFT JOIN `role` AS `r` ON r.role_id = p.primary_role
LEFT JOIN `user` AS `urp` ON urp.user_id = p.reports_to
LEFT JOIN `branch` AS `b` ON b.branch_id = p.branch_id WHERE (u.user_id = '1')
2 Query SELECT `profile`.* FROM `profile` WHERE (user_id = 1) LIMIT 1
2 Query SELECT `privilege`.* FROM `privilege` WHERE ( name = 'view service invoices"') LIMIT 1
2 Query SELECT * FROM organization_details
2 Quit

Monday, 21 November 2011

[FIX] Cannot update domain or sub domain configuration in IIS

APPLIES TO:


  • Parallels Plesk Panel for Windows



 Symptoms


When attemting to reconfigure domain or sub domain configuration in IIS using thewebsrvmng.exe  Plesk tool an error message is received. For a domain:
"%plesk_bin%websrvmng.exe" --reconfigure-vhost --vhost-name=domain.com

The system cannot find the file specified. (COM Error 80070002) For a sub domain:
"%plesk_bin%websrvmng.exe" --update-subdomain --vhost-name=domain.com --subdomain=sub

The system cannot find the file specified. (COM Error 80070002) at configSubdomain(sub.domain.com)


Cause


Some default folders for Plesk domain are missing in (sub) domain root folder.


Resolution


The missing folders need restoring using the Plesk reconfigurator.  This feature checks files permissions + restores missing folders + creates missing system users for (sub) domain. It can be executed via command line as follows:
reconfigurator.exe /check-permissions=domain.com

or using Plesk Panel.

Plesk, Domains, domain.com, check on problem domain, click `Check permissions`.

This should eliminate the source and the command should running properly. For a subdomain, the parent domain needs to be checked.


Monday, 31 October 2011

Linux: /tmp: Read-only file system Error

One of the server that  has problem as below when I want to edit some files in crontab:


$ crontab -e
/tmp/crontab.XXXX1ibTLU: Read-only file system



It shows that the /tmp partition is unwriteable. The read-only has been mounted as read-only because file-system facing some error. To fix this, we need to do file system check (fsck) for /tmp partition. Before we do fsck, we need to unmount the directory but following error occurred:


$ umount /tmp
/tmp: Device or resource busy



It seems like /tmp directory is locked to be unmounted due to some files are already in process/being opened/being executed by some other processes. Using lsof, we can list out all the open files:


$ lsof | grep /tmp
mysqld 2599 mysql 5u REG 7,0 0 6098 /tmp/ibaqFhew (deleted)
mysqld 2599 mysql 6u REG 7,0 0 6099 /tmp/ibC7Yfbn (deleted)
mysqld 2599 mysql 7u REG 7,0 0 6100 /tmp/ibJ8AFbe (deleted)
mysqld 2599 mysql 11u REG 7,0 0 6101 /tmp/ibrLO9t5 (deleted)



As we can see that mysqld is locking some temporary files in /tmp directory. The 2nd column shows PID of the locking process. We need to stop this process using kill command:


$ kill -9 2599



Only then we are able to unmount the /tmp:


$ umount /tmp



Make sure that there is no error being prompt during the unmounting process. Now we can proceed to do fsck with -f (force) and -y (always accept prompt as Yes) to automate the file system check process:


$ fsck -f -y /tmp
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
/usr/tmpDSK: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Deleted inode 6097 has zero dtime. Fix? yes

Inodes that were part of a corrupted orphan linked list found. Fix? yes

Inode 6098 was part of the orphaned inode list. FIXED.
Inode 6099 was part of the orphaned inode list. FIXED.
Inode 6100 was part of the orphaned inode list. FIXED.
Inode 6101 was part of the orphaned inode list. FIXED.
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Inode bitmap differences: -(6097--6101)
Fix? yes

Free inodes count wrong for group #3 (2025, counted=2030).
Fix? yes

Free inodes count wrong (127695, counted=127700).
Fix? yes

/usr/tmpDSK: ***** FILE SYSTEM WAS MODIFIED *****
/usr/tmpDSK: 316/128016 files (3.2% non-contiguous), 66394/512000 blocks



Now the file system has been modified and fixed. We can remount back the partition using following command:


$ mount -a



You should able to use back the /tmp partition at this time, as well as I can do some changes on the crontab!

How to change mail attachment size

To change mail attachment size, we have to change 3 settings.

To change mail attachment size, we have to change 3 settings.
Change mail size in postfix

Postfix is MTA, so we have to change its setting to make it transfer large mail.

If you want to make it allow to transfer mail which size is less than 100Mb, just change 'message_size_limit' setting:

# ---- Run below command in terminal ---- 
# postconf -e message_size_limit='104857600' 
# ---- Restart postfix to make it work ---- 
# /etc/init.d/postfix restart


Note:

  • 104857600 is equal to 100MB x 1024 KB x 1024 Bit.

  • Normally, mail will be encoded before transferred, so the actual mail size will be larger than 100MB, you can simplily increase to 110Mb or 120Mb to make it work as expected.


----
If you use mail clients such as Outlook, thunderbird to fetch/send mails, it's enough to sent large attachments in mail.
If your users will use webmail as mail client, you have to change two more settings:
Change PHP setting to allow to upload large attachment

You should change 'memory_limit', 'upload_max_filesize' and 'post_max_size' in /etc/php.ini (RHEL/CentOS) or/etc/php5/apache2/php.ini (Debian/Ubuntu).

memory_limit = 200M; 
upload_max_filesize = 100M; 
post_max_size = 100M;


Change Roundcube webmail to allow to upload large attachment

Change same settings in .htaccess which under roundcube root directory, it's /usr/local/cpanel/base/3rdparty/roundcube/ (RHEL/CentOS) or  /usr/share/apache2/roundcube/ (Debian/Ubuntu) by default.

php_value upload_max_filesize 100M 
php_value post_max_size 100M


Restart apache web server



# ---- For RHEL/CentOS users ---- 
# /etc/init.d/httpd restart 
# ---- For Debian/Ubuntu users ---- 
# /etc/init.d/apache2 restart




Sunday, 30 October 2011

PCI compliance – Vulnerability SSL Version 2 (v2) Protocol Detection linux

Simple enough to fix on apache.

Load the ssl.conf file and add at the bottom the following:

SSLProtocol -ALL +SSLv3 +TLSv1

then restart apache.

To test the connection on the command line type:

openssl s_client -ssl2 -connect google.com:443

Monday, 24 October 2011

How to assign a dedicated IP to a Sub-domain OR Add-on/Park domain?

By default, cPanel allows one IP per account, however, in case you wish to assign multiple IPs to an account, say for a sub-domain, you can do so by editing a few files. Follow the below steps:

1) The main configuration file of a domain is stored under the /var/cpanel/userdata/<username>/ directory, so edit the subdomain related file under it

# vi /var/cpanel/userdata/<username>/subdomain.domain.tld


Change the value of “IP” to a dedicated IP and save the file. The add-on and Park domains have their related subdomain files in the same directory.

2) Once the above changes are made, you need to rebuild the Apache configuration for the changes to take affect in the respective VirtualHost entry

# /scripts/rebuildhttpconf


3) To mark the dedicated IP as “used”, edit the file /etc/domainips and enter the sub-domain entry

<dedicated ip>: subdomain.domain.tld


Save the file and rebuild the IP pool

# /scripts/rebuildippool


4) Now, edit the DNS zone file of the main domain (i.e. the domain under which the subdomain is created)

# vi /var/named/domain.tld.db


and set the A record of the sub-domain to point to the new IP. Save the file and restart the ‘named’ service

# service named restart


That’s it.

Note: Rebuilding the IP pool will still list the IP as free under the WHM -> IP Function -> ‘Show IP Address Usage’, however WHM wont allow you to assign that IP to another domain.