lamp架构1

A、nginx重定向
进入nginx主配置目录
问题1:防止域名恶意解析到服务器IP

主机:
curl 172.25.254.1
将域名解析到这个IP上,就能够解析,解决办法锁定域名,不能访问IP
server {
    listen 80
    server_name _/localhost;#/表示或
    return 500;
    }

500一般指的是服务端的问题
pcre
也可进行以下重定向操作

server {
   listen 80;
   server_name _;
   rewrite ^(.*) http://www.westos.org permanent;
   }
主机上
curl 172.25.254.1 -I
curl www.westos.org -I

proxy_pass :nginx反向代理命令
在这里插入图片描述
在这里插入图片描述
$1匹配/后面的任意内容。301永久重定向
302暂时
在这里插入图片描述

server1
mkdir /bbs
cd /bbs/
echo bbs.westos.org > index.html
主机
vim /etc/hosts
172.25.254.1 www.westos.org bbs.westos.org
curl bbs.westo.org

使curl www.westos.org/bbs–>bbs.westos.org

在这里插入图片描述
bbs.westos.org重定向到www.westos.org
在这里插入图片描述
在这里插入图片描述

server1
cd /usr/local/nginx/html/
cp -r /bbs/ .
ls
cd bbs/
ls
pwd
主机
curl -I www.westos.org
curl -I bbs.westos.org
curl -I bbs.westos.org/index.html

B、防盗链

server2
vim /var/www/html/index.html

在这里插入图片描述

主机
vim /etc/hosts
172.25.254.2 server2 daolian.westos.org
server1
打开配置文件

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
C、PHP源码编译
mysql
lamp=linux apache/nginx mysql/pgsql php/java/python/golang/C/C++

下载php-7.4.12.tar.gz
从www.php.net php 7.4.27

server1
rpm -qa |grep php #确定系统上没有其他的php
yum list php #不要去安装系统上原有的php版本
tar jxf php-7.4.12.tar.gz
yum install bzip2 -y
cd php-7.4.12/
./configure --prefix=/usr/local/php (路径自己定义) --with-config-file-path=/usr/local/php/etc (配置目录路径) --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-iconv --with-mhash --with-zlib --with-openssl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disble-debug --enable-sockets --enable-soap --enable-inline-optimization --enable-xml --enable-ftp --enable-gd --enable-exif --enable-mbstring --enable-bcmath --with-fpm-systemd
#根据实际开发业务需求定的。
yum search libsystemd
yum install systemd-devel.x86_64 -y
yum install libxml2-devel.x86_64 -y
yum install sqlite-devel.x86_64 -y
yum install libcurl-devel.x86_64 -y
yum install libpng-devel.x86_64 -y
在阿里云上找oniguruma mirror.aliyun.com
oniguruma-devel-6.8.2-1.el7.x86_64.rpm
yum install oniguruma-devel-6.8.2-1.el7.x86_64.rpm -y
cd php-7.4.12/
./configure --prefix=/usr/local/php (路径自己定义) --with-config-file-path=/usr/local/php/etc (配置目录路径) --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-curl --with-iconv --with-mhash --with-zlib --with-openssl --enable-mysqlnd --with-mysqli --with-pdo-mysql --disble-debug --enable-sockets --enable-soap --enable-inline-optimization --enable-xml --enable-ftp --enable-gd --enable-exif --enable-mbstring --enable-bcmath --with-fpm-systemd
make && make install
cd /usr/local/php/bin/
ls
pwd
vim ~/.bash_profile
source ~/.bash_profile
which php

在这里插入图片描述

cd /usr/local/php/etc/
ls
cp php-fpm.conf.default php-fpm.conf
#vim php-fpm.conf
cd php-fpm.d/
ls
cp www.conf.default www.conf
#vim www.conf
cd ..
ls
cd
ls
cd php-7.4.12/
cp php.ini-production /usr/local/php/etc/php.ini
cd /usr/local/php/etc/
ls
vim php.ini

在这里插入图片描述

cd php-7.4.12/
ls
cd sapi/
pwd
ls
cd fpm/
ls
cp php-fpm.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start php-fpm #实验报错
vim /usr/lib/systemd/system/php-fpm.service

在这里插入图片描述

systemctl daemon-reload
systemctl start php-fpm
netstat -antlp#出现9000端口,说明配置没有问题
cd /usr/local/nginx/condf/
ls
vim niginx.conf

