Wednesday, 31 August 2011

Apache reverse proxy of virtual hosts

Here you have a simple example on how to create a vhost for a reverse proxied site:

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName blue.domain.com
    ProxyRequests off
    ProxyPass / http://blue.internal.domain.com/
    ProxyPassReverse / http://blue.internal.domain.com/
</VirtualHost> 
<VirtualHost *:80>
    ServerName red.domain.com
    ProxyRequests off
    ProxyPass / http://red.internal.domain.com/
    ProxyPassReverse / http://red.internal.domain.com/
</VirtualHost>
This is also useful if you have a tomcat or anything else running on a different port and you want to serve everything on the same port:

<VirtualHost *:80>
    ServerName tom.domain.com
    ProxyRequests off
    ProxyPass /myapp http://localhost:8080/myapp
    ProxyPassReverse /myapp http://localhost:8080/myapp
</VirtualHost>

Possibly Related Posts

Friday, 26 August 2011

Recursively remove all empty directories

In Linux:
find <parent-dir> -type d -empty -delete
Alternatives:
find <parent-dir> -empty -type d -exec rmdir {} +
find <parent-dir> -depth -type d -empty -exec rmdir -v {} +
find <parent-dir> -depth -type d -empty -exec rmdir -v {} \;

In Windows:
for /f "usebackq" %%d in (`"dir /ad/b/s | sort /R"`) do rd "%%d"

Possibly Related Posts

Thursday, 25 August 2011

Cisco - Set default route per interface

If you want to set a different default exit route for your clients and servers you can use route-maps to achieve this, using policy-based routing.
With the following configuration the servers from the 10.39.30.0/24 network will use the default gateway 10.39.30.254 but the clients will use 172.18.254.254 as default gateway:

interface GigabitEthernet0/1.1
description Servers Network
encapsulation dot1Q 1 native
ip address 10.39.30.253 255.255.254.0
!
interface GigabitEthernet0/1.2012
description Clients Network
encapsulation dot1Q 2012
ip address 172.18.254.253 255.255.0.0
ip policy route-map lanhop
!
!
ip route 0.0.0.0 0.0.0.0 10.39.30.254
!
! -- This sets the default GW
!
access-list 100 permit ip 172.18.0.0 0.0.255.255 any
!
! -- This matches the entire 172.18.0.0/16 network
!
route-map lanhop permit 10
match ip address 100
set ip default next-hop 172.18.254.254
!
! -- This sets the default GW for the IPs matched by the previous acl.

NOTE:
This is a sample configuration for policy-based routing using the set ip default next-hop and set ip next-hop commands:
  • The set ip default next-hop command verifies the existence of the destination IP address in the routing table, and… if the destination IP address exists, the command does not policy route the packet, but forwards the packet based on the routing table. if the destination IP address does not exist, the command policy routes the packet by sending it to the specified next hop.
  • The set ip next-hop command verifies the existence of the next hop specified, and… if the next hop exists in the routing table, then the command policy routes the packet to the next hop. if the next hop does not exist in the routing table, the command uses the normal routing table to forward the packet.

Possibly Related Posts

Monday, 22 August 2011

Performance Tuning MySQL for Zabbix

On my previous post I've shared some tips on how to tune ZABBIX configuration to get better results,however the most important tunning you have to do is to the data base server. Remember that this values depend on how much memory you have available on your server, here is how I've configured my MySQL server:

1. use a tmpfs tmpdir, create a folder like /mytmp and In /etc/my.cnf configure:
tmpdir=/mytmp
in /etc/fstab i put:
tmpfs /mytmp tmpfs size=1g,nr_inodes=10k,mode=700,uid=102,gid=105 0 0
You'll have to mkdir /mytmp and the numeric uid and gid values for your mysql user+group need to go on that line. Then you should be able to mount /mytmp and use tmpfs for mysql's temp directory. I don't know about the size and nr_inodes options there, I just saw those in linux tmpfs docs on the web and they seemed reasonable to me.

2. Buffer cache/pool settings.

