How to , and other stuff about linux, photo, php … A linux, photography blog. To remember some linux situation, and fix them quickly.

January 23, 2015

Unique visitors from apache log file

Filed under: Linux — Tags: , , — admin @ 11:32 am

Well if you ever want to find out from apache log how many unique visitors you have here is one command

cat /usr/local/apache/domlogs/domain.log |awk '{print $1}' | sort | uniq | wc -l

If you want to find out for a date
cat /usr/local/apache/domlogs/domain.log | grep "\[05/Sep/2010" |awk '{print $1}' | sort | uniq | wc -l

Unique referrers
cat /usr/local/apache/domlogs/domain.log | awk '{print $11};' | awk -F / '{print $3}' | sort | uniq

Number of hits
cat /usr/local/apache/domlogs/domain.log | wc -l

December 16, 2014

Setting up HAProxy with SSL

Filed under: Linux — Tags: , , , , — admin @ 2:02 pm

Well today I was set up a haproxy to use ssl, and did’t figure out from first time how to get only one file for the pem.
In haproxy you have only one file with all certificates.

So the order is this:
cat matrafox.info.key >> matrafox.info.pem
cat matrafox.info.crt >> matrafox.info.pem
cat intermediate.bundle >> matrafox.info.pem

After this just add the
bind *:443 ssl crt /etc/ssl/matrafox.info.pem
And you will have the right one.

November 20, 2014

How to get md RAID array to rebuild even if read errors

Filed under: Linux — Tags: , , , , — admin @ 3:14 pm

Well hope this will help someone like me because I really didn’t find exactly all information on internet.
So .. My situation was like this raid 1 software . On smartctl both hard drive look pretty mess up so I decide to switch sdb first. So, I remove the sdb from raid, make the tiket to datacenter and they say won’t change the hard drive because is ok. So I put the sdb back in place but my surprise was big. The raid didn’t build and get a failed . And the sdb was put in (S) spare .

cat /proc/mdstat
Personalities : [raid1]
md3 : active raid1 sdb4[2] sda4[0]
1851802943 blocks super 1.2 [2/2] [UU]

md2 : active raid1 sdb3[2](S) sda3[0]
1073740664 blocks super 1.2 [2/1] [U_]

md1 : active raid1 sdb2[2] sda2[0]
524276 blocks super 1.2 [2/2] [UU]

md0 : active raid1 sdb1[2] sda1[0]
4193268 blocks super 1.2 [2/2] [UU]