在这里插入图片描述
在这里插入图片描述

nginx -s reload
ls
cd ..
cd html/
vim index.php

在这里插入图片描述
打开浏览器 172.25.254.1/index.php

php -m #查看Php当前模块

添加php模块
php加缓存

tar zxf memcache-4.0.5.2.tgz
ls
cd memcache-4.0.5.2/
ls
less README
yum install autoconf -y 
phpize
ls
./configure --enable-memcache
ll  makefile
make
make install
php -m | grep memcache #查找指定模块
cd /usr/local/php/etc/
ls
vim php.ini

在这里插入图片描述

systemctl reload php-fpm  #平滑重载
netstat -antlp
php -m|grep memcache
cd memcache-4.0.5.2/
cp example.php memcache.php /usr/local/nginx/html/
cd /usr/local/nginx/html/
ls
vim memcache.php

在这里插入图片描述

yum install memcached -y
systemctl start memcached
netatat -antlp

浏览器 172.25.254.1/memcache.php

vim example.php #不用动

浏览器 172.25.254.1/example.php

主机
ab -c10 -n1000 http://172.25.25.1/index.php
ab -c10 -n1000 http://172.25.25.1/example.php

client -> nginx:80 *.php -> phpfpm:9000 -> nginx ->client 传统缓存策略
nginx将php交给phpfpm处理之后,nginx就管不了了。

高速缓存策略
在这里插入图片描述
openresty.org/cn/下载openresty-1.19.9.1.tar.gz
srcache模块可以控制多种缓存类型

server1
tar zxf openresty-1.19.9.1.tar.gz
cd openresty-1.19.9.1/
ls
./configure 
make 
make install 
nginx -s stop
ps ax | grep nginx
ls
cd /usr/local/openresty/
ls
cd nginx/
ls
cd conf/
vim nginx.conf

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

vim /usr/local.nginx/conf/nginx.conf #这个文件的内容与上面的文件内容一致
/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx
curl localhost
cd ..
pwd
cd html/
ls
cp /usr/local/nginx/html/example.php .
cp /usr/local/nginx/html/memcache.php .
cd ..
cd conf/
cd /usr/local/openresty/nginx/conf
主机
ab -c10 -n5000 http://172.25.25.1/example.php
free -m #查看内存量
vim nginx.conf 

在这里插入图片描述

vim /etc/sysconfig/memcached #对CPU没有太大效果,主要是内存

当缓存失效的时候,会把你的后端服务器的流量穿透到你的后端了。
在这里插入图片描述
在这里插入图片描述

/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx -s reload
cd ..
cd html/
cp /usr/local/nginx/html/index.php .
本机
ab -c10 -n5000 http://172.25.25.1/index.php

tomcat结合memcache

/usr/local/openresty/nginx/sbin/nginx -s stop
nginx -t
nginx
cd 
cd ..
cd /usr/local/
server2
systemctl start httpd
systemctl stop httpd
下载apache-tomat-7.0.37.tar.gz
下载jdk-8u121-linux-x64.rpm
rpm -ivh jdk-8u121-linux-x64.rpm
tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
cd /usr/local/
ls
ln -s apache-tomcat-7.0.37/ tomcat
cd tomcat/
ls
bin/startup.sh
netstat -antlp
scp jdk-8u121-linux-x64.rpm apache-tomcat-7.0.37.tar.gz server3
server3
systemctl start httpd
systemctl stop httpd
rpm -ivh jdk-8u121-linux-x64.rpm
tar zxf apache-tomcat-7.0.37.tar.gz -C /usr/local/
cd /usr/local/
ls
ln -s apache-tomcat-7.0.37/ tomcat
cd tomcat/
bin/startup.sh
netstat -antlp
server1
cd /usr/local/nginx/
ls
conf/
ls
vim nginx.conf

在这里插入图片描述
在这里插入图片描述

nginx -t
nginx -s reload

网站上访问:172.25.254.2:8080 172.25.254.3:8080
网站上访问:172.25.254.2/index.jsp

server2
cd /usr/local/
cd tomat/
ls
cd webapps/
cd ROOT/
pwd
scp test.jsp server3:/usr/local/tomat/webapps/ROOT/

nginx对后端有健康检测

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值