Server admin cheatsheet

February 4th, 2013 No comments

PROCESS BASICS

All processes, with params + hierarchy

    ps auxww -H

Show all ruby-related PIDs and processes

    pgrep -fl ruby

What is a process doing?

    strace -f -p $PID

What files does a process have open? (also detects ruby version of a process)

    lsof -p $PID

Flavors of kill

    kill xxxx
    kill xxxx yyyy zzzz
    pkill <name of process>
    pkill -f <word in processname>

Keep an eye on a process

    watch 'ps aux | grep ruby'

TIPS N TRICKS

Run Previous command as root

    sudo !!

Change to last working dir

    cd -

Run something forever

while true;do ruby ghetto.rb; done

MEMORY

How much mem is free?

    free -m
    cat /proc/meminfo

Are we swapping?
First line is avg since boot.

    vmstat 1

List the top 10 memory hogs

    ps aux --sort=-resident|head -11

Detect OOM and other bad things

    for i in messages kern.log syslog; do egrep -i "s[ie] g|oo(m|ps)" /var/log/$i{,.0}; done

Disable OOM killer for a process

   echo -17 > /proc/$PID/oom_adj

TERMINAL & SCREEN

Start a screen session as the current user

    screen -x

Join/re-attach to a screen session

    screen -r

Record a terminal session

   script filename.out 2> filename.timing

Playback a recorded terminal session

   scriptreplay filename.timing filename.out

DISK/FILES

Check reads/writes per disk

    iostat -xnk 5

Files (often logs) marked for deletion but not yet deleted

    lsof | grep delete

Overview of all disks

    df -h

Usage of this dir and all subdirs

    du -hs

Find files over 100MB

    find . -size +100M

Low hanging fruit for free space. Check /var/ log too!

    ls -al /tmp

Find files created within the last 7 days

    find . -mtime -7

Find files older than 14 days

    find . -mtime +14 -type f -name '*.gz'

Delete files older than 14 days

    find *.gz -mtime +14 -type f -exec rm {} \;

Monitor a log file for an IP or anything else

   tail -f file.log | grep 192.168.1.1

NETWORK

TCP sockets in use

    lsof -nPi tcp

Get IP/Ethernet info

    ip addr
    ifconfig

host <=> IP resolution

    host 192.168.1.1
    host MyRouter

Curl, display headers (I), follow redirects (L)

    curl -LI http://google.com

Traceroute with stats over time (top for traceroute) Requires install

    mtr google.com

Traceroute TCP to avoid ICMP blockage

    tcptraceroute google.com

List any IP blocks/rules

    iptables -L

Drop any network requests from IP

    iptables -I INPUT -s 66.75.84.220 -j DROP

Show traffic by port

    iftop

Show all ports listening with process PID

    netstat -tlnp

D/L speed test (don’t run in prod! :)

    wget cachefly.cachefly.net/100mb.test -O /dev/null
Categories: Server Tags:

Integrating Amazon SES with Postfix

August 23rd, 2012 No comments

Postfix was conceived as an alternative to the widely used Sendmail MTA. It is designed to be fast, easy to administer, and secure.

For information about Postfix, go to http://www.postfix.org.

To configure integration using STARTTLS

  1. On your mail server, open the main.cf file. On many systems, this file resides in the /etc/postfix folder.
  2. Add the following lines to the main.cf file, modifying them to reflect your particular situation, and then save the file.
    relayhost = email-smtp.us-east-1.amazonaws.com:25
    smtp_sasl_auth_enable = yes
    smtp_sasl_security_options = noanonymous
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
    smtp_use_tls = yes
    smtp_tls_security_level = encrypt
    smtp_tls_note_starttls_offer = yes
  3. Edit the /etc/postfix/sasl_passwd file. If the file does not exist, create it. Add the following lines to the file, replacing USERNAME and PASSWORD with your SMTP user name and password.
    email-smtp.us-east-1.amazonaws.com:25 USERNAME:PASSWORD
    ses-smtp-prod-335357831.us-east-1.elb.amazonaws.com:25 USERNAME:PASSWORD
  4. Save the sasl_passwd file.
  5. At a command prompt, issue the following command to create an encrypted file containing your SMTP credentials.

    sudo postmap hash:/etc/postfix/sasl_passwd

  6. Remove the /etc/postfix/sasl_passwd file.
  7. Tell Postfix where to find the CA certificate (needed to verify the SES server certificate).

    If running on the Amazon Linux AMI:

    sudo postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/ca-bundle.crt'

    If running on Ubuntu Linux:

    sudo postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt'

To configure integration using a secure tunnel

  1. To begin, you will need to set up a secure tunnel as described in Setting Up a Secure Tunnel. In the following procedure, we use port 2525 as yourstunnel port. If you are using a different port, modify the settings that you actually use accordingly.
  2. On your mail server, open the main.cf file. On many systems, this file resides in the /etc/postfix folder.
  3. Add the following lines to the main.cf file, modifying them to reflect your particular situation, and then save the file.
    relayhost = 127.0.0.1:2525
    smtp_sasl_auth_enable = yes
    smtp_sasl_security_options = noanonymous
    smtp_tls_security_level = may
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
  4. Edit the /etc/postfix/sasl_passwd file. If the file does not exist, create it. Add the following line to the file, replacing USERNAME and PASSWORD with your SMTP user name and password.
    127.0.0.1:2525 USERNAME:PASSWORD
  5. Save the sasl_passwd file.
  6. At a command prompt, issue the following command to create an encrypted file containing your SMTP credentials.

    sudo postmap hash:/etc/postfix/sasl_passwd

  7. Remove the /etc/postfix/sasl_passwd file.

