Apache和LNMP架构做动静分离
admin
2023-03-29 01:22:00
0

Apache和LNMP架构做动静分离

Apache和LNMP架构做动静分离

nginx的静态处理能力很强,动态处理能力不足,所以要把动态的页面交给Apache,实现动静分离。

先安装apache服务

[root@localhost ~]# yum install httpd httpd-devel -y ##安装apacher软件包

[root@localhost ~]# systemctl start httpd.service  ##开启服务

[root@localhost ~]# firewall-cmd --permanent --zone=public  --add-service=http  ##永久允许http服务
success

[root@localhost ~]# firewall-cmd --permanent --zone=public  --add-service=https  ##永久允许https服务
success

[root@localhost ~]# firewall-cmd --reload  ##重新加载防火墙
success

去客户机测试一下能不能访问apache网站

Apache和LNMP架构做动静分离

安装LNMP架构(简易安装)

MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB。 MariaDB由MySQL的创始人Michael Widenius(英语:Michael Widenius)主导开发,他早前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。MariaDB名称来自Michael Widenius的女儿Maria的名字。

安装数据库

yum install mariadb mariadb-server mariadb-libs mariadb-devel -y  #安装数据库组件
[root@localhost ~]# systemctl start  mariadb 
[root@localhost ~]# netstat -natap | grep 3306
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      15154/mysqld        

配置数据库

[root@localhost ~]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):  ##按回车

Set root password? [Y/n] y   ##是否设置密码
New password:   #输入你的密码
Re-enter new password: 

Remove anonymous users? [Y/n] y  ##是否删除匿名用户,不删

Disallow root login remotely? [Y/n] n  ##是否让root用户远程登录

Remove test database and access to it? [Y/n] n  ##是否删除测试数据库

Reload privilege tables now? [Y/n] y  ##是否加载里面的属性列表

安装PHP

yum -y install php

##建立php和mysql关联
yum install php-mysql -y

##安装php插件
yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

cd /var/www/html

vim index.php  ##写上PHP网页



[root@localhost html]# systemctl restart httpd.service 

用客户机去测试一下能不能访问到PHP

Apache和LNMP架构做动静分离

再开一台Linux作为Nginx处理静态请求

[root@localhost ~]# yum install pcre-devel zlib-devel gcc gcc-c++ -y  ##安装环境包

[root@localhost ~]# useradd -M -s /sbin/nologin nginx ##创建程序性用户

[root@localhost ~]# mkdir /chen ##创建挂载点
[root@localhost ~]# mount.cifs //192.168.100.23/LNMP /chen ##挂载
Password for root@//192.168.100.23/LNMP:  

[root@localhost chen]# tar zxvf nginx-1.12.2.tar.gz -C /opt/  ##解压

[root@localhost chen]# cd /opt/
[root@localhost opt]# ls
nginx-1.12.2  rh
[root@localhost opt]# cd nginx-1.12.2/
[root@localhost nginx-1.12.2]# ls
auto     CHANGES.ru  configure  html     man     src
CHANGES  conf        contrib    LICENSE  README

./configure \  ##安装组件
--prefix=/usr/local/nginx \  ##指定路径
--user=nginx \  ##指定用户
--group=nginx \  ##指定组
--with-http_stub_status_module  ##状态统计模块

[root@localhost nginx-1.12.2]# make && make install  ##编译

[root@localhost nginx-1.12.2]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/  ##做软连接
[root@localhost nginx-1.12.2]# nginx -t  ##检查语法
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

写nginx脚本放在系统启动脚本中方便service管理器管理

[root@localhost nginx-1.12.2]# cd /etc/init.d/

[root@localhost init.d]# vim nginx  

#!/bin/bash
#chkconfig: - 99 20  #注释信息
#description: Nginx Service Control Script
PROG="/usr/local/nginx/sbin/nginx"  #这个变量,指向我的命令文件
PIDF="/usr/local/nginx/logs/nginx.pid"  #这个变量,指向nginx的进程号
case "$1" in
    start)
        $PROG                                              
        ;;
    stop)
        kill -s QUIT $(cat $PIDF) 
        ;;
    restart)                                                  
        $0 stop
        $0 start
        ;;
    reload)                                                  
        kill -s HUP $(cat $PIDF)
        ;;
    *)                                                           
                echo "Usage: $0 {start|stop|restart|reload}"
                exit 1
esac
exit 0

开启服务,并测试网页是否生效

[root@localhost init.d]# chmod +x nginx 
[root@localhost init.d]# chkconfig --add nginx 
[root@localhost init.d]# service nginx start 
[root@localhost init.d]# netstat -ntap | grep nginx 
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      17544/nginx: master 

[root@localhost init.d]# systemctl stop firewalld.service
[root@localhost init.d]# setenforce 0
[root@localhost init.d]# yum install elinks -y

[root@localhost init.d]# elinks http://192.168.136.162/ ##测试网站有没有生效

Apache和LNMP架构做动静分离

在nginx配置文件中把动态的请求给Apache处理,174这台服务器

[root@localhost init.d]# vim /usr/local/nginx/conf/nginx.conf
 59         location ~ \.php$ {
 60             proxy_pass   http://192.168.136.174;  ##在sever这个区域,修改地址,把动态的请求转给174处理
 61         }   

[root@localhost init.d]# service nginx stop
[root@localhost init.d]# service nginx start

去客户机测试一下动态的请求和静态的请求,输入192.168.136.174/index.php

Apache和LNMP架构做动静分离

输入192.168.136.174/index.html

Apache和LNMP架构做动静分离

谢谢收看

相关内容

热门资讯

特朗普下令不打了,美国的“余粮... 可以说戛然而止,快得让很多人都无法适应。前两周,每一天美国都要打击伊朗一通。就在7月24日白宫会议前...
穆杰塔巴最新表态:支持黎真主党 △伊朗最高领袖穆杰塔巴·哈梅内伊(资料图)当地时间7月26日晚,伊朗最高领袖穆杰塔巴·哈梅内伊对黎巴...
美军瘫痪一艘驶向伊朗的油轮,特... 美国总统特朗普虽下令暂停打击伊朗,但美军仍在执行对霍尔木兹海峡的封锁任务。针对美军瘫痪一艘驶向伊朗油...
“小牌大耍”的底气到底是哪里来... 澎湃首席评论员 李平这两天,“艺人李权哲乘高铁占座事件”在网上引发热议,该艺人参加的活动主办方曾发布...
越南籍船舶南海遇险沉没,中方已... 据凤凰卫视报道,一艘越南船舶7月24日夜间在越南庆和以东220海里附近遇险沉没,船上共62名越南籍人...
李权哲占座、蒙面、装死:娱乐圈... 你买了一张高铁一等座的票,找到自己的位置,18A。有人坐着。你拿出手机看了眼购票记录——没错,18A...
杭州景区咖啡店闯入1条幼蛇,仅... 夏天气温高、湿度大,蛇类活动进入高峰期,千万别被“小蛇无害”的刻板印象骗了!有些幼蛇看着迷你可爱,实...
AI开源公开信签署企业增至50... IT之家 7 月 26 日消息,英伟达、微软、IBM、Meta 等 25 家美国科技企业本周(7 月...
南阳快手短视频代运营企业的服务... 在短视频平台快速发展的背景下,企业通过快手等渠道进行内容运营已成为常见的市场动作。对于希望借助短视频...
普通人该如何跟上科技发展的步伐 这个被称作科技的词汇, 听起来既有宏大之感, 又颇为遥远, 好似仅仅归属于在实验室里专心致志钻研的科...