unused devices:
When you have 1Tb is a lot of waiting . So panic was on me, why the sbd3 is in S state and is not get in place again. When I was looking on the dmesg log surprise. Because some cluster can’t be read from sda, the raid failed :(. Well this situation is not so ok.. because if both hard drive will have only one cluster bad you are in situation that you can’t replace the hard drive.

So what is the solution. Well there is no magic one like force or skip , or perhaps exist but I didn’t find the exact solution.
The dmesg look something like this
[7646674.321121] end_request: I/O error, dev sda, sector 1251467520
[7646674.321148] raid1: sda3: rescheduling sector 1242024160
[7646691.820040] end_request: I/O error, dev sda, sector 1251467520
[7646691.841995] raid1:md2: read error corrected (8 sectors at 1242026240 on sda3)
[7646709.327315] end_request: I/O error, dev sda, sector 1251467528
[7646709.327923] raid1:md2: read error corrected (8 sectors at 1242026248 on sda3)
[7646726.817936] end_request: I/O error, dev sda, sector 1251467536
[7646726.818461] raid1:md2: read error corrected (8 sectors at 1242026256 on sda3)
[7646744.291904] end_request: I/O error, dev sda, sector 1251467544
[7646744.292431] raid1:md2: read error corrected (8 sectors at 1242026264 on sda3)
[7646762.473787] end_request: I/O error, dev sda, sector 1251467560
[7646762.474294] raid1:md2: read error corrected (8 sectors at 1242026280 on sda3)
[8337479.557401] end_request: I/O error, dev sda, sector 1251471424
[8337479.557427] raid1: sda3: rescheduling sector 1242028000
[8337506.426294] end_request: I/O error, dev sda, sector 1251471432
[8337506.480066] raid1:md2: read error corrected (8 sectors at 1242030152 on sda3)
[8337507.764690] raid1: sda3: redirecting sector 1242028000 to another mirror
[8769133.060807] end_request: I/O error, dev sda, sector 1251476840
[8769133.060833] raid1: sda3: rescheduling sector 1242033496
[8769150.443149] end_request: I/O error, dev sda, sector 1251476840
[8769150.443726] raid1:md2: read error corrected (8 sectors at 1242035560 on sda3)
[8769150.443772] raid1: sda3: redirecting sector 1242033496 to another mirror

Well this is after a grep with sectors in search. The modern hard drive can relocate some sector if they are bad, but to do that a write on that sector must occur . So I start using hdparam to check and write that sectors.
First of all I was making a grep on dmesg do seee the sectors
dmesg | grep -i sectors , or something like this to find out what are the sector.
For me something like this was the output
[9328180.676069] end_request: I/O error, dev sda, sector 1251477144
[9328249.705549] end_request: I/O error, dev sda, sector 1251477144
[9338442.525476] end_request: I/O error, dev sda, sector 1251477144
[9338482.362380] end_request: I/O error, dev sda, sector 1251477144
[9328232.631537] end_request: I/O error, dev sda, sector 1251471488
[9338452.461797] end_request: I/O error, dev sda, sector 1251471488
[9338499.453213] end_request: I/O error, dev sda, sector 1251471488
[9328169.224894] end_request: I/O error, dev sda, sector 1251471456
[9328215.499044] end_request: I/O error, dev sda, sector 1251471456
[9338465.239646] end_request: I/O error, dev sda, sector 1251471456
[9338520.575210] end_request: I/O error, dev sda, sector 1251471456
[9338456.717853] end_request: I/O error, dev sda, sector 1251470641
[9338503.592660] end_request: I/O error, dev sda, sector 1251470641
[9328154.873250] end_request: I/O error, dev sda, sector 1251470640
[9328198.474859] end_request: I/O error, dev sda, sector 1251470640

Well not in this order but .. something like this ( here is after I sorted bout sector number )
So in order to check the sector you can do this

hdparm –read-sector 1251470640 /dev/sda
/dev/sdb: Input/Output error

PLEASE NOTE THAT WRITING THOSE SECTOR IS ON YOUR RISK AND IRREVOCABLE DATA LOSS MAY OCCURRED.
I STRONGLY SUGGEST TO HAVE BACKUP IN CASE YOU CAN’T DO ANYTHING AND A RE INSTALL OF OS IS NEEDED

In order to make a write you have to run this
hdparm –write-sector 1251470640 –yes-i-know-what-i-am-doing /dev/sda

After this I was run a read again and I see no error. So I was thinking ok I mark them all and run again a rebuild . Also this can be run if
smartctl -a /dev/sdb | grep -i reallocated
5 Reallocated_Sector_Ct 0x0033 100 100 005 Pre-fail Always – 0
196 Reallocated_Event_Count 0x0032 100 100 000 Old_age Always – 0

If you have 0 then you can write that sector because hard drive will try to relocate that sector.
So after I relocated all that sectors, I rebuild again, waited 2 hour and another error appear . So I took again a look on dmesg and see other sector that was next to that I first have.
So I started to think it there are no more . So I try to read more to see if error appear.
So I run something like this
for i in $(seq 1251470640 1251478000) ; do hdparm –read-sector $i/dev/sda |grep error ; done
If you see any line with error you have to search those and mark them. You can modify this script into more complex one and if error occur to make it write that sector .

A small script

#!/bin/bash
for i in $(seq 3645583000 3646853936)
do
a=$(hdparm –read-sector $i /dev/sdb)

if [ “$?” -ne “0” ]; then
echo $i
hdparm –write-sector $i –yes-i-know-what-i-am-doing /dev/sdb
fi

done

After I have marked them all I have manage to rebuild the raid again.

PLEASE NOTE THAT WRITING THOSE SECTOR IS ON YOUR RISK AND IRREVOCABLE DATA LOSS MAY OCCURRED.
I STRONGLY SUGGEST TO HAVE BACKUP IN CASE YOU CAN’T DO ANYTHING AND A RE INSTALL OF OS IS NEEDED

October 29, 2014

chkconfig list ubuntu

Filed under: Linux — Tags: , — admin @ 10:52 am

Well on ubuntu I didn’t find a corresponding command to chkconfig list.
So a, easy way to find out what is running on startup is to run this:
runlevel
N X
And after you see what runlevel is you list the directory :
ls -ialh ls -ialh /etc/rcX.d/

Where X is the answer from runlevel

Also some equivalent command:
chkconfig –add
chkconfig –level 345 on
chkconfig –del

update-rc.d defaults
update-rc.d start 20 3 4 5
update-rc.d -f remove

October 22, 2014

mod_rpaf and Amazon ELB

Filed under: Linux — Tags: , , , — admin @ 11:26 am

Well is clear that if you want to use the amazon elb, you will not see the $REMOTE_ADDR correctly and you will need mor_rpaf enabled and installed.
If you have a centos / redhat server I found this nice tutorial on this page

mod_rpaf and Amazon ELB
mod_rpaf-0.6-0.7.x86_64.rpm

And add this
LoadModule rpaf_module modules/mod_rpaf-2.0.so

RPAFenable On
RPAFsethostname On
RPAFproxy_ips 10.
RPAFheader X-Forwarded-For

« Newer PostsOlder Posts »

Powered by WordPress