Wednesday, January 14, 2009

Webpage Password Protection (.htaccess)

Edit the .htaccess file and add these lines to it:

AuthName "Member's Area Name"
AuthUserFile /full/path/to/.htpasswd
AuthType Basic
require valid-user

Change the file mode:

chmod 755 .htaccess

Go to this site http://www.kxs.net/support/htaccess_pw.html and generate your encrypted password.

Copy and paste it to .htpasswd file (It's recommended that, you create this file in another directory).

Go to web page, you must give your username and password to enter it!

Mysql Performance Tuning - 1

Command: mysqladmin -u root -p extended

The values making most sense to monitor are:

Slave_running: If the system is a slave replication server, this is an indication of the slave's health.
Threads_connected: The number of clients currrently connected. This should be less than some preset value (like 200), but you can also monitor that it is larger than some value to ensure that clients are active.
Threads_running: If the database is overloaded you'll get an increased number of queries running. That also should be less than some preset value (20?). It is OK to have values over the limit for very short times. Then you can monitor some other values, when the Threads_running was more than the preset value and when it did not fall back in 5 seconds.
Aborted_clients: The number of clients that were aborted (because they did not properly close the connection to the MySQL server). For some applications this can be OK, but for some other applications you might want to track the value, as aborted connects may indicate some sort of application failure.
Questions: Number of queries you get per second. Also, it's total queries, not number per second. To get number per second, you must divide Questions by Uptime.
Handler_*: If you want to monitor low-level database load, these are good values to track. If the value of Handler_read_rnd_next is abnormal relative to the value that you normally would expect, it may indicate some optimization or index problems. Handler_rollback will show the number of queries that have been rolled back. You might want to wish to investigate them.
Opened_tables: Number of table cache misses. If the value is large, you probably need to increase table_cache. Typically you would want this to be less than 1 or 2 opened tables per second.
Select_full_join: Joins performed without keys. This should be zero. This is a good way to catch development errors, as just a few such queries can degrease the system's performance.
Select_scan: Number of queries that performed a full table scan. In some cases these are OK but their ratio to all queries should be constant. if you have the value growing it can be a problem with the optimizer, lack of indexes or some other problem
Slow_queries: Number of queries longer than --long-query-time or that are not using indexes. These should be a small fraction of all queries. If it grows, the system will have performance problems.
Threads_created: This should be low. Higher values may mean that you need to increase the value of thread_cache or you have the amount of connections increasing, which also indicates a potential problem.

Command: mysqladmin -u root -p processlist

You can get the number of threads connected and running by using other statistics, but this is a good way to check how long queries that are running take. If there are some very long-running queries (e.g. due to being badly formulated) the admin should be informed. You might also want to check how many queries are in "Locked" state - these are not counted as running but are inactive, i.e. a user is waiting on the database to respond.

Command: mysql -u root -p -e "SHOW INNODB STATUS"

This statement produces a great deal of information, from which you should extract the parts in which you are interested. The first thing you need to check is: "Per second averages calculated from the last xx seconds". InnoDB rounds stats each minute.

Pending normal aio reads: These are InnoDB IO request queue sizes. If they are bigger than 10-20 you might have some bottleneck.
reads/s, avg bytes/read, writes/s, fsyncs/s: These are IO statistics. Large values for reads/writes means the IO subsystem is being loaded. Proper values for these depend on your system configuration.
Buffer pool hit rate: The hit rate also depends a lot on your application. Check your hit rate, when there are problems.
inserts/s, updates/s, deletes/s, reads/s: These are low level row operations that InnoDB does. You might use these to check your load if it is in expected range.


You can examine the state of the cache from the mysql command line:

mysql> show status like 'qcache%';

+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 9990 |
| Qcache_free_memory | 34431360 |
| Qcache_hits | 2165383 |
| Qcache_inserts | 461500 |
| Qcache_lowmem_prunes | 113692 |
| Qcache_not_cached | 1894 |
| Qcache_queries_in_cache | 28203 |
| Qcache_total_blocks | 66628 |
+-------------------------+----------+
8 rows in set (0.00 sec)

Here we can see that there have been 2 million cache hits and that about half of the allocated cache is still available (free_memory). The cache has been flushed (lowmem_prunes), so it might be useful to increase the value of cache_size in my.cnf slightly.

Tuesday, January 13, 2009

Change Crontab Editor

Temporary:
env EDITOR=vim crontab -e


Permanently:

add this line in ~/.bashrc:

export EDITOR=vim

Apache Tuning

Links:

(Apache)
http://phplens.com/phpeverywhere/tuning-apache-php
http://httpd.apache.org/docs/1.3/misc/perf-tuning.html
http://perl.apache.org/docs/1.0/guide/performance.html#the_crashme_Script
http://tldp.org/LDP/LGNET/123/vishnu.html
http://www.perlcode.org/tutorials/apache/tuning.html
http://drupal.org/node/215516

(PHP)
http://phplens.com/lens/php-book/optimizing-debugging-php.php

Apache is configured using the httpd.conf file. The following parameters are particularly important in configuring child processes:

Directive

Default

Description

MaxClients

256

The maximum number of child processes to create. The default means that up to 256 HTTP requests can be handled concurrently. Any further connection requests are queued.

StartServers

5

The number of child processes to create on startup.

MinSpareServers

5

The number of idle child processes that should be created. If the number of idle child processes falls to less than this number, 1 child is created initially, then 2 after another second, then 4 after another second, and so forth till 32 children are created per second.

MaxSpareServers

10

If more than this number of child processes are alive, then these extra processes will be terminated.

MaxRequestsPerChild

0

Sets the number of HTTP requests a child can handle before terminating. Setting to 0 means never terminate. Set this to a value to between 100 to 10000 if you suspect memory leaks are occurring, or to free under-utilized resources.

For large sites, values close to the following might be better:

MinSpareServers 32

MaxSpareServers 64

Apache on Windows behaves differently. Instead of using child processes, Apache uses threads. The above parameters are not used. Instead we have one parameter: ThreadsPerChild which defaults to 50. This parameter sets the number of threads that can be spawned by Apache. As there is only one child process in the Windows version, the default setting of 50 means only 50 concurrent HTTP requests can be handled. For web servers experiencing higher traffic, increase this value to between 256 to 1024.

Other useful performance parameters you can change include:

Directive

Default

Description

SendBufferSize

Set to OS default

Determines the size of the output buffer (in bytes) used in TCP/IP connections. This is primarily useful for congested or slow networks when packets need to be buffered; you then set this parameter close to the size of the largest file normally downloaded. One TCP/IP buffer will be created per client connection.

KeepAlive [on|off]

On

In the original HTTP specification, every HTTP request had to establish a separate connection to the server. To reduce the overhead of frequent connects, the keep-alive header was developed. Keep-alives tells the server to reuse the same socket connection for multiple HTTP requests.

If a separate dedicated web server serves all images, you can disable this option. This technique can substantially improve resource utilization.

KeepAliveTimeout

15

The number of seconds to keep the socket connection alive. This time includes the generation of content by the server and acknowledgements by the client. If the client does not respond in time, it must make a new connection.

This value should be kept low as the socket will be idle for extended periods otherwise.

MaxKeepAliveRequests

100

Socket connections will be terminated when the number of requests set by MaxKeepAliveRequests is reached. Keep this to a high value below MaxClients or ThreadsPerChild.

TimeOut

300

Disconnect when idle time exceeds this value. You can set this value lower if your clients have low latencies.

LimitRequestBody

0

Maximum size of a PUT or POST. O means there is no limit.

If you do not require DNS lookups and you are not using the htaccess file to configure Apache settings for individual directories you can set:

# disable DNS lookups: PHP scripts only get the IP address

HostnameLookups off

# disable htaccess checks

AllowOverride none

If you are not worried about the directory security when accessing symbolic links, turn on FollowSymLinks and turn off SymLinksIfOwnerMatch to prevent additional lstat() system calls from being made:

Options FollowSymLinks

#Options SymLinksIfOwnerMatch


MaxClients:

You can, and should, control the MaxClients setting so that your server does not spawn so many children it starts swapping. The procedure for doing this is simple: determine the size of your average Apache process, by looking at your process list via a tool such as top, and divide this into your total available memory, leaving some room for other processes.


MaxRequestsPerChild:

when using PHP's persistent database connections: don't set MaxRequestsPerChild too high so idle resources are released quickly

Tools:

http://2bits.com/articles/tools-for-performance-tuning-and-optimization.html

HTTPERF:
ftp://ftp.hpl.hp.com/pub/httperf/

ab (Apache Benchmark)


PHP:

Enable the compression of HTML by putting in your php.ini:

output_handler = ob_gzhandler

Tuesday, January 6, 2009

Mysql Multiple Instance

Add mysqld_admin part in /etc/mysql/my.cnf:

[mysqld_multi]
mysqld = /usr/bin/mysqld_safe
mysqladmin = /usr/bin/mysqladmin
user = multi_admin
password = multi

Add new instance parameters:

[mysqld3]
socket = /var/run/mysqld/mysql3.sock
port = 3308
pid-file = /var/run/mysqld/mysql3.pid
datadir = /var/lib/mysql/data3
language = /usr/share/mysql/english
server-id = 5

Build new Data directory:

mysql_install_db --user=mysql --ldata=/var/lib/mysql/data3

Restart mysql server:

/etc/init.d/mysql restart

Start new instance:

mysqld_multi start 3

Check that is runing:

mysqld_multi report 3

Set the root password for new instance:

mysqladmin -uroot password "NEWPASSWORD" -S /var/run/mysqld/mysql3.sock

Check new instance is available:

mysql -uroot -p -S /var/run/mysqld/mysql3.sock

Wednesday, December 31, 2008

Change RAMDISK size in Debian

Edit /boot/grub/menu.lst (or grub.conf or lilo.conf) and add ramdisk_size=512000 to this line:
kernel /vmlinuz root=/dev/md1 ro console=tty0 console=ttyS0,57600

kernel /vmlinuz root=/dev/md1 ro ramdisk_size=512000 console=tty0 console=ttyS0,57600

it defines 512 MB Ramdisk.

Reboot system.

To create an ext2fs file system, the following command is used :

mke2fs -m 0 /dev/ram0

The -m 0 option keeps mke2fs from reserving any space on the file system for the root user. This makes the complete ramdisk space available to any regular user.


To mount the ramdisk :


mkdir /mnt/RAMDISK
mount /dev/ram0 /mnt/RAMDISK

Run mount to check whether the RAMDISK has been mounted.
Now the RAMDISK can be used as a regular directory. You can read, write, delete and modify files on the RAMDISK as if you are working on a regular hard disk. Linux would handle it as if it were handling a regular directory on the disk. The difference between RAMDISK and normal DISK would be invisible to a regular user.

The only problem is that if the system is either rebooted or crashes. In that case, all data in the RAMDISK is lost. You will need to recreate the RAMDISK and redo all that has been done.

Wednesday, November 26, 2008

Keyboard problem in VMware under Ubuntu 8.10

In VMWARE Server on my fresh install of Ubuntu 8.10,after powering on a Windows XP vm, I realized that I could not use the some keys properly. On hitting the left arrow key, start menu was being displayed and other arrow keys had similar issues. Also, using VMware player was completely impossible as ctrl-alt-del wasn’t working.

To fix this issue, you simply need to run the following command,

echo 'xkeymap.nokeycodeMap = true' > /etc/vmware/config

Thursday, November 13, 2008

Install Mysql Activity Report on Ubuntu

Install these two packages:

apt-get install librrd2-dev libmysqlclient15-dev

Download the Mysql Report Activity:

wget http://freshmeat.net/redir/mysqlard/...d-1.0.0.tar.gz

tar -xvzf mysqlard-1.0.0.tar.gz
cd mysqlard-1.0.0

./configure
make
make install

Edit /usr/local/share/mysqlard/mysqlar.php and change username and password for your Mysql Database.

Give access right to www-data user for vim /usr/local/share/mysqlard/ :

chown www-data.www-data /usr/local/share/mysqlard/mysqlar.php

Add the alias to apache config file ( I added a new conf file in /etc/apache2/conf.d/ ):

vim /etc/apache2/conf.d/mysqlard.conf

and add these lines to it:

Alias /mysqlard /usr/local/share/mysqlard

"Directory /usr/local/share/mysqlard"

php_flag register_globals off

Options Indexes FollowSymLinks

"IfModule mod_dir.c"

DirectoryIndex mysqlard.php
"/IfModule"

"/Directory"


(change "" with <>).

Create a user in MYSQL:

GRANT USAGE ON *.* TO mysqlar@localhost;

and then change the user in mysqlar.php.

Check too all paths in these files:

mysqlard.server

mysqlard.cnf
mysqlard_graph

Copy the following files in appropriate crontab folders:
mysqlar.daily
mysqlar.weekly
mysqlar.monthly

You need to add a cron job to generate the graphs. For example :
*/5 * * * * root hourly=1 daily=1 weekly=1 monthly=1\
/usr/bin/mysqlar_graph > /dev/null

Restart apache2 service:

/etc/init.d/apache2 restart

You can access Mysql Activity Report with following url:

http://localhost/mysqlard/mysqlar.php

Apache Server Status

The Status module allows a server administrator to find out how well their server is performing. A HTML page is presented that gives the current server statistics in an easily readable form. If required this page can be made to automatically refresh (given a compatible browser). Another page gives a simple machine-readable list of the current server state.

The details given are:

  • The number of worker serving requests
  • The number of idle worker
  • The status of each worker, the number of requests that worker has performed and the total number of bytes served by the worker (*)
  • A total number of accesses and byte count served (*)
  • The time the server was started/restarted and the time it has been running for
  • Averages giving the number of requests per second, the number of bytes served per second and the average number of bytes per request (*)
  • The current percentage CPU used by each worker and in total by Apache (*)
  • The current hosts and requests being processed (*)
The lines marked "(*)" are only available if ExtendedStatus is On.

To enable status reports only for browsers from the foo.com domain add this code to your /etc/apache2/apache2conf configuration file:

"Location /server-status"
SetHandler server-status
Order Deny,Allow
Deny from all
Allow from foo.com

"/Location"

(change " with <>)

You can now access server statistics by using a Web browser to access the page http://your.server.name/server-status

You can get the status page to update itself automatically if you have a browser that supports "refresh". Access the page http://your.server.name/server-status?refresh=N to refresh the page every N seconds.

A machine-readable version of the status file is available by accessing the page http://your.server.name/server-status?auto. This is useful when automatically run, see the Perl program in the /support directory of Apache, log_server_status.

Wednesday, November 12, 2008

Mount a remote folder in Ubuntu

SSHFS (Secure SHell FileSystem) is a file system for Linux capable of operating on files on a remote computer.

apt-get install sshfs

(Remote host must run the ssh daemon)

sshfs
remoteuser@remotehost:/path/to/remote_dir local_mountpoint

Thursday, November 6, 2008

Zoneminder in Ubuntu

In Ubuntu run:

apt-get install zoneminder

apt-get -f install

modprobe -r zc0301
modprobe -r gspca
modprobe gspca

add this line to /etc/modprobe.d/blacklist:
blacklist zc0301

Give access right to Video Devices:

chmod 777 /dev/video(x)

Thursday, October 23, 2008

Friday, October 17, 2008

Enable SSH in VMware ESX 3.x

ESXi 3.5 does ship with the ability to run SSH, but this is disabled by default (and is not supported). If you just need to access the console of ESXi, then you only need to perform steps 1 - 3.

1) At the console of the ESXi host, press ALT-F1 to access the console window.

2) Enter unsupported in the console and then press Enter. You will not see the text you type in.

3) If you typed in unsupported correctly, you will see the Tech Support Mode warning and a password prompt. Enter the password for the root login.

4) You should then see the prompt of ~ #.

Edit the file inetd.conf (enter the command vim /etc/inetd.conf).

5) Find the line that begins with #ssh and remove the #. Then save the file.

6) Once you've closed the vi editor, run the command /sbin/services.sh restart to restart the management services. You'll now be able to connect to the ESXi host with a SSH client.