Lvs-nat实验
实验设备:三台centos虚拟机
Director:DIP:10.0.0.254 VIP:192.168.208.129
RS1:RIP:10.0.0.1
RS2:RIP:10.0.0.2
首先都安装ipvsadm、telnet、httpd
- 配置网卡:RS2:hostonly模式:10.0.0.2/24
配置网卡:RS1:hostonly模式:10.0.0.1/24 方法同上nmtui 配置完使用ip add l查看
配置网卡:Director:ens33: VIP:192.168.208.129 DIP:10.0.0.254
- 在director上打开网卡间转发功能
vim /etc/sysctl.conf
添加net.ipv4.ip_forward=1
执行sysctl -p
- 在RS1、RS2上分别编辑html文件
RS1:<h1>RS1</h1>
RS2:<h1>RS2</h1>
确保关闭防火墙,或者放行80端口
在Director上测试curl http://10.0.0.1 curl http://10.0.0.2
4、
[root@localhost ~]#ipvsadm -A -t 192.168.208.129:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.208.129:80 -r 10.0.0.1:80 -m -w 1
[root@localhost ~]# ipvsadm -a -t 192.168.208.129:80 -r 10.0.0.2:80 -m -w 2
轮询状态做负载均衡
- [root@localhost ~]# ipvsadm -E -t 192.168.208.129:80 -s wrr
以加权轮询做负载均衡
实验2:lvs-nat做WordPress的负载均衡
增加db服务器:RIP:10.0.0.3
Yum -y install mariadb-server nfs-utils
MariaDB [mysql]> CREATE DATDABASE wpdb;
MariaDB [mysql]> GRANT ALL PRIVILEGES ON wpdb.* TO ‘wpuser’@’%’ IDENTIFIED BY ‘wppass’;
MariaDB [mysql]> FLUSH PRIVILEGES;
[root@centos ~]# mkdir /nfs/app/ -pv
[root@centos ~]# cp wordpress-4.8.1-zh_CN.zip /nfs/app/
[root@centos ~]# cd /nfs/app
[root@centos app]# unzip wordpress-4.8.1-zh_CN.zip
[root@centos wordpress]# cp wp-config-sample.php wp-config.php
[root@centos wordpress]# vim wp-config.php
[root@centos wordpress]# id apache
uid=48(apache) gid=48(apache) groups=48(apache
看下是否存在Apache用户和Apache组,没有的话自己创建
[root@centos app]# chown -R apache:apache wordpress
vim /etc/exports
/nfs/app/wordpress 10.0.0.0/16(rw,async,anonuid=48,anongid=48)
[root@centos wordpress]# systemctl start nfs
[root@centos wordpress]# showmount -e 192.168.208.132
Export list for 192.168.208.132:
/nfs/app/wordpress 10.0.0.0/16
然后设置网卡
Ip改成10.0.0.3 gw10.0.0.254
在RS1和RS2上yum -y install nfs-utils
在director上做snat
[root@localhost ~]# iptablt nat -A POSTROUTING -s 10.0.0.0/24 -j SNAT –to-source 192.168.208.129
还有给RS配DNS 要不然yum不了 – -ll
mount -t nfs 10.0.0.3:/nfs/app/wordpress /var/www/html/
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/88805