When you have finished updating the configuration, restart Postfix. At the command line, type the following command and press ENTER.

sudo /etc/init.d/postfix restart

Note

This command may not be exactly the same on your particular server.

When you have completed this procedure, your outgoing email will be sent via the Amazon SES SMTP interface. To verify that this change was successful, send an email message through your Postfix server, and then verify that it arrives at its destination. If the message is not delivered, check your system’s mail log for errors. On many systems, the log file is /var/log/mail.log.

Categories: Server Tags:

convert to utf8

November 8th, 2011 No comments

#/bin/bash
LIST=`find . -name *.inc`
for i in $LIST;
do iconv -c -f euc-kr -t utf8 $i -o $i.”utf8″;
mv $i.”utf8″ $i;
done

Categories: Server, System Tags:

magento upgrade

August 31st, 2011 No comments

rm -rf /var/cache session
./mage mage-setup .
./mage config-set preferred_state stable
./mage list-installed
./mage list-upgrades
./mage install http://connect20.magentocommerce.com/community Mage_All_Latest –force
./shell php indexer.php reindexall

 

app/etc/config.xml

<initStatements>SET NAMES utf8; SET FOREIGN_KEY_CHECKS=0; SET UNIQUE_CHECKS=0;</initStatements>

Categories: Programming, System, Web Tags:

Magento 1.5.0.1 core_directory_storage problem

May 2nd, 2011 No comments
/app/code/core/Mage/Core/Model/Mysql4/File/Storage/Directory/Database.php
CREATE TABLE IF NOT EXISTS `PREFIX_core_directory_storage` (
`directory_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`path` varchar(255) NOT NULL DEFAULT '',
`upload_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
`parent_id` int(10) unsigned DEFAULT NULL,
PRIMARY KEY (`directory_id`),
UNIQUE KEY `IDX_DIRECTORY_PATH` (`name`, `path`),
KEY `parent_id` (`parent_id`),
CONSTRAINT `FK_DIRECTORY_PARENT_ID` FOREIGN KEY (`parent_id`)
REFERENCES `PREFIX_core_directory_storage` (`directory_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Directory storage';
May with
SET FOREIGN_KEY_CHECKS = 0;
Categories: Software Tags:

replace string, sed

February 17th, 2011 No comments

$sed -i 's/foo/foo_bar/g' filename.ext

$find . -type f -exec sed -i ‘s/foo/foo_bar/g‘ {} \;

Categories: Server Tags:

Installing Magento 1.3 with PHP 5.3

December 16th, 2010 No comments

lib/Varien/Object.php
On line 484, replace

public function ___toString(array $arrAttributes = array(), $valueSeparator=’,')
by
public function __invoke(array $arrAttributes = array(), $valueSeparator=’,')

app/code/core/Mage/Catalog/Model/Layer/Filter/Price.php
On line 139. replace

$key.= $taxReq->__toString(array(), ‘_’);
by
$key.= $taxReq->__invoke(array(), ‘_’);

app/code/core/Mage/Core/functions.php
On line 192, replace

switch($errno){
by
switch($errno){
case E_DEPRECATED:
return;

lib/Zend/Pdf/Resource/Image/Jpeg.php
On line 59, replace

if (!$gd_options['JPG Support'] ) {
by
if ( (!isset($gd_options['JPG Support']) || $gd_options['JPG Support'] != true) &&
(!isset($gd_options['JPEG Support']) || $gd_options['JPEG Support'] != true) ) {

Categories: Software Tags:

magento Browse By Vs. Shop By

November 10th, 2010 1 comment

Catalog Category (Non-Anchor)

<block type=”catalog/navigation” name=”catalog.leftnav” after=”currency” template=”catalog/navigation/left.phtml”/>

Catalog Category (Anchor)

<block type=”catalog/layer_view” name=”catalog.leftnav” after=”currency” template=”catalog/layer/view.phtml”/>

Categories: System Tags:

magento disappear poll after voting

November 9th, 2010 1 comment

app/code/core/Mage/Poll/Model/Poll.php

public function getVotedPollsIds()
{
$idsArray = array();
/*
foreach ($this->getCookie()->get() as $cookieName => $cookieValue) {
$pattern = ‘#^’ . preg_quote($this->_pollCookieDefaultName, ‘#’) . ‘(\d+)$#’;
$match = array();
if (preg_match($pattern, $cookieName, $match)) {
if ($match[1] != Mage::getSingleton(‘core/session’)->getJustVotedPoll()) {
$idsArray[$match[1]] = $match[1];
}
}
}

// load from db for this ip
foreach ($this->_getResource()->getVotedPollIdsByIp(Mage::helper(‘core/http’)->getRemoteAddr()) as $pollId) {
$idsArray[$pollId] = $pollId;
}*/

return $idsArray;
}

Categories: System Tags: , ,

remove ssl encryption

October 30th, 2010 No comments

openssl rsa -in server.key -out server.key.new

mv server.key.new server.key

chmod 600 server.key

Categories: Server Tags: , ,