How to use template tool kit
vi /var/www/cgi-bin/somescript.pl
--------------------------------
#!/usr/bin/perl
use File::Copy;
use strict ;
use warnings;
use Data::Dumper ;
use CGI;
use Template;
use Socket;
print "Content-type: text/html\n\n";
my $remote_host = '59.163.11.66';
exit unless($ENV{REMOTE_ADDR} eq $remote_host );
my $tt = Template->new( INCLUDE_PATH => "/var/www/html/formBackup" ) || die "template process failed: $!";
my $q = new CGI;
my $editfile = "/tmp/aa1.$$" ;
my @allmastercf = qw(/etc/postfix /etc/postfix2nd );
my $hostname = `hostname`;
my %hash = get_ips();
##print Dumper ([\%hash]);
my (%postfixinstance,%ipsfile,%tag,%ips,$ptr,$myip,$iaddr,$name);
my %hash1;
my $ERRORS="";
foreach my $mastercf (@allmastercf) {
copy("$mastercf/master.cf", $editfile);
my @array1;
open (IN,$editfile ) or die "cannot open file ";
# -o smtp_mbind_address=/etc/postfix/ips_intoday
while (<IN>) {
chomp;
next unless /smtp_mbind_address=(\/\S+),?\b/;
push(@array1, $1) ;
}
push(@array1, "$mastercf/ips") ;
close (IN);
my @ips;
my @nofiles ;
my @noips;
foreach my $ipfile (@array1) {
unless(open (IN1, "$ipfile")){
print STDERR "Could not open $ipfile\n";
next;
}
while (<IN1>) {
chomp;
$iaddr = inet_aton("$_"); # or whatever address
$name = gethostbyaddr($iaddr, AF_INET);
push (@ips, "<br>$_ --> $name</br>");
#$hash1{$mastercf}{$ipfile} = "@ips";
}
close (IN1) ;
push @{$hash1{ipandfile}},{ip=>"@ips",ipfile=>$ipfile};
@ips ="";
}
push @{$tag{resulth}},{instance=>$mastercf},{info=>$hash1{ipandfile}};
%hash1 = ();
}
#
# Return a hash array %ret = ( '192.168.2.1' => 'eth0:1' , '192.168.2.2' => 'eth0:2' );
#
#print Dumper ([\%tag]);
$tt->process("serverips.html",\%tag) || die $tt->error();
sub get_ips {
my (%hash);
my ($ifconfig)="/sbin/ifconfig";
my (@lines)=qx|$ifconfig | or die("Can't get info from ifconfig: ".$!);
foreach(@lines){
if(/inet addr:([\d.]+)/){
$hash{$1}++ ;
}
}
return %hash;
}
-----------------------------------------------------------------------------------
vi /var/www/html/formBackup/servreip.html
------------------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>netcore Data backup </title>
<link rel="stylesheet" type="text/css" href="/databu/view.css" media="all">
<script type="text/javascript" src="/databu/view.js"></script>
</head>
<body id="main_body1" >
<img id="top" src="/databu/to1p.png" alt="">
<div id="form_container">
<h1><a>EMM server instance ips and PTR </a></h1>
<div class="form_description">
<!--<p>This is the file is written to /etc/backup/BACKUPDAILY</p> -->
</div>
<ul >
<li id="li_1" >
<label class="description" for="element_1">EMM server instance ips and PTR </label>
<table width="681" cellspacing="2" bgcolor="darkGray">
<tbody align="left" valign="baseline" bgcolor="lightGray">
<tr>
<td><h3>Instance</h3> </td>
<td><h3><CENTER>IP ---> PTR </CENTER></h3></td>
<td><h3>IP File</h3></td>
</tr>
[% FOREACH item IN resulth %]
<tr>
<td bgcolor="lightBlue">[% item.instance %]</td></tr>
[% FOREACH item2 IN item.info %]
<tr>
<td> </td>
<td>[% item2.ip %]</td>
<td>[% item2.ipfile %]</td>
</tr>
[% END %]
[% END %]
</tbody>
</table>
</li>
<li class="buttons">
<input type="hidden" name="form_id" value="286586" />
</li>
</ul>
</div>
<img id="bottom" src="/databu/bottom.png" alt="">
</body>
</html>
---------------------
pxeboot installations how to
wget http://192.168.10.105/pxebootCentos54_64bit.tgz
- untar pxebootCentos54_64bit.tgz to your /boot
- add the following to /etc/grub.conf
title CentOS 5.4 Installation
root (hd0,0)
kernel /pxeboot/vmlinuz ro root=LABEL=/ ip=192.168.50.110 netmask=255.255.255.0 gateway=192.168.2.234
dns=192.168.2.234 hostname=centos44 text ks=http://202.162.242.200/ks.cfg ksdevice=eth0
initrd /pxeboot/initrd.img
this is the ks.fcg file http://192.168.10.105/ks.cfg
auth --useshadow --enablemd5
install
url --url=http://192.168.10.105/CentOS54X
lang en_US
keyboard us
network --bootproto=static --device=eth0 --ip=206.183.108.166 --netmask=255.255.255.0 --gateway=206.183.108.1 --nameserver=209.120.245.58 --hostname=dell860-535.rapidns.com --onboot=on
zerombr
rootpw --iscrypted $1$4kHiDPby$etAhqn01O83WXVXju0K/S/
firewall --disable
firstboot --disable
authconfig --enableshadow --enablemd5
selinux --disable
timezone Asia/Calcutta
bootloader --location=mbr --append="rhgb quiet"
zerombr yes
skipx
clearpart --all
part --ondrive=sda / --fstype ext3 --size=1 --grow
part --ondrive=sda /boot --fstype ext3 --size=200 --asprimary
part --ondrive=sda swap --size=7024
reboot
%packages
@base
@editors
@core
@development-libs
@development-tools
@sql-server
kernel-devel
emacs
- make the above added kernel image to be default image to boot and reboot the server.
- After reboot Centos 5.4 installation will begin.
Script removes all old files from particular directories
#
# This Script removes all old files from particular directories
#
set -x
remFiles(){
path=`echo $1` # This is inefficient but We dont expect too many files
days=$2
dirs=$3
for dir in $path;do
if [ -z "$dirs" ];then
find "$dir" -mtime +$days -type f -exec rm -vf {} \;
else
find "$dir" -mtime +$days -type d -exec rm -vfr {} \;
fi
done
}
remFiles "/net/serverbackup/backup/*" "2"
Important things to know in apache
ServerAdmin
ServerAdmin webmaster@domain.com
Sets the email address for the server administrator - this will be used if you have setup the server to contact you on errors. It is also shown in the ServerSignature (if set to 'Email' - see below)
Domain Name
ServerName and ServerAlias
ServerName domain.com
ServerAlias www.domain.com
Sets the domain name for the virtual host. You can have as many aliases as required. For example, you can have domain.com and domain.net point to the same content.
Note this is not a rewrite rule (we'll look at those later) but the domains defined here will serve the same content (assuming you have set the DNS to point to your Slice IP).
Index Files
DirectoryIndex
DirectoryIndex index.html
Defines the index file (the 'home' page that is shown on entering the domain address). Useful if you have want the user to be directed to an alternate page or to a non-standard home page.
Do note this is not a good way of redirecting users as they may go directly to a non specified page such as domain.com/index.php whilst the DirectoryIndex will only work for those entering domain.com.
Documents
DocumentRoot
DocumentRoot /home/demo/public_html/domain.com/public
The location of the domain's public files. Use an absolute path name.
Log Files
ErrorLog and CustomLog
LogLevel warn
ErrorLog /home/demo/public_html/domain.com/log/error.log
CustomLog /home/demo/public_html/domain.com/log/access.log combined
Set the Log levels and the location for the Virtual Hosts log files. Very useful for easy analysis of the domain statistics.
Error Documents
ErrorDocument
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
Used for all the standard error messages.
In these examples I have an 'errors' folder in my public directory. I created each error document and place them in the 'errors' folder. The paths shown are relative to the DocumentRoot folder defined above.
If not defined, Apache will generated its own error pages. Custom error pages are more user friendly and can be customised as much, or as little, as you want.
Apache Footers
ServerSignature
ServerSignature On
Sets whether the server details are displayed in any server generated error pages or index lists. Options are On, Off and Email.
Note the level of detail in the signature is configured via ServerTokens which cannot be set in the Virtual Hosts file - only in the main apache2.conf. See the Apache configuration #2 article for more details.
If set to Email, the ServerAdmin email will be displayed.
cgi-bin
ScriptAlias
ScriptAlias /cgi-bin/ /home/demo/public_html/domain.com/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
Enables the cgi-bin location as defined by the custom virtual hosts layout. You can, of course, leave the cgi-bin in the DocumentRoot location if you so wish.
Directory
<Directory xxx/xxx>
<Directory /home/demo/public_html/domain.com/public>
Options FollowSymLinks
</Directory>
Set the Options for the specified directory - the example shown allows the Option FollowSymLinks to be enable for the public directory of domain.com
Listed below are further Options that can be set:
Directory Browsing
Options
Options -Indexes
To turn off directory browsing use '-Indexes' or 'None'. To turn them on, use '+Indexes'.
SSI
Options
Options -Includes
This Option disables Server Side Inlcudes.
Symlinks
Options
Options -FollowSymLinks
Enable or disable the option to follow symlinks. Be careful with this option as it can lead to security risks (inadvertently linking to configuration folders).
Dejay Clayton made a good suggestion in using SymLinksIfOwnerMatch instead of FollowSymLinks.
The SymLinksIfOwnerMatch allows symbolic links to be followed only if the owner of the link is identical to the owner of the target file or directory. Thus preventing many of the security risks than a simple FollowSymlinks can create.
.htaccess
AllowOverride
AllowOverride None
Setting AllowOverride to none disables .htaccess support. Set to All to allow them.
You can also specify which .htaccess features to enable such as:
AllowOverride AuthConfig Indexes
The Apache AllowOverride docs has more information on the different features.
Remember to specifically protect your .htaccess file. This can be done in two ways:
Firstly rename it to something obscure and, secondly, deny access to the file from external sources:
AccessFileName .myobscurefilename
<Files ~ "^\.my">
Order allow,deny
Deny from all
Satisfy All
</Files>
No Options
Options
Options None
This will turn off all the available options.
Hierarchy
Remember that the Options directives can be set per directory like this:
<Directory />
AllowOverride None
Options None
</Directory>
<Directory /home/demo/public_html/domain.com/public>
AllowOverride All
</directory>
This will turn of all Options and disable .htaccess support for all directories.
However, the second Directory setting will override the first and allow .htaccess support for the domain.com/public directory.
Summary
The Virtual Hosts file is at once an easy tool to use and a very powerful one. My advice is to enter one setting and test it. Then enter the next setting and so on.
Once familiar you will see you have fine control over all of your web folders and files.
how to create linux ISO
BUILD Machines
Current Build machines are
192.168.40.100 <i386>
192.168.50.165 <x86_64>
Chose OS
Currently the build is done on centos5
Build Directories
On 192.168.40.100 <i386>
distros name
On 192.168.50.165 <x86_64>
distros name
Getting Started
eg to create a product TEST ( Test can be any of name you would like to give you distros )
<arch> ---- i386 or x86_64
Create directory /test of desired <arch> machine.
$ cd /test
$ mkdir <arch>
Copy the centos <arch> cd to /test/<arch>
$ mount /dev/cdrom /media
$ cd /media
$ cp -ar * /test/<arch>/
$ cp .discinfo /test/<arch>/
NOTE : .discinfo file os imp without wich it will give a error of not valid centos
Editing stage2
Editing Default CentOS 5.2 stage2.img
Install squashfs rpm
$ rpm -ivh squashfs-tools-3.0-4.x86_64.rpm
Copy the stage2.img file from the images folder of the cd
$ cp stage2.img /opt/
Make Directory
$ mkdir -p /opt/stage2
Mount the copied stage2.img
$ mount -t squashfs stage2.img /media/ -o loop
Copy Contents
$ cd /media
$ cp -arp * /opt/stage2
$ cp .buildstamp /opt/stage2
$ cd /opt/stage2
$ ls -a
. .. .buildstamp etc lib lib64 modules proc usr var
Now to start editing the stage2
All the python files are stored under /opt/stage2/usr/lib/anaconda
$ vi kickstart.py
Hash the lines this is so that kickstart will ask for network if not specified in ks file
if len(filter(lambda nd: nd.bootProto == "query", self.ksdata.network)) == 0:
dispatch.skipStep("network")
Hash this line so as to ask for the welcome screen
dispatch.skipStep("welcome")
Copy following image files (stage2) into /opt/stage2/usr/share/anaconda/pixmaps
anaconda_header.png
first-lowres.png
first.png
progress_first-375.png
progress_first-lowres.png
progress_first.png
splash1.png
splash.png
syslinux-splash.png
Copy /opt/stage2/usr/share/anaconda/pixmaps/rnotes after deleting all the files already present
03-centos5-yum.png
06-centos5-support.png
08-centos5-wiki.png
05-centos5-centosplus.png
01-centos5-welcome.png
02-centos5-donate.png
09-centos5-virtualization.png
07-centos5-docs.png
04-centos5-repos.png
now ur nearly done all thats left is a nice new stage2.img file
$ cd /opt/stage2
$ mksquashfs . ../stage2.img.new
$ mv stage2.img.new stage2.img
Copy the new stage2.img into /test/<arch>/images/
Creating the kickstart file for auto install
$ cd /test/<arch>
$ vi legacy-mpart.cfg
auth --useshadow --enablemd5
install
cdrom
lang en_US
keyboard us
zerombr
firstboot --disable
firewall --disabled
authconfig --enableshadow --enablemd5
selinux --disabled
bootloader --location=mbr --driveorder=hda
skipx
reboot
%packages
@ msx_packages
Include for auto partition under skipx
clearpart --all
part /boot --fstype="ext3" --size=200
part swap --recommended
part / --fstype="ext3" --grow --size=1
Including Scripts
Copy the scripts dir into /test/
$ cd /test/scripts
Make changes in each script according to arch...
Creating Make file
Create a Makefile in /test/ dir
vi Makefile
MKISOFS=/usr/bin/mkisofs
DATE:=$(shell date +"%d-%m-%Y")
CDDIR=/test
ARCH=x86_64
REPODIR=$(CDDIR)/$(ARCH)
RPMDIR=$(CDDIR)/$(ARCH)/CentOS
INSTDIR=$(CDDIR)/roots/installer/usr/local/net/_install
VER=$(shell scripts/version.sh)
#BUILDRPM=/usr/src/redhat/RPMS/$(ARCH)
BUILDRPM=/usr/src/redhat/RPMS/noarch
test: repoclean repo iso
repoclean:
rm -rf $(REPODIR)/repodata/filelists.xml.gz $(REPODIR)/repodata/other.xml.gz $(REPODIR)/repodata/primary.xml.gz $(REPODIR)/repodata/repomd.xml
svnco:
$(CDDIR)/scripts/svnco.sh $(CDDIR)
$(CDDIR)/scripts/premake $(CDDIR)
initrd:
$(CDDIR)/scripts/makeinitrd.sh $(CDDIR)
repo:
scripts/makecomps.sh $(REPODIR)
iso:
@$(MKISOFS) -o $(CDDIR)/images/MailServ_x64-$(DATE).iso -V MailServ-$(VER) -p 'EMS' -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4\
-boot-info-table -R -J -v -T $(REPODIR)
rpmtest:
$(CDDIR)/scripts/rpmtest.sh $(CDDIR)
$(CDDIR)/scripts/dupshow.pl $(RPMDIR)
dupshow:
$(CDDIR)/scripts/dupshow.pl $(RPMDIR)
isocheck:
$(CDDIR)/scripts/isocheck $(CDDIR)
Generating repos
$ cd /test/<arch>/CentOS/
Keep only the desired packages and delete the rest
Making Initrd
The Makefile includes initrd:
Please run
$ make initrd
This will pick up the kickstart file (legacy.cfg and include it into the initrd)
Isolinux edit
cd /test/<arch>/isolinux
$ vi isolinux.cfg
default linux
prompt 1
timeout 600
display boot.msg
F1 boot.msg
F2 options.msg
F3 general.msg
F4 param.msg
F5 rescue.msg
label linux
kernel vmlinuz
append ks=file:/legacy.cfg initrd=initrd.img
label mpart
kernel vmlinuz
append ks=file:/legacy-mpart.cfg initrd=initrd.img
label text
kernel vmlinuz
append initrd=initrd.img text
label ks
kernel vmlinuz
append ks initrd=initrd.img
label local
localboot 1
label memtest86
kernel memtest
append -
This is to prevent errors of cannot find kickstart file since it is in the initrd
Making CD
$ mkdir /test/images
make test
how load balancer works ( ldirector )
cat /etc/ha.d/ldirectord.cf
________
| |
| client |
|________|
CIP=SGW=192.168.2.62 (eth0)
|
|
__________ |
| | | (Virtual IP=192.168.2.110, eth0:110) listening on port 25
| director |---|
| (suse) | |
|__________| | Director IP=192.168.2.24 (eth0)
|
|
-----------------------------------
| |
| |
Real IP=192.168.2.214(eth0) Real IP=192.168.2.230(eth0)
(VIP=192.168.2.110, lo:0) (VIP=192.168.2.110, lo:0)
______|______ ______|______
| | | |
| realserver | | realserver |
|____________| |____________|
on the LVS server
quiescent=yes
checktimeout=10
checkinterval=30
autoreload=yes
logfile="/var/log/ldirectord.log"
virtual=192.168.2.110:25
real=192.168.2.214:25 gate 9
real=192.168.2.230:25 gate 8
service=smtp
protocol=tcp
scheduler=wrr