一、搭建nat模式下LVS的實驗環境
1.創建四臺虛擬機
client——客戶端:192.168.134.111/24(nat模式)
LVS——調度器【雙網卡】:192.168.134.112/24(nat模式)、172.25.254.111/24(僅主機模式)
RS1——服務器:172.25.254.10(僅主機模式)
RS2——服務器:172.25.254.20(僅主機模式)
2.給兩臺測試主機下載httpd服務
[root@RS1 ~]# dnf install httpd -y
[root@RS1 ~]# systemctl enable --now httpd[root@RS2 ~]# dnf install httpd -y
[root@RS2 ~]# systemctl enable --now httpd(注:下載完httpd服務后別忘了啟動該服務)
使用:
[root@LVS ~]# ss -tulpn | grep :80
tcp LISTEN 0 511 *:80 *:* users:(("httpd", pid=30465,fd=4),("httpd",pid=30464,fd=4),("httpd",pid=30463,fd=4),("httpd",pid=3 0461,fd=4))可以通過端口查看該服務是否開啟
3.關閉RS1、RS2虛擬機的防火墻
[root@RS1 ~]# systemctl disable --now firewalld
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".[root@RS2 ~]# systemctl disable --now firewalld
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
記得查看防火墻狀態:
systemctl status firewalld
4.給RS1、RS2兩臺服務器開啟web服務
[root@RS1 ~]# mkdir -p /var/www/html
[root@RS1 ~]# echo "RS1 -- 172.25.254.10" > /var/www/html/index.html[root@RS2 ~]# mkdir -p /var/www/html
[root@RS2 ~]# echo "RS2 -- 172.25.254.20" > /var/www/html/index.html
5.保證LVS能訪問到RS1、RS2兩臺服務器的web服務
[root@LVS ~]# curl 172.25.254.10
RS1 -- 172.25.254.10
[root@LVS ~]# curl 172.25.254.20
RS2 -- 172.25.254.20
6.修改LVS內核參數,打開內核路由功能,使系統內部不同網段網絡可達(IP轉發)
[root@LVS ~]# sysctl -a | grep ip_forward
net.ipv4.ip_forward = 0
net.ipv4.ip_forward_update_priority = 1
net.ipv4.ip_forward_use_pmtu = 0
[root@LVS ~]# vim /etc/sysctl.conf
[root@LVS ~]# sysctl -p
net.ipv4.ip_forward = 1
7.接著為調度器LVS安裝ipvsadm
[root@LVS ~]# dnf install ipvsadm -y
二、如果要使客戶端到RS1、RS2這幾臺虛擬機可以互相通信,那么還需修改網關
RS1:
[connection]
id=eth0
type=ethernet
interface-name=eth0[ipv4]
method=manual
address1=172.25.254.10/24,172.25.254.111
dns=8.8.8.8RS2:
[connection]
id=eth0
type=ethernet
interface-name=eth0[ipv4]
method=manual
address1=172.25.254.20/24,172.25.254.111
dns=8.8.8.8記得修改完之后要
nmcli connection reload
nmcli connection up eth0
效果為:
??