11/16/2012

Installing mod_rpaf to Amazon EC2 behind ELB

1. download mod_rpaf-0.6.tar.gz
2. tar xvfz mod_rpaf-0.6.tar.gz
3. cd mod_rpaf-0.6

According to the following link, I created the patch file like below.
http://tech.superhappykittymeow.com/?p=281

4. vi diff.diff


--- mod_rpaf-2.0.c 2008-01-01 03:05:40.000000000 +0000
+++ mod_rpaf-2.0.c~ 2011-08-25 20:04:39.000000000 +0000
@@ -136,13 +136,25 @@
 }

 static int is_in_array(const char *remote_ip, apr_array_header_t *proxy_ips) {
-    int i;
+   /* int i;
     char **list = (char**)proxy_ips->elts;
     for (i = 0; i < proxy_ips->nelts; i++) {
         if (strcmp(remote_ip, list[i]) == 0)
             return 1;
     }
     return 0;
+    */
+    return 1;
+}
+
+static char* last_not_in_array(apr_array_header_t *forwarded_for,
+          apr_array_header_t *proxy_ips) {
+    int i;
+    for (i = (forwarded_for->nelts)-1; i > 0; i--) {
+ if (!is_in_array(((char **)forwarded_for->elts)[i], proxy_ips))
+     break;
+    }
+    return ((char **)forwarded_for->elts)[i];
 }

 static apr_status_t rpaf_cleanup(void *data) {
@@ -161,7 +173,7 @@
     if (!cfg->enable)
         return DECLINED;

-    if (is_in_array(r->connection->remote_ip, cfg->proxy_ips) == 1) {
+    /* if (is_in_array(r->connection->remote_ip, cfg->proxy_ips) == 1) { */
         /* check if cfg->headername is set and if it is use
            that instead of X-Forwarded-For by default */
         if (cfg->headername && (fwdvalue = apr_table_get(r->headers_in, cfg->headername))) {
@@ -183,7 +195,8 @@
             rcr->old_ip = apr_pstrdup(r->connection->pool, r->connection->remote_ip);
             rcr->r = r;
             apr_pool_cleanup_register(r->pool, (void *)rcr, rpaf_cleanup, apr_pool_cleanup_null);
-            r->connection->remote_ip = apr_pstrdup(r->connection->pool, ((char **)arr->elts)[((arr->nelts)-1)]);
+            /* r->connection->remote_ip = apr_pstrdup(r->connection->pool, ((char **)arr->elts)[((arr->nelts)-1)]); */
+            r->connection->remote_ip = apr_pstrdup(r->connection->pool, last_not_in_array(arr, cfg->proxy_ips));
             r->connection->remote_addr->sa.sin.sin_addr.s_addr = apr_inet_addr(r->connection->remote_ip);
             if (cfg->sethostname) {
                 const char *hostvalue;
@@ -201,7 +214,7 @@
             }

         }
-    }
+    /* } */
     return DECLINED;
 }
=======

5. patch < diff.diff
6.  vi Makefile
edit the fourth line like below and save it.
=======
# Makefile for mod_rpaf.c (gmake)
# $Id: Makefile 16 2007-12-13 03:40:22Z thomas $
APXS=$(shell which apxs)
#APXS2=$(shell which apxs2)
APXS2=/usr/sbin/apxs
=======

7. make rpaf-2.0
8. make install-2.0
9. /usr/sbin/apachectl configtest
10. service httpd restart
11. Check the apache log. :)

10/31/2012

AWS EC2 setup useful commands



#yum install patch
#yum install make
#yum install gcc

For dig command,
#yum install bind-utils

For locate command,
#yum install mlocate

#yum install httpd httpd-devel
#yum install mod_rpaf
#yum install geoip





10/30/2012

How to enable epel repository

For CentOS 6, 64bit

1. Download the rpm of epel.
# wget http://ftp-srv2.kddilabs.jp/Linux/distributions/fedora/epel/6/x86_64/epel-release-6-x.noarch.rpm
check the latest epel version.

2. Install the package.
# rpm -ivh epel-release-6-7.noarch.rpm

3. Edit epel conf file to enable epel repository.

# vi /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 5 - $basearch
#baseurl=http://dl.fedoraproject.org/pub/epel/5/$basearch
mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-5&arch=$basearch
failovermethod=priority
enabled=1
priority=2

4. check if epel repository is working.
# yum install geoip

3/14/2012

Cacti got graphs, But no values.


Cacti about NaN's in their graphs
http://docs.cacti.net/manual:087:4_help.2_debugging#not_nan_but_0_zero_values

Cacti Repodata

For CentOS/RHEL 6.x, 64bit

http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/

3/09/2012

phpMyAdmin Error: Cannot load mcrypt extension

For CentOS 6.2 64bit
The solution is below.


# rpm -ivh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-5.noarch.rpm
# yum update
# yum install php-mcrypt
# /usr/sbin/apachectl restart

3/08/2012

sed in vi.

:%s/old_string/new_string/g


8/28/2011

Cloned Red Hat/CentOS/Scientific Linux Virtual Machines and “Device eth0 does not seem to be present” Message

See this link.
or just delete /etc/udev/rules.d/70-persistent-net.rules and reboot the virtual machine.
Then you can see eth0. :)

8/19/2011

Cacti plugin installation problem

When you applied the pa.sql to cacti database, you might face the following error.

ERROR 1064 (42000) at line 5: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM' at line 12

To get around this, you have to edit pa.sql and replace the word TYPE to ENGINE like this.

:%s/TYPE/ENGINE/g

Then excute the sql file.:)