In /etc/my.cnf jack up innodb_buffer_pool_size as much as possible. If you use /usr/bin/free the value in the "+/- buffer cache" row under the "free" column shows you how much buffer cache you have. I've also setup innodb to use O_DIRECT so that the data cached in the innodb buffer pool would not be duplicated in the filesystem buffer cache. So, in /etc/my.cnf:
innodb_buffer_pool_size=8000M
innodb_flush_method=O_DIRECT
3. Size the log files.

The correct way to resize this is documented here:

http://dev.mysql.com/doc/refman/5.0/en/adding-and-removing.html

In /etc/my.cnf the value I'm going to try is:
innodb_log_file_size=64M
A too small value means that MySQL is constantly flushing from the logfiles to the table spaces. It is better to increase this size on write-mostly databases to keep zabbix streaming to the logfiles and not flushing into the tablespaces constantly. However, the penalty is slower shutdown and startup times.

4. other parameters
innodb_file_per_table
Use file_per_table to keep tablespaces more compact and use "optimize table" periodically. And when you set this value in my.cnf you don't get an actual file_per_table until you run an optimize on all the tables. This'll take a long time on the large zabbix history* and trends* tables.
Turn on slow query logging:
log_slow_queries=/var/log/mysql.slow.log
This setting seems to affect the hit rate of Threads_created per Connection.
thread_cache_size=4
query_cache_limit=1M
query_cache_size=128M
tmp_table_size=256M
max_heap_table_size=256M
table_cache=256
max_connections = 400
join_buffer_size=256k
read_buffer_size=256k
read_rnd_buffer_size=256k 
This should help a lot for high volume writes.
innodb_flush_log_at_trx_commit=2

Possibly Related Posts

Simple Zabbix tunning tips

If you're getting gaps on ZABBIX's graphs and unknown status on some items, a little to often it might mean that you're monitoring server is low on performance, here are some general rules you can follow to boost ZABBIX performance:

  • If the DB is located on the same host as zabbix, change zabbix_server.conf so it uses a Unix socket to connect to the DB
  • Increase the number of pollers, trapers and pingers on the server config but don't overdo it.
    • General rule - keep value of this parameter as low as possible. Every additional instance of zabbix_server adds known overhead, in the same time, parallelism is increased. Optimal number of instances is achieved when queue, on average, contains minimum number of parameters (ideally, 0 at any given moment). This value can be monitored by using internal check zabbix[queue] or you can look at "Administration -> Queue" on the web interface.
  • increase the number of processes on the agents configuration, again, don't overdo it.
  • Change some of the items to use active checks (leave a few as regular checks so you can get availability information, leave stuff like host status as a regular check). Remember that the hostname set on the zabbix agent conf file must match the hostname given to the host on the web interface.
    • A regular check is initiated by ZABBIX server, it periodically sends requests to an agent to get latest info. The agent is passive, it just processes requests sent by the server.
    • An active check works the following way. ZABBIX agents connect to ZABBIX server to get a list of all checks for a host. Then, periodically, send required information to ZABBIX server. Note that ZABBIX server does not initiate anything. ZABBIX agent does all active work. This doesn't require polling on server side, thus it significantly (1.5x-2x) improve performance of ZABBIX server but if the host goes down the server won't get any information.
  • monitor required parameters only

    However the most important tunning you have to make is to the DB server, in my next post I'll give you some advice on how to tune a MySQL server to boost ZABBIX performance.

Possibly Related Posts

Friday, 12 August 2011

Script to check if process is running

This is a skeleton of a watchdog script to check if a process is running:

#!/bin/bash
PROCESS="java"
log_found=`ps faux|grep -v grep|grep $PROCESS|grep -v $0|awk '{print $2}'`
if [ "$log_found" == "" ]; then
    echo "No process found"
else
    echo "Processes found:"
    for PID in $log_found; do
        echo $PID
    done
fi

You must change the PROCESS variable to your process name and add actions for when the process is or isn't found...

Possibly Related Posts

Thursday, 4 August 2011

Set nginx maximum upload size

Edit nginx configuration and look for html block.
Inside html block add the following:

http {
include conf/mime.types;
default_type application/octet-stream;
client_max_body_size 10m;
....
}

Possibly Related Posts