六、LVS-DR应用实例
(一)基本构建思路:
Director: 通过Director实现访问调度到RS1,RS2,实现负载均衡,RS3负责动态分离。
基本拓扑图如下:
(二) 实现方法:
1) 设置nfs 共享目录, /data/wwwroot/wordpress/
yum install -y nfs-utils
service rpcbind start
service nfs start
mkdir -pv /data/wordpress/
useradd -M -r -s /sbin/nologin -u 3307 www
chown www:www /data/wwwroot/wordpress/
vim /etc/exports
/data/wordpress/ 181.163.10.0/24(rw,no_root_squash)
2)将wordpress安装包解压到此目录,并安装PHP,mariadb,修改权限和相应配置
修改共享文件目录及文件权限
chown -R www:www /data/wwwroot/wordpress/
php-fpm.conf 配置修改
listen = 9000 #监听 9000 端口
listen.allowed_clients = 181.163.10.9,181.163.10.10,127.0.0.1 #允许IP
建立数据库
mysqladmin -u root -p create dbase_wordpress_01;
use dbase_wordpress_01;
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
-> ON dbase_wordpress_01.*
-> TO 'localhost'
-> IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.00 sec)
3)RS1 RS2 设置vip 及lo
echo "0">/proc/sys/net/ipv4/ip_forward
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
ifconfig lo:0 $vip netmask 255.255.255.255 broadcast $vip
route add -host $vip dev lo:0
执行脚本完成LVS_Realserver.sh ,RS1结果如下
lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet 181.163.11.254/0 scope global lo:0:1
inet 181.163.11.254/32 brd 181.163.11.254 scope global lo:0
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
4)挂载共享目录
mount -t nfs 181.163.10.11:/data/wwwroot/wordpress/ /data/wwwroot/wordpress/
5) 修改 nginx.conf 文件
root /data/wwwroot/wordpress/;
fastcgi_pass 181.163.10.11:9000;
6)Director 设置
yum install ipvsadm -y
ipvsadm -A -t $VIP:80 -s rr -p 120
ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
echo "0">/proc/sys/net/ipv4/ip_forward
ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
route add -host $VIP dev eth0:0
运行脚本完成添加集群服务及集群节点:LVS_Director.sh
查看结果: ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 181.163.11.254:80 rr persistent 120
-> 181.163.11.2:80 Route 1 0 0
-> 181.163.11.3:80 Route 1 0 0
(三)、结果截图
原创文章,作者:Acheng,如若转载,请注明出处:http://www.178linux.com/55184
评论列表(1条)
详实有料,生动有趣,能加入一些注释信息、架构的解说会更好,加油!