码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • ⽤nginx做负载均衡服务器,配置动静分离


    ⽤nginx做负载均衡服务 器,配置动静分离


    文章目录

    • ⽤nginx做负载均衡服务 器,配置动静分离
        • 部署LNMP ,做动态资源
            • nginx安装
            • mysql安装
            • 安装php
            • 配置nginx
            • 配置PHP网络界面
        • node2安装httpd,做静态资源
        • node3源码安装nginx并配置负载均衡器,进行调度
        • 配置负载均衡
        • 实现动静分离

    题目:
    后端RS服务器⼀台部署LNMP(nginx1.22+mysql8.0+php8.1),⼀台部署
    httpd。
    要求nginx和php使⽤编译安装
    最后要通过访问nginx负载均衡服务器的IP看到动静分离的效果。
    
    • 1
    • 2
    • 3
    • 4
    • 5

    环境准备:

    主机 ip 安装的服务
    node1 192.168.174.170 lnmp,动态资源
    node2 192.168.174.175 nginx,静态资源
    node3 192.168.174.177 nginx,做负载均衡

    部署LNMP ,做动态资源

    nginx安装
    //首先关闭防火墙和selinux
    [root@node1 ~]# setenforce 0
    [root@node1 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
    [root@node1 ~]# systemctl disable  --now firewalld.service 
    
    //创建用户
    [root@node1 ~]# useradd -rMs /sbin/nologin nginx
    
    //安装所需要的依赖包
    [root@node1 ~]# dnf -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget vim
    
    //下载nginx源码包,并解压
    [root@node1 ~]# wget https://nginx.org/download/nginx-1.22.0.tar.gz
    [root@node1 ~]# tar -xf nginx-1.22.0.tar.gz 
    [root@node1 ~]# cd nginx-1.22.0/
    [root@node1 nginx-1.22.0]# 
    
    //编译安装
    [root@node1 nginx-1.22.0]# ./configure \
    > --prefix=/usr/local/nginx \
    > --user=nginx \
    > --group=nginx \
    > --with-debug \
    > --with-http_ssl_module \
    > --with-http_realip_module \
    > --with-http_image_filter_module \
    > --with-http_gunzip_module \
    > --with-http_gzip_static_module \
    > --with-http_stub_status_module 
    
    //开启编译安装
    [root@node1 nginx-1.20.2]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
    
    //安装成功
    [root@node1 nginx-1.22.0]# cd /usr/local/nginx/
    [root@node1 nginx]# ls
    conf  html  logs  sbin
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    nginx配置

    //配置环境变量
    [root@node1 nginx]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
    [root@node1 nginx]# source /etc/profile
    
    //启动服务
    [root@node1 nginx]# nginx 
    [root@node1 nginx]# ss -anlt
    State      Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     Process     
    LISTEN     0          128                    0.0.0.0:80                  0.0.0.0:*                    
    LISTEN     0          128                    0.0.0.0:22                  0.0.0.0:*                    
    LISTEN     0          128                       [::]:22                     [::]:* 
    
    //关闭服务,编写service文件,并设置服务开机自启
    [root@node1 nginx]# cat > /usr/lib/systemd/system/nginx.service << EOF
    > [Unit]
    > Description=nginx server daemon
    > After=network.target 
    > 
    > [Service]
    > Type=forking
    > ExecStart=/usr/local/nginx/sbin/nginx
    > ExecStop=/usr/local/nginx/sbin/nginx -s stop
    > ExecReload=/bin/kill -HUP \$MAINPID
    >  
    > [Install]
    > WantedBy=multi-user.target
    > EOF
    
    
    [root@node1 nginx]# systemctl daemon-reload
    [root@node1 nginx]# systemctl enable --now nginx.service 
    Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
    [root@node1 nginx]# ss -anlt
    State      Recv-Q     Send-Q           Local Address:Port           Peer Address:Port     Process     
    LISTEN     0          128                    0.0.0.0:80                  0.0.0.0:*                    
    LISTEN     0          128                    0.0.0.0:22                  0.0.0.0:*                    
    LISTEN     0          128                       [::]:22                     [::]:*
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37

    1

    mysql安装
    //安装依赖包
    [root@node1 ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
    
    //创建apache服务的用户和组
    [root@node1 ~]# useradd -r -M -s /sbin/nologin mysql[root@node1 ~]# cd /usr/local/
    [root@node1 local]# chown -R mysql.mysql mysql*
    [root@node1 local]# ll |gerp mysql
    bash: gerp: command not found
    [root@node1 local]
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
  • 相关阅读:
    error: ‘dummy’ may be used uninitialized [-Werror=maybe-uninitialized]
    【Java】使用HttpClient进行简单的post请求
    gradle版本是7.1.3加载arr包踩坑
    【毕业设计】基于单片机的智能饮水机系统 - stm32 物联网 嵌入式
    思腾云计算
    (部署服务器系列三)eclipse远程调试springboot项目代码
    【深度学习实验】网络优化与正则化(七):超参数优化方法——网格搜索、随机搜索、贝叶斯优化、动态资源分配、神经架构搜索
    2022杭电多校(四)
    一些常用的兼容性测试方法和技巧
    基于imx6ul下调试tlv320aic3x声卡
  • 原文地址:https://blog.csdn.net/Y_Prodigal/article/details/127422679
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号