LNMT与nginx动静分离

目录

概述

部署2个tomcat     修改第二个tomcat主配置文件的所有端口号

部署Mariadb

部署nginx

反向代理负载均衡

加权轮询

动静分离


概述:
    所谓的LNMT架构指的就是Linux操作系统上部署Nginx web服务器、MySQL数据库服务器、Tomcat中间件服务器。
        L:linux
        N:nginx
        M:mysql
        T: tomcat
        A:apache
        P: PHP

部署2个tomcat     修改第二个tomcat主配置文件的所有端口号

[root@localhost local] cp -r tomcat tomcat1   #再配置一个tomcat1
[root@localhost tomcat1] vim conf/server.xml     #修改配置文件所有端口
[root@localhost bin] ./startup.sh    #启动

[root@localhost bin] netstat -anptl |grep java
tcp6       0      0 127.0.0.1:8005          :::*                    LISTEN      4548/java           
tcp6       0      0 127.0.0.1:8006          :::*                    LISTEN      6176/java           
tcp6       0      0 :::8009                 :::*                    LISTEN      4548/java           
tcp6       0      0 :::8010                 :::*                    LISTEN      6176/java           
tcp6       0      0 :::8080                 :::*                    LISTEN      4548/java           
tcp6       0      0 :::8081                 :::*                    LISTEN      6176/java    
#俩个 tomcat都启动了

部署Mariadb

[root@localhost ~] yum -y install mariadb-server

部署nginx

[root@localhost yum.repos.d] ll   #进入/etc/yum.repos.d
总用量 0
drwxr-xr-x. 2 root root 195 5月  12 22:42 bak
[root@localhost yum.repos.d] mv bak/CentOS-Base.repo .
[root@localhost yum.repos.d] ll
总用量 4
drwxr-xr-x. 2 root root  171 5月  30 18:04 bak
-rw-r--r--. 1 root root 1664 10月 23 2020 CentOS-Base.repo  #改为CentOS-Base.repo配置

[root@localhost ~] yum -y install epel-release   #安装 epel-release
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.bfsu.edu.cn

[root@localhost ~] yum -y install nginx   #安装nginx

反向代理负载均衡

[root@localhost ROOT] vim /etc/nginx/nginx.conf  #修改nginx主配置文件


http {
    upstream tomcat{                     #在http内写入
           server 192.168.159.141:8080;
           server 192.168.159.141:8081;
}
 


 server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;

       location / {                               #在server内写入
        root /usr/share/nginx/html;
        proxy_pass http://tomcat;
  }

编写index.html文件,启动服务

[root@localhost tomcat] vim webapps/ROOT/index.html
[root@localhost tomcat] vim ../tomcat1/webapps/ROOT/index.html
[root@localhost bin] systemctl start nginx.service

刷新一下,自动变成 

加权轮询

 

[root@localhost bin] vim /etc/nginx/nginx.conf
http {
     upstream tomcat{
         server 192.168.159.146:8080 weight=1;    #刷新3次,2次是8081端口
         server 192.168.159.146:8081 weight=2;    

动静分离

[root@localhost bin] vim /etc/nginx/nginx.conf
 
 
 location  ~\.jsp$ {      #加入配置文件内容
        proxy_pass http://tomcat;
        proxy_set_header  Host $host;
  }

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

我还能再学点

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

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

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

打赏作者

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

抵扣说明:

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

余额充值