标签:LVS_DR
LVS_DR
使用DR模型的FWM类型的lvs服务负载均衡一个php应用,如Discuz!论坛或者phpMyAdmin;
前提条件:三台主机(一台调度器,两台服务器即RS)
声明:调度器配置一个网络接口
主接口地址:172.16.1.11/16(DIP)
主接口标签地址:172.16.1.254/32(VIP)
# ifconfig ens33:0 172.16.1.254 netmask 255.255.255.255 broadcast 172.16.1.254 up
RS1:
主接口:172.16.1.12/16
环回接口的标签接口:172.16.1.254/32
# ifconfig lo:0 172.16.1.254 netmask 255.255.255.255 broadcast 172.16.1.254 up
RS2:
主接口:172.16.1.13/16
环回接口的标签接口:172.16.1.254/32
# ifconfig lo:0 172.16.1.254 netmask 255.255.255.255 broadcast 172.16.1.254 up
配置:
RS1:内核参数的配置:
# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
配置LAMP服务:
前提:安装LAMP所需组件:
# yum install httpd php php-mysql mariadb-server
创建虚拟主机:
# cd /etc/httpd/conf.d/
# vim vhost1.conf
<VirtualHost 172.16.1.12:80>
ServerName www.ytc.com
DocumentRoot "/myweb/vhost1"
DirectoryIndex index.php
<Directory "/myweb/vhost1">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
完善虚拟主机所需目录要求:
# mkdir -pv /myweb/vhost1
# cd /myweb/vhost1
# vim index.php (做测试页面)
Real Server 1 <br>
<?php
phpinfo();
?>
将phpmyadmin包传送到该目录并解压
# tsr xf phpMyAdmin-3.5.4-all-languages.tar.gz
注意iptables和SELinux的干扰:
# iptables -F
# setenforce 0
RS2:内核参数的配置:
# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
配置LAMP服务:
前提:安装LAMP所需组件:
# yum install httpd php php-mysql mariadb-server
创建虚拟主机:
# cd /etc/httpd/conf.d/
# vim vhost1.conf
<VirtualHost 172.16.1.13:80>
ServerName www.ytc.org
DocumentRoot "/myweb/vhost2"
DirectoryIndex index.php
<Directory "/myweb/vhost2">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
完善虚拟主机所需目录要求:
# mkdir -pv /myweb/vhost2
# cd /myweb/vhost2
# vim index.php (做测试页面)
Real Server 2 <br>
<?php
phpinfo();
?>
将wordpress包传送到该目录并解压
# tsr xf wordpress-4.2-zh_CN.tar.gz
注意iptables和SELinux的干扰:
# iptables -F
# setenforce 0
调度器配置:
给数据报文打标记;
# iptables -t mangle -A PREROUTING -d 172.16.1.254 -p tcp --dport 80 -j MARK --set-mark 10
创建集群:
# ipvsadm -A -f 10 -s wrr
向集群中添加RS:
# ipvsadm -a -f 10 -r 172.16.1.12 -g -w 2
# ipvsadm -a -f 10 -r 172.16.1.13 -g -w 2
web端测试:
输入172.16.1.254/index.php
第三次输入172.16.1.254:
然后做长连接和数据库共享(上一篇博客中,这里不再赘述)
web端测试:172.16.1.254/wordpress/index.php
创建数据库授权用户后,登录:
完成;
标签:LVS_DR
原文地址:http://blog.51cto.com/yuantianchi/2126592