SLOW log in over SSH

If you are experiencing very long delays when logging into linux systems using SSH.

It could be waiting for Reverse DNS to time out before giving the login prompt or password prompt.

I made the following change to fix it in the /etc/ssh/sshd_config

 

vi /etc/ssh/sshd_config

Make sure the useDNS line looks like this:

UseDNS no

 

 

Posted in Uncategorized | Leave a comment

Analyzing mysql slow query logs

The mysql servers we use are configured to log slow queries ( those that take over 5 seconds to run or queries that do not use any index).

The output is put in /var/log/mysqld.slow.log  ( on the dbhost server! )

I found a program today that is part of mysql that makes it easier to use this log file to pinpoint queries that might be slowing things down.  It is called mysqldumpslow

To run it just pass the name of the log file and it converts the variables in the queries in the log file to tokens so it can group similar queries together and tell you how often a particular query is run.  It sorts the queries by how long they take to run, so you can focus on queries your apps are running that are taking a long time to run ( and making the user wait )

Typically adding indexes or rewriting the query to be more efficient can greatly improve performance.

For example I just ran it on our db1 log and immediately realized that the query we run to check a persons PKI DN certificate ( which is run for every page we display ) was doing the query with no index on pki_dn field  — so it was sequentially scanning through the users table every time.   I created an index on pki_dn that should make that check faster.

To use it:

 

/usr/bin/mysqldumpslow /var/log/mysqld.slow.log

 

NOTE: your mysql database must be configure to log slow queries.  This is done with the following queries in /etc/my.cnf  ( in the main [mysqld] section )

log-slow-queries = /var/log/mysqld.slow.log
log-long-format
long_query_time = 5
log-queries-not-using-indexes=1

 

If the file doesn’t already exist it won’t create it. So be sure to make the file /var/log/mysqld.slow.log and set permissions to be writable by mysql user and restart mysql like this:

> /var/log/mysqld.slow.log

chown mysql:mysql /var/log/mysqld.slow.log

chmod 770 /var/log/mysqld.slow.log

service mysqld restart

Posted in Uncategorized | Tagged | Leave a comment

Upgrading PHP on redhat 5



I updated the php ona redhat box today.

This upgrade now seems to fix a bug in PHP that wouldn’t allow values of > 1.5 Gig on file uploads

I have the settings now set to allow up to 2.5Gig.

The steps I took to upgrade it were:

 

Be sure to save the /etc/php.ini  file first:

cp /etc/php.ini /etc/php.ini.save

 

service httpd stop

 

yum erase php.x86_64 php-cli.x86_64 php-common.x86_64 php-devel.x86_64 php-mysql.x86_64 php-pdo.x86_64 php-pear.noarch php-pear-MDB2.noarch php-pear-MDB2-Driver-mysql.noarch

 

yum install php53.x86_64 php53-cli.x86_64 php53-common.x86_64 php53-devel.x86_64 php53-mysql.x86_64 php53-pdo.x86_64 php-pear.noarch php-pear-MDB2.noarch php-pear-MDB2-Driver-mysql.noarch

 

Edit the Newly installed php.ini file and copy the customizations we have ( at the top of the file )  (NOTE these also exist further down in the file and need to be commented out there in the new file so the only reference to those settings is at the top with our desired values.

 

service httpd start

[root@svn_repo etc]# vi /etc/php.ini

[PHP]

***** Customizations *******

allow_call_time_pass_reference = On

include_path=”.:/usr/share/pear:/php/includes:/usr/local/lib/php/Smarty”

max_execution_time = 60000

max_input_time = 60000

memory_limit = 2500M

upload_tmp_dir = /www/upload_tmp_dir

 

; Maximum allowed size for uploaded files.

;  IMPORTANT NOTE

;  DO NOT SET THESE variables > 1500M

;  apache gets confused and treats it as a negative number

;  and not allow anything to post..  K. Meek 10/09

; NOTE — make sure the post_max_size and upload_max_filesize is not set to another value below!!

post_max_size = 2500M

upload_max_filesize = 2500M

 

;*****  end customizations ****

 

 

Posted in Uncategorized | Leave a comment

Using Handler postDelayed to queue a task for later execution

I figured out how to get my android app to auto post after a certain amount of idle time.

 

Trick was to create a handler in the activity that is running.

 

Then make a “Runnable” function that will do what you want. — think of this as the “function to be run later”.

 

To call it later issues handler.postDelayed(runnable_function,20000);

 

If the user does something that makes you want to “reset” or cancel the pending call you can call handler.

private Handler handler = new Handler();

final Runnable post_score = new Runnable()
{
public void run()
{
Toast.makeText(getApplicationContext(), “Posting Score in Background.”, Toast.LENGTH_SHORT).show();
new PostScoreTask().execute(S);
}
};

 

// Queue up a message to Post this score
handler.removeCallbacks(post_score);
handler.postDelayed(post_score, auto_post_delay);

 

I call these two commands above any time the user changes something that should be posted to the server.  But each time they do something we cancel any pending posts and “Queue” up another message to ask that it be done after the specified auto_post_delay. ( which is an integer set to number of milliseconds to wait before posting.
This should cause the posting to be “near Real time” but not waste internet resources posting until current input has been completed.

 

 

Posted in Uncategorized | Leave a comment

SELINUX local policy creation

Run the command

audit2allow -m local -l > local.te < /var/log/audit.log

This will generate a local.te file that will have the policy to allow the things denied int he current audit.log

You’ll want to review closely to see if those are in fact the things you want to allow.

To turn this into a binary module you use this command:

checkmodule -M -m -o local.mod local1.te

To Create a policy that can be loaded into the kernel use this

semodule_package -o local.pp -m local.mod

Then to activate it use this

semodule -i local.pp

Posted in Uncategorized | Tagged | Leave a comment

Run subcommand and return output to variable in PHP

If you need to run a subcommand and pull the output you can use the proc_open like below.

Kevin

 

$descriptorspec = array(

0 => array(“pipe”, “r”),  // stdin is a pipe that the child will read from

1 => array(“pipe”, “w”),  // stdout is a pipe that the child will write to

2 => array(“file”, “/tmp/yourprocoutput.txt”, “a”) // stderr is a file to write to

);

$process = proc_open(“/bin/ls -l /tmp”, $descriptorspec, $pipes);

while (!feof($pipes[1])) {

$result .= fread($pipes[1], 8192);

print “.”;

}

print “RESULT: [$result] \n”;

?> 

Posted in Uncategorized | Tagged | Leave a comment

Refreshing jquery-ui tabs using php xajax calls

I have a jquery-ui tab displays information that can be edited using a xajax pop up dialog.

After saving the dialog I wanted to “refresh” the current tab.

This little bit of code in the server did the trick.

 
$objResponse->addScript(‘ $(“#dialog”).dialog(‘ . “‘close’);”);
$objResponse->addRemove(‘dialog’);
$mycmd = << $(“#tabs”).tabs(‘load’,$(“#tabs”).tabs(‘option’,’selected’));
MY_DELIMITER;
$objResponse->addScript($mycmd);

Posted in Uncategorized | Tagged , , | Leave a comment

Making textarea boxes expand on entry

If you have ever worked with web forms you know that editing a large amount of text can be painful when you can only see a few lines of text at a time.

Firefox 4 has a nifty feature that gives you draggable resize icon on the bottom of all textarea boxes. This is nice, but rather than have to resize a field every time, I like this trick. Just by adding the onclick and onblur tags to the textarea box as shown below you can make the text box EXPAND when you click into it to make it easier to edit.

Adjust the rows as you see fit.