准备工作

首先配置一下环境:

      Directory:ens33 172.16.251.73 ens37 192.168.42.1

      RS1:192.168.42.132  gw 192.168.42.1

      RS2:192.168.42.133  gw 192.168.42.1

   将全部主机时间同步 :ntpdate 172.16.0.1

大致拓扑图为:

    LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

在RS1、2上:

    yum install httpd php php-mysql

vim /etc/httpd/conf.d/zhang.conf

  LVS--搭建一个LVS-nat,负载均衡 WordPress (5)  LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

将wordpress目录创建软连接:

    ln -s /tmp/wordpress/ /var/www/html/wordpress/

在数据库主机上:

    yum install mariadb-server

 编辑配置文件:

    vim /etc/my.cnf.d/server.cnf

    LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

开启服务systemctl start mariadb

    对数据库进行操作:

        LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

回到RealServer中:

  编辑wordpress配置文件:

    cp wp-config-sample.php  wp-config.php

    vim wp-config.php

    LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

chmod -R a+w wordpress/LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

启动httpd服务


再将非结构化的的内容共享在一台主机上,利用NFS:    

    yum install -y nfs-utils

    mkdir /data/wp

    vim /etc/exports

LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

systemctl start nfs.service

ss -ntl 查看2049端口开启

在RS服务器上:

mount -t nfs 192.168.42.138:/data/wp /var/www/html/wp-content/

在Directory中:

    yum install -y ipvsadm

  配置lvs-nat:   

    ipvsadm -A -t 172.16.251.73:80 -s rr

    ipvsadm -a -t 172.16.251.73:80 -r 192.168.42.132 -m

    ipvsadm -a -t 172.16.251.73:80 -r 192.168.42.133 –m

ipvsadm -ln

LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

开启核心转发功能:

    sysctl -w net.ipv4.ip_forward=1

测试:


在RS主机中查看访问日志,

LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

可知遵循lvs轮询模式

编辑新的文章:

LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

在数据库中查看:

    LVS--搭建一个LVS-nat,负载均衡 WordPress (5)

可见,搭建成功

相关文章:

  • 2021-06-18
  • 2021-09-18
  • 2021-08-30
  • 2021-06-08
  • 2021-12-24
  • 2021-09-01
  • 2022-01-09
  • 2021-09-10
猜你喜欢
  • 2021-05-13
  • 2021-07-18
  • 2021-08-13
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案