|
|
slmingol posted this in tips & tricks on October 5th, 2009, @ 10:12 am
Background
This one threw me for a bit but I finally realized that when I had Compiz enabled on an Ubuntu 9.04 system, I couldn’t use VNC to connect via Remote Desktop Sharing in GNOME (aka. Vino, aka. VNC Server). Apparently this has been an issue going back since 2007 8-(, when Compiz is enabled. Since this is the first system that I actually bothered to enable Compiz I’m dealing with it for the first time.
The problem shows up when you try and connect remotely to a system that has Remote Desktop Sharing enabled –AND– Compiz. This thread on launchpad was helpful in showing the lineage of the problem, and the only real workaround to get Remote Desktop Sharing to work.
Solution
The workaround? If you’re coming at it remotely, and are too lazy to walk over to the remote system … ssh into the remote system and run these commands to effectively disable Compiz, and enable (re-enable?) the window manager Metacity.
1
2
3
| ssh <remote system>
export DISPLAY=:0
nohup metacity --replace > /dev/null & |
NOTE: I’m wrapping a “nohup … > /dev/null &” around the “metacity –replace” so that when/if I close the ssh connection, the metacity running in there doesn’t get inexplicably killed off. Additionally, this version of nohup (/usr/bin/nohup), likes to leave a nohup.out file lying around, which is just cruft in our case, so by sending all the output to /dev/null we are effectively disabling the creation of the nohup.out file.
Now you can do your work remotely with Compiz turned off. But now what to do when you’re all done and you want to turn Compiz back on? Easy. Do this:
1
2
3
| ssh <remote system>
export DISPLAY=:0
nohup compiz --replace > /dev/null & |
Useful Links
NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.
slmingol posted this in tips & tricks on August 24th, 2009, @ 10:55 pm
Background
Today a co-worker, let’s call him Evan, was trying to retrofit the UNIX command nohup into a script that I originally developed, and was not having much luck. He was trying to debug a unstable server daemon that’s called by my script. The server daemon had been crashing for the better part of 2 weeks, and the vendor of this particular daemon was directing Evan to prefix the launching of the daemon with nohup. Seemed like a simple request, but nohup wasn’t behaving as he expected. Both Evan and the vendor support specialist, let’s call him Sal, were looking for a nohup.out file to be deposited in the directory where they were running my script. I initially thought that my script might be changing directories behind the scenes, causing the files to show up some where else. After a quick check I could find no evidence of any nohup.out files anywhere. I really didn’t have much experience with nohup either so I figured this was the perfect excuse to better understand how nohup works.
nohup
nohup stands for “no hangup”, and is a way to start a process up that is immune from being hungup. It’s typically invoked like this:
This means that within UNIX, when a parent process spawns a child process, and the parent process is then sent the signal to hangup, the child process has been instructed via nohup to ignore that signal. At which point the child process then becomes a child process of the init process, i.e. the process with the PID of 1. The init process is the originating process of every process on a UNIX system. As always, an example can explain it better than I:
example #1 (simple nohup, without killing the parent process)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| # start the command "sleep 5" nohup'd and backgrounded
% nohup sleep 5 &
[1] 32257
% ps -eaf | egrep "[s]leep|[U]ID|[/]sbin/init"
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jun20 ? 00:00:01 /sbin/init
root 32257 31977 0 21:36 pts/8 00:00:00 sleep 5
% ps -eaf | egrep "[s]leep|[U]ID|[/]sbin/init"
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jun20 ? 00:00:01 /sbin/init
[1]+ Done nohup sleep 5 |
example #2 (parent is killed, child remains)
…. Continue reading → [one-liner]: How to Properly Use nohup »»
slmingol posted this in tips & tricks on August 15th, 2009, @ 2:02 am
Here’s a little trick that I learned how to do the other day while at work. I’ve done this before using ssh in a linux terminal but hadn’t had the chance to actually do it from a windows box using PuTTY.
Objective
To access a web server (on a remote linux box) which is listening on port 80 through an ssh connection. We want to access the web server through port 10001 on the localhost. This can be accomplished by mapping localhost’s port 10001 to port 80 on the remote host.
Here’s a diagram that attempts to represent what’s going on with the ports, the hosts, and the ssh connection.
 ports diagram
Setup
In this scenario we have 2 hosts, the local host (i.e. localhost) and the remote host (homer). Running PuTTY on the localhost, we specify that we want to login to homer as a user on that system, i.e. root, for example. It doesn’t have to be root, this just happens to be the user that I’m using in this example.
 putty dialog #1
Next in the PuTTY Configuration dialog box, expand the category SSH, and select the category Tunnels. In Tunnels’ configuration, specify the Source port, 10001, and the Destination, homer:80. Then click the Add button.
 putty dialog #2
…. Continue reading → [one-liner]: Port Forwarding Using PuTTY »»
slmingol posted this in tips & tricks on July 22nd, 2009, @ 3:12 pm
The other day a website I maintain started experiencing what appeared to be a DoS attack. When this occurs I usually take a peek at Apache’s access_log to see if there is an “unusual” amount of traffic coming from a set of IP addresses. A DoS can be classified as one of 2 situations:
- a lot of page hits coming from the same IPs
- a lot of IPs hitting the same URL
The first situation is easy to diagnose with a one-liner like this:
1
2
3
4
5
6
7
8
9
10
11
12
| # displays the top 10 IP addresses along with there frequency counts
% cut -d" " -f1 access_log | sort -n | uniq -c | sort -nr | head
31123 216.246.75.191
20922 204.2.196.164
20746 204.2.196.177
17723 216.246.75.202
14762 165.254.127.134
13967 165.254.127.127
13718 206.57.29.168
11670 206.57.29.174
8099 96.17.161.211
7264 96.17.161.207 |
The second situation requires a little bit more complex command but it’s kinda sorta doable. At least to the point that gives you a warm fuzzy.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| # display the top 20 URLs by IP requests
# columns in the output are: (frequency, URL, IP)
% cat access_log | awk '{print $7, $1}' | sort | uniq -c | sort -rn | head -20
729 /globe/mul/webAnalytics/cj_metrics.js 96.17.161.211
714 /globe/mul/webAnalytics/cj_metrics.js 216.246.75.191
604 /globe/mul/webAnalytics/cj_metrics.js 96.17.161.207
526 /globe/mul/webAnalytics/cj_metrics.js 216.246.75.202
312 /globe/mul/webAnalytics/cj_metrics.js 12.182.252.217
259 /ejnac/webAnalytics/metrics.js 216.246.75.191
251 /ejnac/webAnalytics/metrics.js 96.17.161.211
234 /ejnac/PageQuery.jhtml?pq-path=3316/13061/15193&pq-locale=en_US 216.246.75.202
227 /ejnac/webAnalytics/metrics.js 96.17.161.207
202 /global/mul/webAnalytics/cj_metrics.js 12.182.252.212
192 /ejnac/webAnalytics/metrics.js 216.246.75.202
189 /ejnac/PageQuery.jhtml?pq-path=1234/43067/45141&pq-locale=en_US 12.182.252.212
175 /eknec/PageQuery.jhtml?pq-path=1234/43064/14194&pq-locale=en_US 216.246.75.191
161 /akamai-sure-toast-object.html 216.246.75.191
151 /globe/mul/metrics/metrics.js 12.182.252.217
148 /globe/mul/metrics/metrics.js 216.246.75.191
140 /globe/mul/webAnalytics/cj_metrics.js 209.170.118.220
140 /globe/mul/metrics/metrics.js 12.182.252.212
137 /ejnac/PageQuery.jhtml?pq-path=1234/15066/16197&pq-locale=en_US 12.182.252.217
120 /globe/mul/metrics/metrics.js 216.246.75.202 |
After a while of running these types of commands against your access_logs, you’ll start to develop a feel for what’s normal, and what’s not.
NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.
slmingol posted this in tutorials on June 20th, 2009, @ 2:18 am
Setting up a RAID can be a tricky proposition. But once you’ve gone through a couple of times it isn’t really all that hard to master. Below are some screenshots from a CentOS 5 build I recently went through to help explain how one can go about setting up a RAID-1 using 2 60GB drives. RAID-1 is 2 drives mirroring each other. I should mention that these directions should be directly applicable to a RHEL system as well as a Fedora system too.
Getting Started
First things first you need to boot the system using a CentOS DVD. Eventually you’ll get to the point where you’ll need to partition the drives, and you’ll be presented with the following screen.
 initial screen - setting up partitions
Setting up the Primary Drive for the OS
Initially we need to go through and remove any pre-existing partitions that may exist on the drives. In our setup we have 3 drives. 1 is for the OS, and the other 2 drives are going to make up our RAID-1.
Here I’m removing the pre-existing partition on the hda drive, aka. the one that the OS will be installed to.
 removing hda's existing partitions
I’m going to skip a bit here, but suffice to say that all I did was create a default setup of partitions on hda.
…. Continue reading → Setting up a RAID During a CentOS 5 Installation »»
slmingol posted this in tutorials on May 20th, 2009, @ 1:51 am
This tutorial sets up and configures the following:
Primary packages
- sendmail
- spamassassin
- milter-greylist
- GeoIP
- clamav
- spamassassin-milter
- clamav-milter
- dovecot
Addons to spamassassin
Optional Extras
NOTE: I’ll discuss how to setup the spf-milter, towards the end of this post but I now consider this an OPTIONAL package after talking with the maintainer of the city-fan.org repo, Paul Howarth. In talking with Paul, it turns out that spamassassin now has the ability to perform SPF checks based on a sender’s domain and IP address. This makes installing the spf-milter redundant and unecessary.
Getting Started
I found this very helpful YUM repository, city-fan.org that contains pretty much everything I needed to accomplish this, minus the ClamAV packages. For those I looked to another repository, rpmforge. To get started, I installed the repo rpm files below.
Setting up city-fan.org repo
1
2
3
4
5
6
7
8
| # install yum repo package
rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/city-fan.org-release-1-7.rhel5.noarch.rpm
# import repo's GPG Key
rpm --import http://www.city-fan.org/ftp/contrib/yum-repo/CITY-FAN.ORG-GPG-KEY
# perform an initial update
yum update |
Setting up rpmforge repo
1
2
3
4
5
6
7
8
| # install yum repo package
rpm -Uvh http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
# import repo's GPG Key
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
# perform an initial update
yum update |
Setting up Spamassassin
1
2
| yum install spamassassin \
spamass-milter |
Setup /etc/sysconfig/spamassassin
1
2
| # Options to spamd
SPAMDOPTIONS="-d -c -m5 -H" |
Setup /etc/sysconfig/spamass-milter
1
2
3
4
5
6
7
8
9
10
11
12
| ### Override for your different local config
#SOCKET=/var/run/spamass-milter/spamass-milter.sock
### Standard parameters for spamass-milter are:
### -P /var/run/spamass-milter.pid (PID file)
###
### Note that the -f parameter for running the milter in the background
### is not required because the milter runs in a wrapper script that
### backgrounds itself
###
### You may add another parameters here, see spamass-milter(1)
#EXTRA_FLAGS="-m -r 15" |
Add the following to sendmail.mc and re-make sendmail.cf
1
2
3
4
5
6
| dnl **
dnl ** enable spamassassin-milter to scan for spam using spamassassin **
dnl **
INPUT_MAIL_FILTER(`spamassassin', `S=unix:/var/run/spamass-milter/spamass-milter.sock, F=, T=C:15m;S:4m;R:4m;E:10m')dnl
define(`confMILTER_MACROS_CONNECT',`t, b, j, _, {daemon_name}, {if_name}, {if_addr}')dnl
define(`confMILTER_MACROS_HELO',`s, {tls_version}, {cipher}, {cipher_bits}, {cert_subject}, {cert_issuer}')dnl |
Setting up SPF (NOTE: used by spamassassin, NOT the milter!)
1
2
3
4
5
| # install perl-Mail-SPF
yum install perl-Mail-SPF
# restart spamassassin (in order to detect the spf plugin)
/etc/init.d/spamassassin restart |
Spamassassin will automatically detect that SPF has been installed and will start using it as part of its scoring of each email. You can confirm that it’s working with this test.
1
2
3
4
5
6
7
8
9
10
11
| spamassassin -D < /usr/share/doc/spamassassin-3.2.5/sample-spam.txt 2>&1 |grep -i spf
[18108] dbg: config: read file /usr/share/spamassassin/25_spf.cf
[18108] dbg: config: read file /usr/share/spamassassin/60_whitelist_spf.cf
[18108] dbg: plugin: loading Mail::SpamAssassin::Plugin::SPF from @INC
[18108] dbg: spf: checking to see if the message has a Received-SPF header that we can use
[18108] dbg: spf: using Mail::SPF for SPF checks
[18108] dbg: spf: no suitable relay for spf use found, skipping SPF-helo check
[18108] dbg: spf: already checked for Received-SPF headers, proceeding with DNS based checks
[18108] dbg: spf: no suitable relay for spf use found, skipping SPF check
[18108] dbg: spf: def_spf_whitelist_from: already checked spf and didn't get pass, skipping whitelist check
[18108] dbg: spf: whitelist_from_spf: already checked spf and didn't get pass, skipping whitelist check |
Setting up DKIM
This module implements the various components of the DKIM and DomainKeys message-signing and verifying standards for Internet mail. It currently tries to implement these specifications:
* RFC4871, for DKIM
* RFC4870, for DomainKeys
1
| yum install perl-Mail-DKIM |
Spamassassin will automatically detect that DKIM has been installed and will start using it as part of its scoring of each email. I confirmed that it was working by sending myself an email from my gmail account and copying this email, make sure to include the full headers, into a text file. In my case I called this file test_email.txt.
1
2
3
4
5
6
| spamassassin -D < ~/sam2.txt 2>&1 |grep -i dk
[18334] dbg: config: read file /usr/share/spamassassin/25_dkim.cf
[18334] dbg: config: read file /usr/share/spamassassin/60_whitelist_dk.cf
[18334] dbg: config: read file /usr/share/spamassassin/60_whitelist_dkim.cf
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
bh=8PW6kvDkcUGo7mGimEUrTlMVS5Y1dFw/IjjLn1WnNLw=; |
Setting up GeoIP
This package will be leveraged by milter-greylist to perform greylisting based on geographic locations of the sender’s IP address.
Setting up milter-greylist
The latest version can be downloaded from this page
1
2
| wget http://www.mailscanner.info/files/greylist/milter-greylist-4.0-4.jkf.el5.i386.rpm
yum --nogpgcheck install milter-greylist-4.0-4.jkf.el5.i386.rpm |
…. Continue reading → How to Setup a Mail Server on CentOS 5 »»
|