|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
功能实在太强了,在配合exec参数或者通过管道重定向到xargs命令和grep命令,可以完成非常复杂的操作,如果同样的操作用图形界面的工具来完成,恐怕要多花十几陪的时间。
split_two
情况四台呆板都是RedHat4.8(64位)版本:
IP地点用途
192.168.5.55MASTER
192.168.2.73BACKUP
192.168.5.54负载A
192.168.5.57负载B
192.168.2.100VIP
1、MASTER上安装haproxy
.代码以下:
wgethttp://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.20.tar.gz/root
解压到以后目次
tarzxvfhaproxy-1.3.20.tar.gz
进到此目次
cdhaproxy-1.3.20
编译及安装,安装到/usr/local目次,可是安装完此目次下没有haproxy文件夹,我也很奇异!
makeTARGET=linux26prefix=/usr/local/haproxyinstall
可是出来的了局会提醒以下信息
install-d/usr/local/sbin
installhaproxy/usr/local/sbin
install-d/usr/local/share/man/man1
install-m644doc/haproxy.1/usr/local/share/man/man1
install-d/usr/local/doc/haproxy
forxinconfigurationarchitecturehaproxy-enhaproxy-fr;do
install-m644doc/$x.txt/usr/local/doc/haproxy;
done
提醒你启动haproxy在sbin目次,其他的在doc目次
进进到haproxy目次
cd/usr/local/doc/haproxy
新建一个haproxy主设置文件
.代码以下:
vihaproxy.cfg
global
log127.0.0.1local0
maxconn4096
chroot/usr/local/doc/haproxy
uid501
gid501
daemon
nbproc1
pidfile/usr/local/doc/haproxy/haproxy.pid
defaults
log127.0.0.1local3
modehttp
optionhttplog
optionhttpclose
optiondontlognull
optionforwardfor
optionredispatch
retries2
maxconn2000
balanceroundrobin
statsuri/haproxy-status检察形态
statshide-version埋没haproxy版本
statsrealmGeminiHaproxy检察形态必要口令
statsauthadmin:admin用户名和暗码
contimeout5000
clitimeout50000
srvtimeout50000
listenweb_proxy192.168.2.100:80
serverweb1192.168.5.54:8080cookieapp1inst1checkinter2000rise2fall5
serverweb2192.168.5.57:8080cookieapp1inst2checkinter2000rise2fall5
2、MASTER安装keepalived
tarzxvfkeepalived-1.1.15.tar.gz
vi/usr/src/kernels/2.6.9-89.EL-smp-x86_64/include/linux/types.h
将以下两行正文失落,不然编译会堕落,跟我这个版本的体系有干系,你的大概不要!
.代码以下:
/*
typedef__u16__bitwise__sum16;
typedef__u32__bitwise__wsum;
*/
cdkeepalived-1.1.15
./configure
make
makeinstall
将keepalived作为体系服务启动
cp/usr/local/etc/rc.d/init.d/keepalived/etc/init.d/
cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/
mkdir/etc/keepalived/
cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/
cp/usr/local/sbin/keepalived/usr/sbin/
vi/etc/keepalived/keepalived.conf内容以下:
.代码以下:
!ConfigurationFileforkeepalived
global_defs{
router_idLVA_DEVEL
}
vrrp_scriptchk_http_port{
script"/root/check_haproxy.sh"
interval2
weight2
}
vrrp_instanceVI_1{
stateMASTER
interfaceeth0
virtual_router_id51
priority100
advert_int1
authentication{
auth_typePASS
auth_pass1111
}
track_script{
chk_http_port
}
virtual_ipaddress{
192.168.2.100
}
}
下面挪用了一个剧本check_haproxy.sh,内容以下:
.代码以下:
#!/bin/bash
A=`ps-Chaproxy--no-header|wc-l`
if[$A-eq0];then
/usr/local/sbin/haproxy-f/usr/local/doc/haproxy/haproxy.cfg
echo"haproxystart"
sleep3
if[`ps-Chaproxy--no-header|wc-l`-eq0];then
/etc/init.d/keepalivedstop
echo"keepalivedstop"
fi
fi
3、BACKUP上安装haproxy,步骤就不具体先容,和MASTER下面一样的。
haproxy.conf内容以下
.代码以下:
global
log127.0.0.1local0
maxconn4096
chroot/usr/local/doc/haproxy
uid501
gid501
daemon
nbproc1
pidfile/usr/local/doc/haproxy/haproxy.pid
defaults
log127.0.0.1local3
modehttp
optionhttplog
optionhttpclose
optiondontlognull
optionforwardfor
optionredispatch
retries2
maxconn2000
balanceroundrobin
statsuri/haproxy-status
statshide-version
statsrealmGeminiHaproxy
statsauthadmin:admin
contimeout5000
clitimeout50000
srvtimeout50000
listenweb_proxy192.168.2.100:80
serverweb1192.168.5.54:8080cookieapp1inst1checkinter2000rise2fall5
serverweb2192.168.5.57:8080cookieapp1inst2checkinter2000rise2fall5
4、BACKUP上安装keepalived,步骤也未几先容,keepalived.conf文件内容就两处有变更,白色字体标出
.代码以下:
!ConfigurationFileforkeepalived
global_defs{
router_idLVA_DEVEL
}
vrrp_scriptchk_http_port{
script"/root/check_haproxy.sh"
interval2
weight2
}
vrrp_instanceVI_1{
stateBACKUP
interfaceeth0
virtual_router_id51
priority99
advert_int1
authentication{
auth_typePASS
auth_pass1111
}
track_script{
chk_http_port
}
virtual_ipaddress{
192.168.2.100
}
}
挪用剧本check_haproxy.sh内容:
.代码以下:
#!/bin/bash
A=`ipa|grep192.168.2.100|wc-l`
B=`ps-ef|grephaproxy|grep-vgrep|awk{print$2}`
if[$A-gt0];then
/usr/local/sbin/haproxy-f/usr/local/doc/haproxy/haproxy.cfg
else
kill-9$B
fi
5、两台负载呆板我就未几先容了,用的是体系自带的apache
登录192.168.5.54上操纵:
echothisis192.168.5.54!>/var/www/html/index.html
修正/etc/httpd/conf/httpd.conf文件的监听端口为8080
sed-is/Listen80/Listen8080/g/etc/httpd/conf/httpd.conf
/etc/init.d/httpdstart
登录192.168.5.57上操纵:
echoHello,Thisis192.168.5.57!>/var/www/html/index.html
修正/etc/httpd/conf/httpd.conf文件的监听端口为8080
sed-is/Listen80/Listen8080/g/etc/httpd/conf/httpd.conf
/etc/init.d/httpdstart
6、测试步骤
启动MASTER上的keepalived服务,再启动BACKUP上的keepalived服务。
断定MASTER上是不是有192.168.2.100地点,用ipa检察便可!
然先手动杀失落MASTER上的haproxy历程,看看是不是能即刻恢复历程?
中断MASTER上的keepalived服务,确认BACKUP是不是接受VIP地点?
最初再启动MASTER上的keepalived服务,再确认MASTER是不是再接受VIP地点?
总结:我这测试都没成绩,假如有成绩请给我留言!
原文:http://blog.chinaunix.net/uid-23916356-id-3387261.html
学习python,无论你是打算拿他当主要开发语言,还是当辅助开发语言,你都应该学习他,因为有些时间我们耗不起。 |
|