May 15

linux — install mod_rapf to work with apache2.4 backend in ubuntu

you can not get real ip of the client making the request if you put apache behind the nginx server.All cilent ip become 127.0.0.1 in the apache access log.tha’s because that nginx now become the client of the apache server.To circumvent this, you’d want to install mod_rpaf (http://stderr.net/apache/rpaf/).

To get and source code:

Source code    
http://stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz

To build and install a third-party Apache module,we need the help of apxs

Source code    
apxs -c mod_rpaf-2.0.c
apxs -i -a -n mod_rpaf-2.0 mod_rpaf-2.0.la

However,i got error message:

Source code    
usr/local/apache2/build/libtool --silent --mode=compile gcc -std=gnu99 -prefer-pic   -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/usr/local/apache2/include  -I/usr/local/apache2/include   -I/usr/local/apache2/include   -c -o mod_rpaf-2.0.lo mod_rpaf-2.0.c && touch mod_rpaf-2.0.slo
mod_rpaf-2.0.c: In function 'rpaf_cleanup':
mod_rpaf-2.0.c:150: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:151: error: 'conn_rec' has no member named 'remote_addr'
mod_rpaf-2.0.c:151: warning: implicit declaration of function 'inet_addr'
mod_rpaf-2.0.c:151: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c: In function 'change_remote_ip':
mod_rpaf-2.0.c:164: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:183: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:186: error: 'conn_rec' has no member named 'remote_ip'
mod_rpaf-2.0.c:187: error: 'conn_rec' has no member named 'remote_addr'
mod_rpaf-2.0.c:187: error: 'conn_rec' has no member named 'remote_ip'
apxs:Error: Command failed with rc=65536

After google,i know that the mod_rpaf need to pached to work with apache2.4.

Source code    
apt-get install git
git clone git://gist.github.com/2716030.git
apt-get install patch
patch mod_rpaf-2.0.c 2716030/mod_rpaf-2.0.c.patch

if you don’t like to use git,you can just copy and save the diff file.Now compile and install again:

Source code    
apxs -c mod_rpaf-2.0.c
apxs -i -a -n mod_rpaf-2.0 mod_rpaf-2.0.la

BUT after install,when you tried to check with

Source code    
httpd -S

it shows that there are some syntax error if apache load the new complied mod_rpaf-2.0.so.after some try,

Source code    
apxs -c mod_rpaf-2.0.c
apxs -i -a -n mod_rpaf mod_rpaf-2.0.c

This will work.maybe this only happened in ubuntu.

May 09

linux – “Disk xxx contains BIOS RAID metadata”

While installing Cent OS 6.4,i got the error like below:

Getting error “Disk sda contains BIOS RAID metadata, but is not part of any recognized BIOS RAID sets. Ignoring disk sda.”

after googling,i reboot into rescue mode,with the following command to erase the whole disk:

dd if=/dev/zero of=/dev/xxx (xxx is the disk you would like to install linux)

Apr 29

linux — install cent os via url mirros in china

Below list some available mirrors url that can be used to do a network installation of cent os:

http://mirror.bit.edu.cn/centos/6.4/os/

http://mirrors.yun-idc.com/centos/6.4/os/

http://mirrors.btte.net/centos/6.4/os/

http://mirror.esocc.com/centos/6.4/os/

http://mirrors.163.com/centos/6.4/os/

http://mirrors.sohu.com/centos/6.4/os/

http://mirror.neu.edu.cn/centos/6.4/os/

Apr 27

linux — CentOS change the name of the network interface

The network didn’t work in my new minimal CentOS install. After some try on changing both “adapter type” and mac addr,i found that with ifconfig command

> ifconfig -a

First,you need to edit the file below,find the line with your mac(the one generated by Virtulbox),change ethx to ech0,remove all other lines.
> vim /etc/udev/rules.d/70-persistent-net.rules

the name of the network become eth3.not eth0 by default.but there is only ifcfg-eth0 in /etc/sysconfig/network-scirpts/. so is it possible for me to revert the name back to eth0?yes!

SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”08:00:27:07:aa:e6″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth0″
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”03:00:23:24:45:e2″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth1″
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”03:00:37:27:ba:a3″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth2″
SUBSYSTEM==”net”, ACTION==”add”, DRIVERS==”?*”, ATTR{address}==”05:00:37:07:ab:c6″, ATTR{type}==”1″, KERNEL==”eth*”, NAME=”eth3″

Now, reload the udev configuration.
>  start_udev

Third,restart network service
> service network restart

 

 

Apr 19

linux — rsync backup withou rsync daemon

i run rsync over ssh to do daily backup with the following command,

rsync -avze ‘ssh -p5000′ [USER@]HOST:SRC… [DEST]

it works ok except that when you remove file/dir from src,it can not be mapped to DESC. To make the deletion affect to the DEST backup,you need to add the –delete option.

rsync -ave ‘ssh -p5000′ –delete user@host:src  desc

 

Apr 17

Linux – Centos 6 Obtain DHCP IP Address using console

I just install a minimal CentOS 6 in my virtualbox. then i found yum did not work due to the network setting.After google,i got this –

When doing a minimal install on Centos 6, the server is not set to use DHCP by default. Most servers use static IP addresses,

First,  edit /etc/sysconfig/network-script/ifcfg-eth0 and change ONBOOT variable to yes. Then just restart the nework service.

> vi /etc/sysconfig/network-script/ifcfg-eth0
DEVICE=”eth0″
BOOTPROTO=”dhcp”
HWADDR=”08:00:27:4A:EB:45″
NM_CONTROLLED=”yes”
ONBOOT=”no” => ONBOOT=”YES”
TYPE=”Ethernet”
UUID=”40ff2ca9-fe32-4060-8a0d-75e698ed34b6″

> service network restart  OR
>/etc/init.d/network restart

you can also try to run

> dhcpclient

Oct 03

apache — let search engine fetch robots.txt based upon domain name

if you have a website with multiple domain(for some special reason),and you want google or other major search engine to fetch different robots.txt,how will you do?

first,get all ready prepared robots.txt and put them in the root folder of you website.you need to name it as robots.txt ,robots1.txt ,robots2.txt

second,create .htaccess file( if not existed)

third,add the following apache config command to the head of the file

Source code    
RewriteCond %{HTTP_HOST} abcdomain1\.com$ [NC]
RewriteRule robots.txt robots1.txt [L]
 
RewriteCond %{HTTP_HOST} abcdomain2\.com$ [NC]
RewriteRule robots.txt robots2.txt [L]
 
RewriteCond %{HTTP_HOST} abcdomain3\.com$ [NC]
RewriteRule robots.txt robots3.txt [L]
Aug 21

linux — use public key authentication to log into ssh

what to do if you want to automate run rsync over ssh without specify any password to backup data?well the only way to access remote ssh server without password is to use pubkey authentication.

First,on the ssh server you need to login,config it to accept pubkey authentication:

vi /etc/ssh/sshd_config

comment out the line PubkeyAuthentication yes and restart sshd dameon:

/etc/init.d/sshd restart

Second, go to the client server,the one you need to bakup.issue the command ssh-keygen to generate a public and private keypair:

# ssh-keygen

press enter without setting any passphrase,.Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub. Copy the content of id_rsa.pub file and paste it to the backup user’s authorized_keys file on the ssh server. if the you use root user,then you need to stored the pub key to /root/.ssh/authorized_keys.This file store all authorized keys for all clients,each line for each client server.It looks like

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAtjz9QhNQQAqDB/KoiiPLdI2aYyWWuw5QCRqsv+JmdWqWxWivfxCnG+LXw9V/jBpvGFCW4wCwIlO0pq/HGMfts2rjCElWvaeZiDuIwR38TCVbPDzl670MRcWjvp+Gy3IIkrkI7J419VNeCEuGria5t4THdHI4Gsz21nSUbFyko5E= rsa-key-20120510

Third, now you can rsync via ssh without specify ssh password for the user.ie

rsync -avze ‘ ssh -p9998 ‘/home/www/abc.com  root@ip:~/bak

Aug 17

linux — fdisk and makefs.ext3 to partition and format a new disk

To show a list for disk intalled on your server,you can issue the command below:

Source code    
fdisk -l | grep '^Disk'

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
Disk identifier: 0x0004d76c
Disk /dev/sdb: 1500.3 GB, 1500301910016 bytes
Disk identifier: 0x00065d74
Disk /dev/sdc: 1500.3 GB, 1500301910016 bytes
Disk identifier: 0x27b927b8

it shows my server has tree disk;Now let’s start to partion the second disk /dev/sdb,

Source code    
fdisk /dev/sdb

This command will switch you from shell to fdisk console,issue the m command fdisk will print all the available command.Below is a summary of the fdisk command:

  • m – print help
  • p – print the partition table
  • n – create a new partition
  • d – delete a partition
  • q – quit without saving changes
  • w - write the new partition table and exit

With those command, the new disk can be easily cut into any partitions.After partition,you need to format the newly created partition so it can be mounted.

Source code    
mkfs.ext3 /dev/sdb1

Then you can mount the partition as below:

Source code    
# mkdir /sdb1
# mount /dev/sdb1 /sdb1

To make the /dev/sdb1 partition be mounted after system reboot,you need to update /etc/fstab file as below:

Source code    
/dev/sdb1     /sdb1       ext3    defaults      1 2

or you can label the partition using e2label. For example, if you want to label the new partition /backup, enter

e2label /dev/sdb1 /backup

Then You can use label name insted of partition name to mount disk using /etc/fstab:

LABEL=/backup /sdb1 ext3 defaults 1 2