Lighttpd both http and https

 

We can configure both http & https on lighttpd webserver.

Use following configuration to serve both http & https requests:

server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
accesslog.filename = "/var/log/lighttpd/access.log"
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80

#Configuration for https
$SERVER["socket"] == ":443" {
  ssl.engine = "enable"
  ssl.pemfile = "/etc/lighttpd/certs/www.example.com.pem"
}

In above configuration http://www.example.com.pem file should contain both the private key and the certificate.

After updating lighttpd.conf file restart lighttpd:

$ service lighttpd restart

After restarting both http & https should work for your host.

iptables start on boot – Ubuntu/Debian

 

By default Ubuntu/Debian OS wont load iptable on boot.

So to load iptables on boot use follow procedure:

Save iptable conf with iptables-save command:

iptables-save > /etc/iptables.conf

Next, open file with name /etc/network/if-up.d/iptables and add following content:

#!/bin/sh
iptables-restore < /etc/iptables.conf

Change permission file /etc/network/if-up.d/iptables as executable with following command:

chmod +x /etc/network/if-up.d/iptables

Now, iptables will restored on boot.

Whenever you change iptable rules don’t forgot to update iptables.conf file. Use following command to update iptables.conf file:

iptables-save > /etc/iptables.conf

Python – check variable for None

 

To check if a variable is None use following code:

>>> val=None
>>> val is None
True

If you want to use above example with if condition use following code:

if not (val in None):
  print "val is not none"
else:
  print "val is none"

Python – ImportError: No module named memcache

While trying to connect memcached using python I got following error:

ImportError: No module named memcache

Since I imported memcache & it’s not available in my server I got the error message saying that “No module named memcache”.

To resolve this issue we need to install python-memcache module.

Use following command to install python-memcache:

$ pip install python-memcache

If  your OS is Ubuntu/Debian following command also works for you:

$ apt-get install python-memcache

After installing python-memcache we can seamlessly connect to memcached.

Ubuntu desktop change nameservers permanently

To change nameservers permanently in Ubuntu Desktop Version we need to update /etc/resolvconf/resolv.conf.d/head file with desired list.

Following is the procedure to change nameservers permanently:

Open /etc/resolvconf/resolv.conf.d/head file with your favourite editor:

sudo vim /etc/resolvconf/resolv.conf.d/head

Add following lines to /etc/resolvconf/resolv.conf.d/head, save & exit from the file

nameserver 4.2.2.2
nameserver 208.67.222.222

Run following command to change nameservers permanently:

sudo resolvconf -u

After running above commands nameservers in your desktop version will get updated with new list as mentioned in /etc/resolvconf/resolv.conf.d/head file.
To conform this open /etc/resolve.conf and validate.

Linghttpd – unknown config-key: accesslog.filename

Recently I faced wearied scenario where I am unable to view access logs of lighttpd.

Even though after adding accesslog.filename = “/var/log/lighttpd/access.log” line in lighttpd.conf file logs are not getting updated in lighttpd.conf file

After debugging for a while I seen following error in /var/log/lighttpd/error.log:

WARNING: unknown config-key: accesslog.filename (ignored)

To fix this issue I adding “mod_accesslog” to servers.modules in lighttpd.conf file & restarted lighttpd. After that issue got resolved.

Following is my server.modules after adding mod_accesslog:

server.modules = (
  "mod_access",
  "mod_alias",
  "mod_compress",
  "mod_redirect",
  "mod_accesslog",
  "mod_rewrite",
)

HBase error there is a hole in the region chain

Recently while I am trying to restart HBase I got error message saying that “ERROR: There is a hole in the region chain between …… You need to create a new .regioninfo and region dir in hdfs to plug the hole”.

Following is the error message:

ERROR: There is a hole in the region chain between TestTable,2,1415170922328.3c1b2a210888171d142059912e2faba1. and TestTable,3,1415171044919.da852e5b0034a2ca83f6966280454b4a. You need to create a new .regioninfo and region dir in hdfs to plug the hole.
ERROR: Found inconsistency in table TestTable

To fix this issue you need to stop HBase and delete recover.edits folders for failing regions.

After that start HBase and run hbck which should succeed.

fatal error: Python.h: No such file or directory

While trying to install some python module I got following exception:

fatal error: Python.h: No such file or directory

Reason for exception:

If you haven’t properly installed the header files and static libraries for python dev this issue may occur.

To resolve this issue install python-dev module by using following command:

$ sudo apt-get install python-dev

Linux – Ping multiple hosts using fping

 

fping is a ping like program which uses the Internet Control Message Protocol (ICMP) echo request to determine if a host is up.

With fping we can ping multiple hosts at a time. Use following command to ping multiple hosts:

$ fping -f IPsFiles.txt 

where in IPsFiles.txt I have multiple hots.

Below are some other examples of fping:

To ping a host/IP:

$ fping 192.168.2.2

Output:

192.168.2.2 is alive

$ fping 192.168.2.22

Output:

192.168.1.22 is unreachable

To ping range of IP’s:

$ fping -g 192.168.2.0/24

To list only unreachable hosts/IP’s

$ fping -q -u -f IPsFiles.txt

where -q is for Quiet mode and -u is to list only unreachable targets.

To list only reachable hots/IP’s

$ fping -q -a -f IPsFiles.txt

where -a is to list only alive hots.