首页 技术 正文
技术 2022年11月12日
0 收藏 640 点赞 4,379 浏览 1860 个字

实现LNMP

环境:

linux系统机器
A:一台N:nginx,ip:192.168.213.251
B:一台P:php-fpm,php-mysql ,ip:192.168.213.253
C:一台M:mysql or mariadb,ip:192.168.213.254
连接方式:
A <------------> B <-----------> C
关闭防火墙
disable掉selinux

1.在A上安装和配置nginx

yum install nginx
cd /etc/nginx
cp nginx.conf nginx.conf.bak
vim nginx.conf
在server中添加
index index.php ;
location ~* \.php$ {
fastcgi_pass 192.168.213.254:9000;
fastcgi_param SCRIPT_FILENAME /var/www/html/php$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/(status|ping)$ {
fastcgi_pass 192.168.213.254:9000;
fastcgi_param SCRIPT_FILENAME /var/www/html/php$fastcgi_script_name;
include fastcgi_params;
}
nginx -t
systemctl start nginx

2.在B上安装和配置php-fpm,php-myql

yum install php-fpm php-myql
vim /etc/php-fpm.d/www.conf
listen=9000
listen.allowed_clients = 127.0.0.1,192.168.213.251
pm.status_path = /status #用于查看php-fpm状态
ping.path = /ping
ping.response = pong

3.在C上安装和配置mysql 数据库

yum install mysql mysql-server mysql-libs
chkconfig mysqld on
chkconfig --list mysqld
service mysqld start
service mysqld status
/usr/bin/mysql_secure_installation #根据需求进行配置
mysql -uroot -pxm1234
mysql>create user "shenxm"@'%' identified by 'xm1234';

4.测试

在B上找个目录,存放数据。
cd /var/www/html/php
vim index.php
<?php
echo date("Y/m/d h:i:s");
$mysqli=new mysqli("192.168.213.253","shenxm","xm1234");
if(mysqli_connect_errno()){
echo "not ok!";
$mysqli=null;
exit;
}
echo "ok.o....kkkk!!!";
$mysqli->close();
phpinfo();
?>
在浏览器上
http://192.168.213.251/index.php #会有是否ok的显示
http://192.168.213.251/ping #会显示pong的恢复
http://192.168.213.251/status #会有状态信息显示

5.实现fastcgi缓存

在A上
cd /etc/nginx
vim nginx.conf
在http中添加:
fastcgi_cache_path /var/cache/nginx/fcgi_cache levels=1:2:1 keys_zone=fcgicache:20m inactive=120s;
在server中location ~* \.php$中补充:
fastcgi_cache fcgicache;
fastcgi_cache_key $request_uri;
fastcgi_cache_valid 200 302 10m;
fastcgi_cache_valid 301 1h;
fastcgi_cache_valid any 1m;
测试:
ab -c 100 -n 2000 http://192.168.213.251/index.php
可以把fastcgi_cache 关掉在测试下
修改配置文件nginx.conf ,把“fastcgi_cache fcgicache;”改为“fastcgi_cache off;”,然后在测试。
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,087
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,562
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,821
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905