共享nfs和nginx负载均衡

简介: 共享nfs和nginx负载均衡

环境:在分布式基础上搭建nfs

nginx1:192.168.8.10

mysql:192.168.8.20

php: 192.168.8.30

nfs: 192.168.8.40

nginx2: 192.168.8.50

nginx_lb: 192.168.8.60

1.搭建nfs共享服务器,把网站静态元素通过挂载方式放在nfs上

   

(1)开启一台centos7,安装nfs-utils、rpcbind:

yum -y install nfs-utils  rpcbind

(2)创建挂载点

mkdir -p /nfs/blog

(3)发布共享目录  

vim /etc/exports

  添加:

/nfs/blog    192.168.8.0/24(rw,sync,no_root_squash)

  保存退出

   

(4)重启nfs服务

  systemctl restart rpcbind
    systemctl restart nfs

(5)在nginx服务器上查看nfs共享目录

showmount -e 192.168.8.40

(6)把wordpress的内容目录挂载到nfs

cd /wordpress
    cp -rp wp-content/  wp-contentbak
    mount -t nfs 192.168.8.40:/nfs/blog  wp-content
    cp -rp wp-contentbak/*  wp-content/

(7)设置永久挂载

vim /etc/fstab

添加:    

192.168.8.40:/nfs/log  /wordpress/wp-content   nfs     defaults        0 0

保存退出

   

2.搭建第二台web服务器

(1)安装nginx

yum -y epel-release
    yum -y install nginx

(2)把web1(192.168.8.10)上的nginx的配置复制到web2(192.168.8.50)

scp -rp /etc/nginx/*  root@192.168.8.50:/etc/nginx

(3)把web1上网页源码复制到web2

scp -rp /wordpress root@192.168.8.50:/

(4)启动服务

systemctl start nginx

3.搭建nginx负载均衡(192.168.8.60)

(1)安装nginx

yum -y install epel-release
yum -y install nginx

(2)配置负载均衡

vim /etc/nginx/conf.d/lb1.conf

添加:

upstream webcluster {
        server 192.168.8.10:80;
        server 192.168.8.50:80;
}
server {
        listen 80;
        server_name blog.benet.com;
        location / {
                proxy_pass      http://webcluster;
                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
}
}

保存退出

systemctl restart nginx

4.nginx1和nginx2,动态查看nginx访问日志

tail -f /var/log/nginx/access.log

5.客户端修改/etc/hosts,指向lb服务器,访问网站

vim /etc/hosts
192.168.8.60  blog.benet.com


相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
目录
相关文章
|
移动开发 JSON 监控
网络协议解析:在员工上网监控软件中实现HTTP流量分析
随着企业对员工网络活动的监控需求不断增加,开发一套能够实现HTTP流量分析的网络协议解析系统变得愈发重要。本文将深入探讨如何在员工上网监控软件中实现HTTP流量分析,通过代码示例演示关键步骤。
565 0
|
存储 安全 Linux
Proxmox Backup Server 4.0 Beta - 开源企业级备份解决方案
Proxmox Backup Server 4.0 Beta - 开源企业级备份解决方案
806 0
Proxmox Backup Server 4.0 Beta - 开源企业级备份解决方案
|
Ubuntu Linux API
在Linux中,如何在Linux中安装和配置KVM?
在Linux中,如何在Linux中安装和配置KVM?
|
Linux
开源日志平台GrayLog5.1.7 CentOS7一键安装脚本
开源日志平台GrayLog5.1.7 CentOS7一键安装脚本
548 1
|
Linux 数据安全/隐私保护 Docker
一键脚本快速安装容器版GrayLog
一键脚本快速安装容器版GrayLog
1319 0
一键脚本快速安装容器版GrayLog
Proxmox VE (PVE) 销毁集群
可以尝试以下方法将正常节点的集群状态销毁,在需要时重建集群
1026 0
|
运维 安全 Linux
【Anolis OS】龙蜥操作系统(Anolis OS) 8.6安装指南
【Anolis OS】龙蜥操作系统(Anolis OS) 8.6安装指南
10204 0
|
存储 Web App开发 虚拟化