LVS
package included in HA
vi /etc/ha.d/ldirectord.conf
checktimeout=3
checkinterval=10
DÀNH CHO CON NHẢ NGHÈO
VIRTUAL SERVER IS SLACKWARE
I. Mô hình:
II. BONDING
Bonding is the same as port trunking. allows you to create multi-gigabit pipes to transport traffic through the highest traffic areas of your network. Linux bond or team multiple network interfaces (NIC) into single interface
You can use it wherever you need redundant links, fault tolerance or load balancing networks. It is the best way to have a high availability network segment. A very useful way to use bonding is to use it in connection with 802.1q VLAN support
è Redundancy trên connection
/usr/src/linux/Documentation/networking
gcc -Wall -O -I/usr/src/linux/include ifenslave.c -o ifenslave
cp ifenslave /sbin/ifenslave
vi rc.bond
#!/bin/sh
#
case “$1″ in
’start’)
echo “start bond0″
#modprobe bonding mode=balance-alb miimon=100
modprobe bonding mode=balance-rr miimon=100
modprobe tg3
ifconfig bond0 up
ifenslave bond0 eth0
ifenslave bond0 eth1
#TODO need to be changed
ifconfig bond0 hw ether 00:16:3e:aa:aa:aa
;;
’stop’)
ifconfig bond0 down
rmmod bonding
rmmod tg3
;;
*)
echo “Usage: $0 {start|stop}”
;;
esac
vi rc.M
before ““#Initialize the networking hardware””
# If script rc.bond is executeable then start it
if [ -x /etc/rc.d/rc.bond ]; then
. /etc/rc.d/rc.bond start
fi
vi rc.inet1.conf
And add these lines to it before the default gateway gets assigned:
IFNAME[4]=”bond0″
IPADDR[4]=”XXX.XX.XX.XX”
NETMASK[4]=”255.255.255.0″
USE_DHCP[4]=”"
DHCP_HOSTNAME[4]=”"
cat /proc/net/bonding/bond0
III. DRBD:
Mục đích Mirror 2 Virtual Disk của 2 Virtual Server trên 2 Physical server qua NIC.
KERNEL 2.6
Device Drivers,Connector - unified userspace <-> kernelspace linker
modprobe cn
download http://oss.linbit.com/drbd/
make; make install
/etc/drbd.conf
syncer {
rate 10M;
}
cram-hmac-alg sha1;
shared-secret “shared-string”;
on drbd-one {
device /dev/drbd0;
disk /dev/hdd1;
address 192.168.0.240:8888;
meta-disk internal;
}
on drbd-two {
device /dev/drbd0;
disk /dev/hdd1;
address 192.168.0.241:8888;
meta-disk internal;
}
STEP BY STEP CONFIGURE
1. Before starting the primary node, you should create the metadata for the devices:
root-shell> drbdadm create-md all
root-shell> /etc/init.d/drbd start
root-shell> drbdadm — –overwrite-data-of-peer primary all
root-shell> mkfs.ext3 /dev/drbd0
root-shell> mount /dev/drbd0 /mnt/drbd
1. To set up a secondary node:
A. Copy the /etc/drbd.conf file from your primary node to your secondary node.
B. root-shell> drbdadm create-md all
C. root-shell> /etc/init.d/drbd start
Command test việc vận hành mirror các virtual HDD
cat /proc/drbd à /*(Kiểm tra tình trạng kết nối của 2 HDD virtuak trên 2 virtual server)*/
root-shell> drbdadm primary all
root-shell> drbdadm secondary all
root-shell> drbdadm disconnect all
root-shell> drbdadm connect all
//if split brain - run this on failed node
drbdadm – –discard-my-data connect all
//and do connect on order side
IV. High Availability (HeartBeat)
Heartbeat is a daemon that provides cluster infrastructure (communication and membership) services to its clients. This allows clients to know about the presence (or disappearance!) of peer processes on other machines and to easily exchange messages with them
download http://www.slackware.com/~alien/slackbuilds/libnet/pkg/11.0/libnet-1.1.2.1-i486-1.tgz
download http://hg.linux-ha.org/lha-2.1/archive/STABLE-2.1.4.tar.bz2
tar -jxvf heartbeat.tar.bz2
./ConfigureMe configure
make; make install
//Edit file ha.cf
vi ha.cf
logfacility local0
keepalive 500ms
deadtime 10
warntime 5
initdead 30
mcast bond0 225.0.0.1 694 2 0
auto_failback off
node drdb-one
node drdb-two
ping 10.10.50.254 10.10.50.50
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster
deadping 5
//Edit haresources
vi haresources
drdb-two drbddisk Filesystem::/dev/drbd0::/raid1::ext3 mysql 10.10.50.28
vi resource.d/mysql.resource
#!/bin/bash
#
# This script is inteded to be used as resource script by heartbeat
#
# Mar 2006 by Monty Taylor
#
###
. /etc/ha.d/shellfuncs
case "$1" in
start)
res=`/etc/init.d/mysql start`
ret=$?
ha_log $res
exit $ret
;;
stop)
res=`/etc/init.d/mysql stop`
ret=$?
ha_log $res
exit $ret
;;
status)
if [ `ps -ef | grep '[m]ysqld'` ] ; then
echo "running"
else
echo "stopped"
fi
;;
*)
echo "Usage: mysql {start|stop|status}"
exit 1
;;
esac
exit 0
package included in HA
vi /etc/ha.d/ldirectord.conf
checktimeout=3
checkinterval=10
download http://slackbuilds.org/repository/12.2/network/iscsitarget/
download src (link in iscsitarget.info)
./iscsitarget.SlackBuild
installpkg /tmp/iscsitarget-0.4.17-i486-1_SBo.tgz
vi /etc/ietd.conf
Target iqn.2001-04.com.example:storage.disk2.sys1.xyz
# Users, who can access this target. The same rules as for discovery
# users apply here.
# Leave them alone if you don’t want to use authentication.
#IncomingUser joe secret
#OutgoingUser jim 12charpasswd
# Logical Unit definition
# You must define one logical unit at least.
# Block devices, regular files, LVM, and RAID can be offered
# to the initiators as a block device.
Lun 0 Path=/dev/drbd1,Type=blockio
# Alias name for this target
Alias Test
/etc/rc.d/rc.iscsi-target start
OCFS2
download http://oss.oracle.com/projects/ocfs2-tools/files/
mkdir /etc/sysconfig
touch /sbin/chkconfig ; chmod 755 /sbin/chkconfig
rpm -ivh –nodeps ocfs2-tools-1.4.2-1.el5.i386.rpm
vi /etc/sysconfig/o2cb
O2CB_ENABLED=true
vi /etc/ocfs2/cluster.conf
node: ip_port = 7777 ip_address = 10.10.50.6 number = 0 name = GSX-2 cluster = ocfs2 node: ip_port = 7777 ip_address = 10.10.50.5 number = 1 name = GSX-1 cluster = ocfs2 cluster: node_count = 2 name = ocfs2
/usr/src/linux/Documentation/networking
gcc -Wall -O -I/usr/src/linux/include ifenslave.c -o ifenslave
cp ifenslave /sbin/ifenslave
vi rc.bond
#!/bin/sh # case "$1" in 'start') echo "start bond0" #modprobe bonding mode=balance-alb miimon=100 modprobe bonding mode=balance-rr miimon=100 modprobe tg3 ifconfig bond0 up ifenslave bond0 eth0 ifenslave bond0 eth1 #TODO need to be changed ifconfig bond0 hw ether 00:16:3e:aa:aa:aa ;; 'stop') ifconfig bond0 down rmmod bonding rmmod tg3 ;; *) echo "Usage: $0 {start|stop}" ;; esac
vi rc.M
before "“#Initialize the networking hardware”"
# If script rc.bond is executeable then start it if [ -x /etc/rc.d/rc.bond ]; then . /etc/rc.d/rc.bond start fi
vi rc.inet1.conf
And add these lines to it before the default gateway gets assigned:IFNAME[4]="bond0" IPADDR[4]="XXX.XX.XX.XX" NETMASK[4]="255.255.255.0" USE_DHCP[4]="" DHCP_HOSTNAME[4]=""cat /proc/net/bonding/bond0
DRBDKERNEL 2.6
,modprobe cndownload http://oss.linbit.com/drbd/make; make install/etc/drbd.conf
global { usage-count yes; } common { syncer { rate 10M; } } resource r0 { protocol C; handlers { pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f"; pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f"; local-io-error "/usr/lib/drbd/notify-local-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f"; outdate-peer "/usr/lib/heartbeat/drbd-peer-outdater -t 5"; } startup { wfc-timeout 5; degr-wfc-timeout 120; # 2 minutes. outdated-wfc-timeout 2; # 2 seconds. } disk { on-io-error detach; } net { max-buffers 8192; cram-hmac-alg "sha1"; shared-secret "hieuvpn"; after-sb-0pri discard-least-changes; after-sb-1pri discard-secondary; after-sb-2pri violently-as0p; rr-conflict disconnect; } syncer { rate 10M; al-extents 257; } on drdb-one { device /dev/drbd0; disk /dev/hda3; address 10.10.50.26:7788; meta-disk internal; } on drdb-two { device /dev/drbd0; disk /dev/hda3; address 10.10.50.27:7788; meta-disk internal; } }
resource r1 { protocol C; handlers { pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f"; pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f"; local-io-error "/usr/lib/drbd/notify-local-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f"; outdate-peer "/usr/lib/heartbeat/drbd-peer-outdater -t 5"; } startup { wfc-timeout 5; degr-wfc-timeout 120; # 2 minutes. outdated-wfc-timeout 2; # 2 seconds. } disk { on-io-error detach; } net { max-buffers 8192; cram-hmac-alg "sha1"; shared-secret "hieuvpn"; after-sb-0pri discard-least-changes; after-sb-1pri discard-secondary; after-sb-2pri violently-as0p; rr-conflict disconnect; } syncer { rate 10M; al-extents 257; } on drdb-one { device /dev/drbd1; disk /dev/hdb; address 10.10.50.26:7790; meta-disk internal; } on drdb-two { device /dev/drbd1; disk /dev/hdb; address 10.10.50.27:7790; meta-disk internal; } } Before starting the primary node, you should create the metadata for the devices:root-shell> drbdadm create-md allroot-shell> /etc/init.d/drbd startroot-shell> drbdadm -- --overwrite-data-of-peer primary allroot-shell> mkfs.ext3 /dev/drbd0root-shell> mount /dev/drbd0 /mnt/drbdTo set up a secondary node:Copy the/etc/drbd.conf
file from your primary node to your secondary node.root-shell> drbdadm create-md allroot-shell> /etc/init.d/drbd start
cat /proc/drbdroot-shell> drbdadm primary allroot-shell> drbdadm secondary allroot-shell> drbdadm disconnect allroot-shell> drbdadm connect allif split brain - run this on failed nodedrbdadm -- --discard-my-data connectall
(forcing by drbdadm invalidate all )
and do connect on order side
HA
download http://www.slackware.com/~alien/slackbuilds/libnet/pkg/11.0/libnet-1.1.2.1-i486-1.tgzdownload http://hg.linux-ha.org/lha-2.1/archive/STABLE-2.1.4.tar.bz2tar -jxvf heartbeat.tar.bz2./ConfigureMe configuremake; make install
vi ha.cf
logfacility local0 keepalive 500ms deadtime 10 warntime 5 initdead 30 mcast bond0 225.0.0.1 694 2 0 auto_failback off node drdb-one node drdb-two ping 10.10.50.254 10.10.50.50 respawn hacluster /usr/lib/heartbeat/ipfail apiauth ipfail gid=haclient uid=hacluster deadping 5
vi haresources drdb-two drbddisk Filesystem::/dev/drbd0::/raid1::ext3 mysql 10.10.50.28
vi resource.d/mysql.resource #!/bin/bash # # This script is inteded to be used as resource script by heartbeat # # Mar 2006 by Monty Taylor # ### . /etc/ha.d/shellfuncs case "$1" in start) res=`/etc/init.d/mysql start` ret=$? ha_log $res exit $ret ;; stop) res=`/etc/init.d/mysql stop` ret=$? ha_log $res exit $ret ;; status) if [ `ps -ef | grep '[m]ysqld'` ] ; then echo "running" else echo "stopped" fi ;; *) echo "Usage: mysql {start|stop|status}" exit 1 ;; esac exit 0
1/ chuyển phụ đề srt :
- dùng unikey chuyển sang font abc
- srt2ssa.exe chuyển srt sang file ssa
- chọn font abc , primary = white
-mở vdub.exe load file - video compression divx - filters - subtitle - save AVI
/* ————————————————————
* “FilterRules” feature to log any message through this MTA
* (c) /Invisible VR Corp. 2001
*
* ABSTRACT
* This routine sends every message which match the FilterRules.
*
* IMPLEMENTATION
* The FilterRules code is compiled into the sendmail binary.
* To check whether a message was already filtered it writes
* log in /var/log/filter.log
*
* CONFIGURATION
* The FilterRules is configuerd in /etc/sendmail.fil as:
* <Sender> <Recipient> <Subject> <SendTo>
*
* ———-/etc/sendmail.fil example:————-
* a@a.com b@b.com * c@c.com
* * * This|is|the|Rules d@d.com
* * e@e.com * d@d.com
* * * * f@f.com
* * * Love|letter|for|you #!virusbox@antivirus.com
* * * * *
* —————— END ————————–
* That means :
* 1/ If From a@a.com To b@b.com then send the
* message to c@c.com
* 2/ If the subject content “This is the Rules” then
* send the message to d@d.com
* 3/ If the recipient is e@e.com then send the
* message to d@d.com
* 4/ Send all message to f@f.com
* 5/ If the subject content “Love letter for you” then
* - Drop(!) the message and send a copy to virusbox@antivirus.com
* - Ignore(#) other rules. It scans from the bottom to top.
* 6/ Enable Log function, It writes activities log
* to /var/log/filter.log
*
*
*
*
* COMPATIBILITY
* FilterRules is tested with sendmail-8.8.5 and sendmail-8.11.2
* under Linux RedHat 7.1
*
* AUTHOR
* Hieu Nguyen Trung - hieu@vpnvietnam.com
*
* LICENSE/WARRANTY
* The software is provided “AS IS” without warranties of any kind,
* either expressed or implied, including, but not limited to the
* implied warranties of merchantability and fitness for a particular
* purpose. The entire risc of the software is with you. In no event
* we will be liable for any damages, including any lost profits,
* lost savings or other incidental damages arising out of the use
* or inability to use the software, even if we have been advised
* of the possibility of such damages, or for any claim by another party.
*
* INSTALLATION
* This source fragment must be included into the source-file:
* …/sendmail-8.x.y/src/srvrsmtp.c
* at the following position
*
* the sendmail binary must be remaked and reinstalled at
* its proper position (normally /usr/sbin/sendmail).
* —————————————————————
*/
/* Insert [-My Filter Code-] before these lines
*
* SmtpPhase = “delivery”;
* (void) bftruncate(e->e_xfp);
*
*/
// —————- My Filter Code———————
my_filter(e);
if (clearlist)
for (a = e->e_sendqueue; a != NULL; a = a->q_next)
{
/* make this “go away” */
a->q_state = QS_REMOVED;
}
while (sendtos!=NULL)
{
a = parseaddr(sendtos->sendto, NULLADDR, RF_COPYALL, ‘ ‘, &delimptr, e);
if (a != NULL )
a = recipient(a, &e->e_sendqueue, 0, e);
pst=sendtos;
sendtos=sendtos->next;
free(pst);
}
//—————-End My Filter ———————————
/* And Insert All The below Codes before these lines
*
* void smtp(nullserver, d_flags, e)
* char *volatile nullserver;
* register ENVELOPE *volatile e;
*/
//———————- Insert this —————————-
struct filter //Rules List
{
char subject[200];
char from[100];
char to[100];
char sendto[100];
struct filter * next;
};
typedef struct filter FILTER;
struct sendto //Sendtos List
{
char sendto[100];
struct sendto * next;
};
typedef struct sendto SENDTO;
SENDTO * sendtos, * pst;
FILTER * filters;
bool clearlist;
^Mbool exitrule;
bool fdebug;
//Add Rule to Rules List
void addchains(char *sfrom,char *sto,char *ssubject,char *ssendto)
{
FILTER *p;
p = (FILTER *)malloc(520);
if (p==NULL) return;
strcpy(p->subject,ssubject);
strcpy(p->from,sfrom);
strcpy(p->to,sto);
strcpy(p->sendto,ssendto);
p->next=filters;
filters=p;
}
void deletechains(void) //Delete Rules List
{
FILTER *p;
while (filters!=NULL)
{
p=filters;
filters=filters->next;
free(p);
}
}
void sendlist(receipient) // Add Matchs to sendtos list
char *receipient;
{
SENDTO *r;
char *p;
p = strchr(receipient,’#');
if (p != NULL)
{
receipient++;
exitrule=TRUE;
}
p = strchr(receipient,’!');
if (p != NULL)
{
receipient++;
clearlist=TRUE;
}
r = (SENDTO *)malloc(120);
if (r==NULL) return;
strcpy(r->sendto,receipient);
r->next=sendtos;
sendtos=r;
}
void cmpchains(e,fdebug) //Scan Rules
ENVELOPE *volatile e;
bool fdebug;
{
ADDRESS *b,*c;
HDR *h;
char *delimptr;
FILTER *p;
char subject[200]=”-None-”;
time_t t;
FILE *logfile;
for (h = e->e_header; h != NULL; h = h->h_link)
{ //Get subject from HDR
if (strcasecmp(h->h_field,”subject”)==0) strcpy(subject,h->h_value);
}
if (fdebug)
{ //Open Log File
logfile = fopen(”/var/log/filter.log”,”a”);
if (logfile == NULL ) fdebug=FALSE;
}
if (fdebug)
{
time(&t);
fprintf(logfile,”\n\nDate : %s”,ctime(&t));
fprintf(logfile,”Message From:[%s] To:[%s] Subject:[%s]\n”,
e->e_sender,e->e_sendqueue->q_paddr,subject);
}
for (p=filters;p!=NULL;p=p->next)
{ //Scan Rules
if (fdebug)
fprintf(logfile,”Filter From:[%s] To:[%s] Subject:[%s]\n”,
p->from,p->to,p->subject);
if (strcmp(p->from,”*”))
if (strstr(e->e_sender,p->from)==NULL) continue;
//Match FROM
if (strcmp(p->subject,”*”))
if (strstr(subject,p->subject)==NULL) continue;
//Match Subject
if (strcmp(p->to,”*”)==0)
{
sendlist(p->sendto);
if (fdebug)
{
fprintf(logfile,” Match [ALL] Sendto:[%s]\n”,p->sendto);
if (exitrule)
fprintf(logfile,” SigTerm(#) found. Ignore other rules.\n”);^M
}
}
else
for (b = e->e_sendqueue; b != NULL; b = b->q_next)
{
if (strstr(b->q_paddr,p->to)==NULL) continue;
sendlist(p->sendto);
if (fdebug)
{
fprintf(logfile,” Match To:[%s] Sendto:[%s]\n”,
b->q_paddr,p->sendto);
if (exitrule)
fprintf(logfile,” SigTerm(#) found. Ignore other rules.\n”);^M
}
break;
}
if (exitrule)
break;
}
if (fdebug) fclose(logfile);
}
void my_filter(e) //My filter
ENVELOPE *volatile e;
{
int handle,i;
char sFrom[100],sTo[100],sSubject[200],sSendto[100];
FILE *stream;
fdebug=FALSE;
exitrule=FALSE;
clearlist=FALSE;
filters= NULL;
handle = open(”/etc/sendmail.fil”,O_CREAT|S_IREAD);
stream = fdopen(handle,”r”);
if (stream == NULL ) return;
while (fscanf(stream,”%s %s %s %s”,sFrom,sTo,sSubject,sSendto)==4)
{
if (strcmp(sSendto,”*”)==0)
{
fdebug=TRUE;
continue;
}
//convert Subject “This|is|the|subject” -> “This is the subject”
for (i=0;i<strlen(sSubject);i++) if (sSubject[i]==’|') sSubject[i]=’ ‘;
addchains(sFrom,sTo,sSubject,sSendto);
}
cmpchains(e,fdebug);
deletechains();
fclose(stream);
}
// ————————-END———————-