NFS 共享存储支撑下的 HAProxy+Nginx 集群性能验证实验

1.1 主机规划

主机名 IP地址 安装软件
haproxy 192.168.72.100/24 haproxy
nginx1 192.168.72.10/24 nginx,nfs-utils
nginx2 192.168.72.20/24 nginx,nfs-utils
nfs 192.168.72.30/24 nfs-utils

1.2 搭建nfs

1.2.1 环境准备

1、克隆服务器

2、设置主机名、ip

root@node1 \~# nmcli c modify ens160 ipv4.method manual ipv4.addresses 192.168.72.30/24 ipv4.gateway 192.168.72.2 ipv4.dns 223.5.5.5 connection.autoconnect yes

root@node1 \~# nmcli c up ens160

root@node1 \~# hostnamectl set-hostname nfs && bash

root@nfs \~#

3、关闭防火墙

复制代码
[root@nfs ~]# systemctl disable --now firewalld.service 
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".

4、关闭selinux

复制代码
[root@nfs ~]# setenforce 0
[root@nfs ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config
1.2.2 安装nfs

1、创建共享目录

复制代码
[root@nfs ~]# mkdir /share

2、创建共享文件

复制代码
[root@nfs ~]# vim /share/index.html
nfs 192.168.72.30

3、为文件设置权限

复制代码
[root@nfs ~]# chown -R nobody: /share

4、安装nfs

复制代码
[root@nfs ~]# dnf install nfs-utils -y

5、配置nfs

复制代码
[root@nfs ~]# vim /etc/exports

文件内容如下:

复制代码
/share  192.168.72.0/24(rw,sync,no_subtree_check)

验证配置

复制代码
[root@nfs ~]# exportfs -rv
exporting 192.168.72.0/24:/share

6、启动nfs

复制代码
[root@nfs ~]# systemctl start nfs-server.service

验证启动

复制代码
[root@nfs ~]# showmount -e 192.168.72.30
Export list for 192.168.72.30:
/share 192.168.72.0/24

1.3 搭建nginx2

1.3.1 环境准备

1、克隆一台虚拟机

2、设置主机名

复制代码
[root@localhost ~]# hostnamectl set-hostname nginx2 && bash

3、关闭防火墙

复制代码
[root@nginx2 ~]# systemctl disable --now firewalld.service 
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".

4、关闭selinux

复制代码
[root@nginx2 ~]# setenforce 0
[root@nginx2 ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config

5、设置IP地址

复制代码
[root@nginx2 ~]# nmcli c m ens160 ipv4.method manual ipv4.addresses 192.168.72.20/24 ipv4.gateway 192.168.72.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@nginx2 ~]# nmcli c up ens160
1.3.2 安装nginx

1、安装nginx

复制代码
[root@nginx2 ~]# dnf install nginx -y

2、将nginx根目录挂载到共享路径下

复制代码
# 安装工具
[root@nginx2 ~]# dnf install nfs-utils -y
# 挂载目录
[root@nginx2 ~]# mount -t nfs 192.168.72.30:/share /usr/share/nginx/html/
# 查看目录
[root@nginx2 ~]# ls /usr/share/nginx/html/
index.html
# 查看文件
[root@nginx2 ~]# cat /usr/share/nginx/html/index.html 
nfs 192.168.72.30

3、启动服务

复制代码
[root@nginx2 ~]# systemctl start nginx

4、访问测试

复制代码
[root@nginx2 ~]# curl 192.168.72.20
nfs 192.168.72.30

1.4 搭建nginx1

1.4.1 环境准备

1、克隆一台虚拟机

2、设置主机名

复制代码
[root@localhost ~]# hostnamectl set-hostname nginx1 && bash

3、关闭防火墙

复制代码
[root@nginx1 ~]# systemctl disable --now firewalld.service 
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".

4、关闭selinux

复制代码
[root@nginx1 ~]# setenforce 0
[root@nginx1 ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config

5、设置IP地址

复制代码
[root@nginx1 ~]# nmcli c m ens160 ipv4.method manual ipv4.addresses 192.168.72.10/24 ipv4.gateway 192.168.72.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@nginx1 ~]# nmcli c up ens160
1.4.2 安装nginx

1、安装nginx

复制代码
[root@nginx1 ~]# dnf install nginx -y

2、将nginx根目录挂载到共享路径下

复制代码
# 安装工具
[root@nginx1 ~]# dnf install nfs-utils -y
# 挂载目录
[root@nginx1 ~]# mount -t nfs 192.168.72.30:/share /usr/share/nginx/html/
# 查看目录
[root@nginx1 ~]# ls /usr/share/nginx/html/
index.html
# 查看文件
[root@nginx1 ~]# cat /usr/share/nginx/html/index.html 
nfs 192.168.72.30

3、启动服务

复制代码
[root@nginx1 ~]# systemctl start nginx

4、访问测试

复制代码
[root@nginx1 ~]# curl 192.168.72.10
nfs 192.168.72.30

1.5 搭建haproxy

1.5.1 环境准备

1、克隆一台虚拟机

2、设置主机名

复制代码
[root@localhost ~]# hostnamectl set-hostname haproxy && bash

3、关闭防火墙

复制代码
[root@haproxy ~]# systemctl disable --now firewalld.service
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".

4、关闭selinux

复制代码
[root@haproxy ~]# setenforce 0
[root@haproxy ~]# sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/selinux/config

5、设置IP地址

复制代码
[root@haproxy ~]# nmcli c m ens160 ipv4.method manual ipv4.addresses 192.168.72.100/24 ipv4.gateway 192.168.72.2 ipv4.dns 223.5.5.5 connection.autoconnect yes
[root@haproxy ~]# nmcli c up ens160
1.5.2 安装haproxy

1、安装haproxy

复制代码
[root@haproxy ~]# dnf install haproxy -y

2、配置haproxy

复制代码
[root@haproxy ~]# cp -p /etc/haproxy/haproxy.cfg{,.bak}
[root@haproxy ~]# vim /etc/haproxy/haproxy.cfg

文件内容如下:

复制代码
global
    log         127.0.0.1 local2
​
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon
​
    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats mode 600 level admin
​
    # utilize system-wide crypto-policies
    ssl-default-bind-ciphers PROFILE=SYSTEM
    ssl-default-server-ciphers PROFILE=SYSTEM
​
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
​
frontend webserver
    bind *:80
    default_backend             webcluster
​
backend webcluster
    balance     roundrobin
    server web1 192.168.72.10:80 check inter 2000 rise 2 fall 3 weight 1
    server web2 192.168.72.20:80 check inter 2000 rise 2 fall 3 weight 1

3、验证配置文件语法

复制代码
[root@haproxy ~]# haproxy -c -f /etc/haproxy/haproxy.cfg
Configuration file is valid

4、启动haproxy

复制代码
[root@haproxy ~]# systemctl start haproxy

5、访问测试

复制代码
[root@haproxy ~]# systemctl start haproxy
[root@haproxy ~]# curl 192.168.72.100
nfs 192.168.72.30
[root@haproxy ~]# curl 192.168.72.100
nfs 192.168.72.30
[root@haproxy ~]# curl 192.168.72.100
nfs 192.168.72.30
[root@haproxy ~]# curl 192.168.72.100
nfs 192.168.72.30
[root@haproxy ~]# curl 192.168.72.100
nfs 192.168.72.30
[root@haproxy ~]# curl 192.168.72.100
nfs 192.168.72.30
[root@haproxy ~]# curl 192.168.72.100
nfs 192.168.72.30
相关推荐
逸模11 小时前
告别熬夜手工整理台账,逸模智能归集实现项目数据自动化存档
大数据·运维·人工智能·笔记·其他·信息可视化·自动化
sbjdhjd11 小时前
Redis 主从复制、哨兵高可用与 Cluster 集群部署实验手册
运维·前端·redis·云原生·开源·bootstrap·html
AOwhisky12 小时前
MySQL 学习笔记(第四期):SQL 语言之多表查询
linux·运维·网络·数据库·笔记·学习·mysql
Phantom Void12 小时前
服务器处理客户端请求的设计方法
linux·运维·网络
倔强的石头10612 小时前
Fooocus开源神器+cpolarAI让绘画告别服务器依赖
运维·服务器·cpolar
wei_shuo12 小时前
服务器挂了等用户投诉才发现?我用Beszel搭了轻量监控系统,宕机第一时间通知我
运维·服务器
王码码203512 小时前
多台服务器怎么统一看状态?Beszel 轻量监控,搭起来不费事
运维·服务器·后端·安全·阿里云·接口·web
APItesterCris15 小时前
实战教程:借助 Open Claw + 淘宝商品 API,低成本实现电商自动化监控与智能选品
大数据·运维·自动化
风曦Kisaki17 小时前
# 自动化运维Day03:Ansible模块进阶(setup,debug),四种常用变量,进阶语法;Ansible Roles(角色)
运维·自动化·ansible
赵民勇17 小时前
Linux strings命令详解
linux·运维