Nginx模拟CLB搭建nginx+nfs同步web服务器搭建

实验目的:模拟生产环境clb 云平台负载均衡 后端web服务器,nfs共享存储,若没有clb,也可以keeplived-nginx vip方式完成搭建

这个实验省略了redis mysql 等真实生产环境。同理可以使用云平台mysql,redis产品即可,或者自建高可用中间件集群

集群角色系统配置
192.168.26.130 (clb)nginx代替centos7.6 2c2g
192.168.26.130 web服务器-nfs服务端centos7.6 2c1g
192.168.26.130 web服务器-nfs客户端centos7.6 2c1g

首相我们安装nginx 3个环境执行

省略环境配置
主机名修改以及hostname修改

yum -y install nginx

两台web服务器上操作

web服务器搭建nfs共享存储


web1nfs-服务端

yum install nfs-utils rpcbind -y

mkdir /data  ##创建共享目录

vim /etc/exports  ##配置nfs server端
/data 192.168.26.120(rw,no_root_squash)
##nfs配置规则可以百度 建议生产中指定ip段

##设置开机自启 
systemctl enable rpcbind 
systemctl enable nfs-server
systemctl start rpcbind
systemctl start nfs-server
exportfs -r 重读配置文件

web2-nfs-客户端操作

yum install -y nfs-utils

showmount -e 192.168.26.100 ##执行查看nfs服务端得共享情况 ip记得替换
输出结果正常
Export list for 192.168.26.100:
/data 192.168.26.120

创建本地共享文件夹
mkdir /data
mount -t nfs 192.168.26.100:/data/ /data/ ##挂载共享目录文件夹

开启开机自动挂载
vim /etc/fstab

...
##加入此行
192.168.26.100:/data /data nfs defaults 0 0

df -h ##查看是否挂载成功

在这里插入图片描述
两台web服务器同时操作

修改nginx.conf主页目录为nfs路径

...
server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /data; ##主页路径修改成nfs目录
            index  index.html index.htm;
        }


设置一个主页
echo haitao01! > /data/index/html
启动nginx
nginx -t ##检测conf是否正确
nginx -s reload ##重读配置文件
验证
[root@web2_nfs2 conf]# curl 192.168.26.100
haitao01!

测试nfs效果
任何一台web服务器修改主页index.html看是否生效

echo haitao > /data/index.html

验证
[root@web2_nfs2 conf]# curl 192.168.26.120
haitao
[root@web2_nfs2 conf]# curl 192.168.26.100
haitao

web服务器配置完成
下面开出配置clb负载均衡器
这里我就用另外一台nginx来代替

vim nginx.conf
需要修改得部分配置
...
http {
    include       mime.types;
    default_type  application/octet-stream;

    upstream  test-web {       ##配置负载均衡 
       server    192.168.26.100:80;
       server    192.168.26.120:80;
    }
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            proxy_pass http://test-web;  ##和上面得负载均衡关联
            root   html;
            index  index.html index.htm;
        }
...

验证

[root@slb_nginx nginx]# curl 192.168.26.130
haitao01!
[root@slb_nginx nginx]# curl 192.168.26.130
haitao01!
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大鹅i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值