dr模式中lvs主機與實際伺服器都有一塊網絡卡連在同一物理網段上。
ip分配
vip:10.10.3.170
rip1:10.10.3.140
rip2:10.10.3.141
1、安裝所需的依賴包
yum install -y wget make kernel-devel gcc gcc-c++ libnl* libpopt* popt-static
2、建立乙個軟鏈結,防止後面編譯安裝ipvsadm時找不到系統核心
ln -s /usr/src/kernels/2.6
.32-358.18
.1.el6.x86_64/ /usr/src/linux
wget
.org/software/kernel-2.6/ipvsadm-1.26
.tar
.gztar zxvf ipvsadm-1.26
.tar
.gzcd ipvsadm-1.26
make && make install
4、編寫並執行指令碼(lvs伺服器的指令碼)
vi lvs.sh
#!/bin/bash
# 2013-09-07 by kgdxpr
vip=10.10.3.170
rip1=10.10.3.140
rip2=10.10.3.141
/etc/rc.d/init.d/functions
logger $0 called with $1
case
"$1"
instart)
echo
" start lvs of directorserver"
/sbin/ifconfig eth0:0
$vip broadcast $vip netmask 255.255.255.255 up
/sbin/route add -host $vip dev eth0:0
echo
"1" >/proc/sys/net/ipv4/ip_forward
#clear ipvs table
/sbin/ipvsadm -c
#set lvs
/sbin/ipvsadm -a -t $vip:80
-s rr
/sbin/ipvsadm -a -t $vip:80 -r $rip1:80 -g
/sbin/ipvsadm -a -t $vip:80 -r $rip2:80 -g
#run lvs
/sbin/ipvsadm
;;stop)
echo
"close lvs directorserver"
echo
"0" >/proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -c
/sbin/ifconfig eth0:0 down
;;*)
echo
"usage: $0 "
exit
1esac
注:/sbin/ipvsadm -a -t $vip:80 -s rr (rr代表輪詢,還有分配方式)
/sbin/ipvsadm -a -t vi
p:80−
r rip1:80 -g (-g代表dr模式,還有其他模式)
5、給指令碼加許可權,並執行
chmod +x lvs.sh
chmod 755 /etc/rc.d/init.d/functions
./lvs.sh start
6、配置後端的web伺服器指令碼
vi realserver.sh
#!/bin/bash
# 2013-09-07 by kgdxpr
vip=10.10.3.170
/etc/rc.d/init.d/functions
case
"$1"
instart)
echo
" start lvs of realserver"
/sbin/ifconfig lo:0
$vip broadcast $vip netmask 255.255.255.255 up
/sbin/route add -host $vip dev lo:0
echo
"1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo
"2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo
"1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo
"2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p >/dev/null 2>&1
;;stop)
/sbin/ifconfig lo:0 down
echo
"close lvs directorserver"
echo
"0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo
"0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo
"0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo
"0" >/proc/sys/net/ipv4/conf/all/arp_announce
;;*)
echo
"usage: $0 "
exit
1esac
7、給指令碼加許可權,並執行
chmod +x realserver.sh
chmod 755 /etc/rc.d/init.d/functions
./realserver.sh start
CentOS 6 4 安裝配置ftp
1 安裝vsftpd yum install vsftpd 2 關閉防火牆 service iptables stop 3 允許21埠通行 vi etc sysconfig iptables 新增兩條 a input m state state new m tcp p tcp dport 21 j ...
修改CentOS6 4網路配置
一 centos 修改ip位址 修改對應網絡卡的ip位址的配置檔案 vi etc sysconfig network scripts ifcfg eth0 修改以下內容 device eth0 描述網絡卡對應的裝置別名,例如ifcfg eth0的檔案中它為eth0 bootproto static ...
CentOS6 4配置163的yum源
centos系統自帶的更新源的速度實在是慢,為了讓centos6使用速度更快的yum更新源,可以選擇163 網易 的更新源。wget 2.備份並替換系統的repo檔案 root localhost cd etc yum.repos.d root localhost mv centos base.re...