MySQL Relationships (JOIN explained)

The visual diagrams still confuse me after so many years and I always forget…so here it is:

INNER JOIN gets all records from one table that have some related entry in a second table

LEFT JOIN gets all records from the LEFT linked table but if you have selected some columns from the RIGHT table, if there is no related records, these columns will contain NULL

RIGHT JOIN is like the above but gets all records in the RIGHT table

FULL JOIN gets all records from both tables and puts NULL in the columns where related records do not exist in the opposite table

Categories: Uncategorized. Comments Off on MySQL Relationships (JOIN explained)

Remount read/write in single user mode

If /etc/fstab is correct, you can simply type:

# mount -n -o remount /

If /etc/fstab is wrong, you must give the device name and possibly the
type, too: e.g.

# mount -n -o remount -t ext4 /dev/sda3 /

Categories: Uncategorized. Comments Off on Remount read/write in single user mode

Pacemaker / Corosync / DRBD Cheatsheet

Monitor the status:

crm_mon

Migrate all resources to another node:

crm resource migrate rg_main <fqdn_node_name>

Take node offline and online (be careful, this sets a ‘prefer’ to the other node to force a transition, which may or may not get removed afterwards):

crm node standby
crm node online

Start and stop all resources (warning, this will take them completely offline, NOT migrate):

crm resource stop rg_main
crm resource start rg_main

Show configuration:

crm configure show

If resources are stuck in ‘(unmanaged) FAILED’ state, e.g. due to a failed stop action, you can clear it out:

crm_resource -P
crm resource cleanup rg_main

Be careful — this could trigger a migration if the stuck resources were preventing one. Make sure you’re ready for one.

Monitor the cluster status along with fail counts:

crm_mon --failcount

One-shot status output:

crm status

Check DRBD status:

cat /proc/drbd

DRBD split-brain cleanup on secondary node:

drbdadm disconnect main
drbdadm -- --discard-my-data connect main

DRBD split-brain cleanup on primary node:

drbdadm disconnect main
drbdadm primary main
drbdadm connect main

Scheduler optimizing on large arrays (untested):

echo deadline > /sys/block/sdb/queue/scheduler
echo 0 >  /sys/block/sdb/queue/iosched/front_merges
echo 150 > /sys/block/sdb/queue/iosched/read_expire
echo 1500 > /sys/block/sdb/queue/iosched/write_expire

Exchange 2012 Allow Relay from IP

Enable mail relaying from a specific IP or range of IPs.

1. Exchange Management Console -> Server Configuration -> Hub Transport

2. New Receive Connector

* Set remote network to the IP or range you want to allow relay from (default is any IP so watch out here)
* “Externally Secured” authentication
* “Exchange Servers” permission group
* All other options disabled

Categories: Uncategorized. Comments Off on Exchange 2012 Allow Relay from IP

Increasing max files or folders per directory on Linux EXT filesystem

If a (poorly coded) app reaches the maximum number of files or folders per directory in Linux, you may see errors like this:

Error happened when generating Download Link.
Please try again or Contact administrator.
(ERROR:mkdir)

A quick and dirty way to increase the limit (and overall performance of the system) is to add the dir_index flag to the ext filesystem, then reindex:

tune2fs -O dir_index /dev/sda3
updatedb &
Categories: Uncategorized. Comments Off on Increasing max files or folders per directory on Linux EXT filesystem

Cpanel Apache Symlink Protection

wget http://layer1.rack911.com/before_apache_make -O /scripts/before_apache_make
chmod 700 /scripts/before_apache_make
## Rebuild apache (might want to do it thru WHM instead)
/scripts/easyapache --build
Categories: Uncategorized. Comments Off on Cpanel Apache Symlink Protection

AS Number Stats on Linux

I’ve got a couple of Linux machines that are sitting outside of the Sflow ‘zone’ and AS traffic stats go unmeasured. I wanted to get a rough idea on the number of connections per AS number so here’s a little app that parses netstat and sorts AS numbers by number of connection.

NOTE1: This won’t work on Cpanel servers due to tmp restrictions.

NOTE2: Specify an alternative (e.g newer) GeoIPASNum.dat file with the –geo option.

wget http://djlab.com/stuff/asnum
chmod +x asnum
./asnum

Example output:

[root@mx1 ~]# ./asnum
(18) | RFC1918 or BOGON
(11) | AS29889 Fast Serv Networks, LLC
(4) | AS3320 Deutsche Telekom AG
(2) | AS7922 Comcast Cable Communications, Inc.

Quick and (very) dirty cron script

#!/bin.sh
#/root/doasnum.sh
#*/5 * * * * /root/./doasnum.sh >> /var/log/asnum.log

thedate=`date`
echo "***********************"
echo $thedate
/root/asnum
echo "***********************"

Don’t forget to rotate the logs.

#/etc/logrotate.d/asnum
/var/log/asnum.log
{
        rotate 7
        daily
        missingok
}
Categories: Uncategorized. Comments Off on AS Number Stats on Linux

Obfuscate or Encrypt Perl

There are 3 primary options:

1. Use PAR with PAR::Filter::Obfuscate or PAR::Filter::Crypto

2. Use Filter::Crypto::CryptFile (requires certain modules installed on target system)

3. Encrypt modules with Module::Crypt.

Categories: Uncategorized. Comments Off on Obfuscate or Encrypt Perl