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>
    ProxyRequests off
    ProxyPass /
    ProxyPassReverse /
<VirtualHost *:80>
    ProxyRequests off
    ProxyPass /
    ProxyPassReverse /
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>
    ProxyRequests off
    ProxyPass /myapp http://localhost:8080/myapp
    ProxyPassReverse /myapp http://localhost:8080/myapp

Possibly Related Posts

Friday, 26 August 2011

Recursively remove all empty directories

In Linux:
find <parent-dir> -type d -empty -delete
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 network will use the default gateway but the clients will use as default gateway:

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

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:
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:
3. Size the log files.

The correct way to resize this is documented here:

In /etc/my.cnf the value I'm going to try is:
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
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:
This setting seems to affect the hit rate of Threads_created per Connection.
max_connections = 400
This should help a lot for high volume writes.

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:

log_found=`ps faux|grep -v grep|grep $PROCESS|grep -v $0|awk '{print $2}'`
if [ "$log_found" == "" ]; then
    echo "No process found"
    echo "Processes found:"
    for PID in $log_found; do
        echo $PID

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