Memory Usage with /proc/meminfo

The entries in the /proc/meminfo can help explain what's going on with your memory usage, if you know how to read it.

Example of `cat /proc/meminfo`:

        total:    used:    free:  shared: buffers:  cached:
Mem:  1050001408 1012899840 37101568        0 113672192 420950016
Swap: 2097434624 217985024 1879449600
MemTotal:      1025392 kB
MemFree:         36232 kB
MemShared:           0 kB
Buffers:        111008 kB
Cached:         279304 kB
SwapCached:     131780 kB
Active:         677908 kB
ActiveAnon:     487272 kB
ActiveCache:    190636 kB
Inact_dirty:    129164 kB
Inact_laundry:   23948 kB

Tuning / Optimizing my.cnf file for MySQL

Had to do some fine tuning of MySQL 4.1.9 and here is what my.cnf file looks like for a 2GHz machine with 1GB of memory.

[mysqld]
socket=/path/to/mysql.sock
datadir=/var/lib/mysql
skip-locking
skip-innodb
# MySQL 4.x has query caching available.
# Enable it for vast improvement and it may be all you need to tweak.
query_cache_type=1
query_cache_limit=1M
query_cache_size=32M
# max_connections=500
# Reduced to 200 as memory will not be enough for 500 connections.
# memory=key_buffer+(sort_buffer_size+read_buffer_size)*max_connections

Accelerating PHP with eAccelerator

eAccelerator is a further development from mmcache PHP Accelerator & Encoder. It increases performance of PHP scripts by caching them in compiled state, so that the overhead of compiling is almost completely eliminated.

  • Prior to installing check that php-devel package is installed.
  • Download via http://eaccelerator.net/DownloadEaccelerator
  • Run the below commands to compile and configure:
      # export PHP_PREFIX="/usr"
      # $PHP_PREFIX/bin/phpize
    

PHP Accelerator

PHP Accelerator is an easily installed PHP Zend engine extension that provides a PHP cache, and is capable of delivering a substantial acceleration of PHP scripts without requiring any script changes, loss of dynamic content, or other application compromises.

  1. Installation:
    • Download PHPAccelerator.
    • Unpackage it and move contents to "/usr/local/phpaccelerator".
    • Include the below line to php.ini under dynamic extension section:
          zend_extension="/usr/local/phpaccelerator/php_accelerator_1.3.3r2.so"
      

Protect against HTTP DoS attacks with mod_dosevasive

mod_dosevasive is an evasive maneuvers module for Apache to provide evasive action in the event of an HTTP DoS or DDoS attack or brute force attack. It is also designed to be a detection and network management tool, and can be easily configured to talk to ipchains, firewalls, routers, and etcetera. mod_dosevasive presently reports abuses via email and syslog facilities.

The below steps were used to install mod_dosevasive on Apache-2.

  1. Installation:
    • Check that you have httpd-devel package installed as you will need apxs
    • Download mod_dosevasive.

Check your spellings on the Command Line Interface

The aspell command, from the aspell package is designed to spell check files. This package also provides the command spell, ispell, and run-with-aspell which call aspell in different ways.

For example, to check if the word "compatible" is correct, execute the command:

echo compatible|aspell -a

The output should be similar to:

@(#) International Ispell Version 3.1.20
*

This output shows that "compatible" is spelt correctly.

However, if you try to check the word "compatable," the output would be:

@(#) International Ispell Version 3.1.20

Rolling Back Your System with RPM

Configuring a rollback capability in your system is just a matter of taking a few well-planned steps. They involve creating some macros for the rpm system, choosing a "safe point" - the point in time before which you won't want to roll back your system - and creating an archive directory for rpms replaced by new versions.

Each time you update or uninstall an rpm package in a rollback-enabled system, the rpm is actually repackaged and archived. It's not deleted. That allows you the capability to re-install that package at any time.

Further, the system allows you to use an intuitive rollback criteria, such as `rpm -Uvh --rollback '3 days ago'`. This is done by the use of a field in the rpm database known as the Transaction ID (TID). The repackaged package is also noted with the TID. When rolling back, any package equal to or older than the requested TID (as interpreted from the plain-english time) is re-installed on the system. You can also rollback one particular package by `rpm -Uvh --rollback <package>`.

Redirection of Input and Output...

To read from an input file instead of typing the input in.

$ program < input

To send the output to an output file, this is hard to figure out if the program is interactive, since the prompts go to the output file.

$ program > output

To append the output to an output file

$ program >> output

Read the input from the input file, put the output to the output file.

$ program < input > output

Some programs output data to stderr not stdout ( the compiler is an example ). If you want to capture the compiler warnings in a text file try this.

Encrypting shell scripts

Do you have scripts that contain sensitive information like passwords and you pretty much depend on file permissions to keep it secure? If so, then that type of security is good provided you keep your system secure and some user doesn't have a "ps -ef" loop running in an attempt to capture that sensitive info (though some applications mask passwords in "ps" output). There is a program called "shc" that can be used to add an extra layer of security to those shell scripts. SHC will encrypt shell scripts using RC4 and make an executable binary out of the shell script and run it as a normal shell script. This utility is great for programs that require a password to either encrypt, decrypt, or require a password that can be passed to a command line argument.

vi Editor Basics...

Getting Started

The command "vi" without any file name will open a new file where you can enter the text and edit but while coming out you will be asked to enter a valid file name to save the text.
"vi" with a existing file name will open that file for editing.

Comment