企业化运维(3)_PHP、nginx结合php-fpm、memcache、openresty、goaccess日志可视化

###1.PHP源码编译###

解压PHP压缩包,切入PHP目录,进行configure-->make-->make installd三部曲

[root@server1 ~]# yum install -y bzip2 systemd-devel libxml2-devel sqlite-devel libpng-devel libcurl-devel   ##依赖性
[root@server1 ~]# yum install -y oniguruma-6.8.2-1.el7.x86_64.rpm oniguruma-devel-6.8.2-1.el7.x86_64.rpm   ##依赖性

解压php压缩包
[root@server1 ~]# tar xf php-7.4.12.tar.bz2
[root@server1 ~]# cd php-7.4.12/

三部曲
[root@server1 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 --disable-debug --enable-sockets --enable-soap --enable-inline-optimization --enable-xml --enable-ftp --enable-gd --enable-exif --enable-mbstring --enable-bcmath --with-fpm-systemd

[root@server1 php-7.4.12]# make
[root@server1 php-7.4.12]# make install

###2.PHP初始化配置###

(1)php-fpm.conf

[root@server1 php-7.4.12]# cd /usr/local/php/etc
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# vim php-fpm.conf
去掉注释
pid = run/php-fpm.pid

(2)fpm.conf

[root@server1 etc]# cd php-fpm.d/
[root@server1 php-fpm.d]# cp www.conf.default www.conf

(3)php.ini

[root@server1 ~]# cd php-7.4.12/
[root@server1 php-7.4.12]# cp php.ini-production /usr/local/php/etc/php.ini
[root@server1 php-7.4.12]# vim /usr/local/php/etc/php.ini
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Aisa/Shanghai			#修改时区

(4)php-fpm.service

[root@server1 php-7.4.12]# cd sapi/fpm
[root@server1 fpm]# cp php-fpm.service /usr/lib/systemd/system

[root@server1 fpm]# vim /usr/lib/systemd/system/php-fpm.service  ##php-fpm启动文件
注释此行
#ProtectSystem=full

(5)启动服务

[root@server1 fpm]# systemctl  daemon-reload
[root@server1 fpm]# systemctl start php-fpm.service
[root@server1 fpm]# netstat -antlp|grep :9000
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      24709/php-fpm: mast
[root@server1 fpm]# systemctl enable php-fpm

###3.nginx结合php-fpm###

(1)修改nginx配置文件

切入配置目录,编辑配置文件,注释之前的设定,取消php的注释。

[root@server1 sapi]# cd /usr/local/nginx/conf/
[root@server1 conf]# vim nginx.conf
...
location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }

编写一个php发布文件,重启服务

[root@server1 conf]# vim /usr/local/nginx/html/index.php
<?php
phpinfo()
?>

测试: 
浏览器中访问
http://192.168.56.11/index.php

(2)添加php环境变量

[root@server1 ~]# vim .bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/php/bin   ##添加路径

export PATH

[root@server1 ~]# source .bash_profile

[root@server1 ~]# which php
/usr/local/php/bin/php

###4.php动态扩展模块###

(1)软件安装

解压软件包,切入目录,执行phpize,提醒缺少依赖。phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块。

[root@server1 ~]# tar xf memcache-4.0.5.2.tgz
[root@server1 ~]# cd memcache-4.0.5.2/
[root@server1 memcache-4.0.5.2]# phpize   ##phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,提醒缺少依赖autoconf
[root@server1 memcache-4.0.5.2]# yum install -y autoconf

安装依赖,重新执行phpize。

[root@server1 memcache-4.0.5.2]# phpize  ##扩展成功
Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902

对memcache进行源码编译,confugure--make--make install三步曲。

[root@server1 memcache-4.0.5.2]# ./configure
[root@server1 memcache-4.0.5.2]# make
[root@server1 memcache-4.0.5.2]# make install

(2)添加memcache功能模块

编辑php.ini,然后重启服务,执行php -m可以看到memcache。

[root@server1 memcache-4.0.5.2]# php -m  |grep memcache

[root@server1 memcache-4.0.5.2]# cd /usr/local/php/etc
[root@server1 etc]# vim php.ini
extension=memcache		#添加memcache模块

[root@server1 etc]# systemctl  reload php-fpm
[root@server1 etc]# php -m |grep memcache
memcache

安装memcached,并开启服务,查看端口。

切入memcache目录,拷贝文件并编译,最后重启服务。

[root@server1 memcache-4.0.5.2]# cp example.php memcache.php /usr/local/nginx/html/

[root@server1 html]# yum install -y memcached
[root@server1 html]# systemctl enable --now memcached
[root@server1 html]# netstat -antlp|grep :11211
tcp        0      0 0.0.0.0:11211           0.0.0.0:*               LISTEN      27984/memcached
tcp6       0      0 :::11211                :::*                    LISTEN      27984/memcached


[root@server1 memcache-4.0.5.2]# cd /usr/local/nginx/html/
[root@server1 html]# vim memcache.php

$VERSION='$Id$';

define('ADMIN_USERNAME','admin');       // Admin Username
define('ADMIN_PASSWORD','westos');      // Admin Password
define('DATE_FORMAT','Y/m/d H:i:s');
define('GRAPH_SIZE',200);
define('MAX_ITEM_DUMP',50);

$MEMCACHE_SERVERS[] = 'localhost:11211'; // add more as an array
#$MEMCACHE_SERVERS[] = 'mymemcache-server2:11211'; // add more as an array

(3)测试

访问http://192.168.76.11/example.php,多刷新几次页面

查看缓存命中状态

http://192.168.56.11/memcache.php

在测试端用压力测试工具观察有没有memcache缓存加速的区别

###5.配置php加载模块openresty,构建nginx高速缓存###

基于openresty(构建高效透明的缓存机制) 访问,能将缓存放在nginx中,速度更快。
使用memc-nginx和srcache-nginx模块构建高效透明的缓存机制。
如果需要做到高速缓存,nginx可以跳过php直接向memcache存储,但是只能做静态存储 ,如果需要动态存储,还是要调用php,因此两种缓存策略时同时在进行的。

 (1)安装软件

首先停止nginx服务,避免端口冲突
[root@server1 ~]# nginx  -s stop

[root@server1 ~]# tar xf openresty-1.21.4.1.tar.gz
[root@server1 ~]# cd openresty-1.21.4.1/

三部曲
[root@server1 openresty-1.21.4.1]# ./configure --prefix=/usr/local/openresty --with-http_ssl_module --with-http_stub_status_module
[root@server1 openresty-1.21.4.1]# make
[root@server1 openresty-1.21.4.1]# make install

(2)软件配置 

[root@server1 openresty-1.21.4.1]# cd /usr/local/openresty/nginx
[root@server1 nginx]# ls
conf  html  logs  sbin
[root@server1 nginx]# cd conf/
[root@server1 conf]# cp /usr/local/nginx/conf/nginx.conf .
[root@server1 conf]# cp /usr/local/nginx/conf/cert.pem .
检测语法
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx  -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
启动openresty
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx

测试
访问:http://192.168.76.11/

(3)nginx配置高速缓存

拷贝测试页面

[root@server1 html]# pwd
/usr/local/openresty/nginx/html
[root@server1 html]# cp /usr/local/nginx/html/index.php .
[root@server1 html]# cp /usr/local/nginx/html/example.php .

修改openresty的nginx配置文件

[root@server1 conf]# pwd
/usr/local/openresty/nginx/conf

[root@server1 conf]# vim nginx.conf
upstream memcache {
        server 127.0.0.1:11211;
        keepalive 512;
        }                 ##加上新的负载均衡器,告诉nginx你的memcache缓存在什么位置

...

location /memc {
        internal;                      ##表示只接受内部访问
        memc_connect_timeout 100ms;
        memc_send_timeout 100ms;
        memc_read_timeout 100ms;
        set $memc_key $query_string;   ##表示内部的$query_string来作为key
        set $memc_exptime 300;         ##表示缓存失效时间
        memc_pass memcache;
        }

location ~ \.php$ {
            set $key $uri$args;
            srcache_fetch GET /memc $key;
            srcache_store PUT /memc $key;

            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi.conf;
        }

检测语法并重启 

[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx  -t
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx  -s reload

 (4)测试

在测试端用压力测试工具观察用openresty构建nginx高速缓存的效果

###6.goaccess日志可视化###

(1)软件安装

做实验前关闭openresty服务,切回nginx
安装依赖性
[root@server1 ~]# yum install -y GeoIP-devel-1.5.0-13.el7.x86_64.rpm
[root@server1 goaccess-1.4]# yum install ncurses-devel

[root@server1 ~]# tar xf goaccess-1.4.tar.gz
[root@server1 ~]# cd goaccess-1.4/

三部曲
[root@server1 goaccess-1.4]# ./configure --enable-utf8 --enable-geoip=legacy
[root@server1 goaccess-1.4]# make
[root@server1 goaccess-1.4]# make install

(2)可视化日志监控

[root@server1 ~]# goaccess /usr/local/nginx/logs/access.log -o /usr/local/nginx/html/report.html --log-format=COMBINED --real-time-html &

 (3)测试

浏览器访问:
http://192.168.76.11/report.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/712149.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

python如何对list求和

如何在Python中对多个list的对应元素求和&#xff0c;前提是每个list的长度一样。比如&#xff1a;a[1&#xff0c;2&#xff0c;3]&#xff0c;b[2&#xff0c;3&#xff0c;4]&#xff0c;c[3&#xff0c;4&#xff0c;5]&#xff0c;对a&#xff0c;b&#xff0c;c的对应元素…

Maven常用命令介绍(Ⅰ)

基本命令 Maven生命周期 Maven的生命周期是对所有的构建过程进行抽象和统一。Maven的生命周期是抽象的&#xff0c;这意味着生命周期本身不做任何实际的工作&#xff0c;生命周期只是定义了一系列的阶段&#xff0c;并确定这些阶段的执行顺序。而在执行这些阶段时&#xff0c;…

父亲节马上到了-和我一起用Python写父亲节的祝福吧

前言 让我们一起用Python写一段父亲节的祝福吧 &#x1f4dd;个人主页→数据挖掘博主ZTLJQ的主页 个人推荐python学习系列&#xff1a; ☄️爬虫JS逆向系列专栏 - 爬虫逆向教学 ☄️python系列专栏 - 从零开始学python 话不多说先上代码 import tkinter as tk from doctest imp…

MEMS:Lecture 16 Gyros

陀螺仪原理 A classic spinning gyroscope measures the rotation rate by utilizing the conservation of angular momentum. 经典旋转陀螺仪通过利用角动量守恒来测量旋转速率。 Coriolis Effect and Coriolis Force 科里奥利效应是一种出现在旋转参考系中的现象。它描述了…

显示类控件——Label

&#x1f40c;博主主页&#xff1a;&#x1f40c;​倔强的大蜗牛&#x1f40c;​ &#x1f4da;专栏分类&#xff1a;QT ❤️感谢大家点赞&#x1f44d;收藏⭐评论✍️ 文章目录 一、Label介绍属性代码示例: 显示不同格式的文本代码示例: 显示图片代码示例: 文本对齐, 自动换行…

PFA 反应罐内衬特氟龙 润滑绝缘行业加工 匠心工艺

PFA反应罐别名也叫反应瓶&#xff0c;储样罐&#xff0c;清洗罐等。可作为样品前处理实验中消解样品和中低压溶样的反应容器&#xff0c;广泛应用于半导体分析、新材料、新能源、同位素分析等。 PFA反应罐规格参考&#xff1a;250ml、300ml、350ml、500ml、1L等。 产品特点&…

大众点评js逆向过程(未完)

1、这里mtgsig已经被拼到url中 2、进入后mtgsig已经计算完&#xff0c; ir he(this[b(4326)], !1), 就是加密函数 32 次 796 1143 ->508 -> 754 -> 1151 160 注意IC这个数组 控制流平坦化进行AST 解析 AST网址

Swift开发——循环执行方式

本文将介绍 Swift 语言的循环执行方式 01、循环执行方式 在Swift语言中,主要有两种循环执行控制方式: for-in结构和while结构。while结构又细分为当型while结构和直到型while结构,后者称为repeat-while结构。下面首先介绍for-in结构。 循环控制方式for-in结构可用于区间中的…

2024全新仿麻豆视频苹果cms源码v10影视模板

下载地址&#xff1a;2024全新仿麻豆视频苹果cms源码v10影视模板 高端大气的设计&#xff0c;适合做电影、连续剧、综艺、动漫、微电影、纪录片、海外剧等视频网站

【秋招突围】2024届秋招笔试-小红书笔试题-第一套-三语言题解(Java/Cpp/Python)

&#x1f36d; 大家好这里是清隆学长 &#xff0c;一枚热爱算法的程序员 ✨ 本系计划跟新各公司春秋招的笔试题 &#x1f4bb; ACM银牌&#x1f948;| 多次AK大厂笔试 &#xff5c; 编程一对一辅导 &#x1f44f; 感谢大家的订阅➕ 和 喜欢&#x1f497; &#x1f4e7; 清隆这边…

Nginx实战:故障处理_后端服务正常,nginx偶发502(Bad Gateway)

一、故障场景 用户访问服务偶发报错【502 Bad Gateway】&#xff0c;但是服务后端正常运行。架构如下&#xff1a; #mermaid-svg-4dDszusKEuPgIPlt {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-4dDszusKEuPgIPlt…

axios打通fastapi和vue,实现前后端分类项目开发

axios axios是一个前后端交互的工具&#xff0c;负责在前端代码&#xff0c;调用后端接口&#xff0c;将后端的数据请求到本地以后进行解析&#xff0c;然后传递给前端进行处理。 比如&#xff0c;我们用fastapi写了一个接口&#xff0c;这个接口返回了一条信息&#xff1a; …

攻防世界-fakebook题目__详解

1.打开题目先用dirsearch工具扫描一波&#xff0c;扫出来了robots.php目录&#xff0c;然后访问robots.txt 目录&#xff0c;发现了有一个备份文件 &#xff0c;访问备份文件&#xff0c;下载内容 文件的大致内容如下 里面有一个curl_exec这个函数容易造成ssrf攻击的漏洞 我…

监控神器vnStat初探

文章目录 一、概述二、官方docker部署1. vnStat守护进程和HTTP服务器在同一容器中运行2. 双容器运行&#xff0c;vnstat容器收集数据&#xff0c;vnstati容器提供web服务 三、修改后的编排文件四、运行结果五、停止监控不感兴趣的网卡 一、概述 vnStat是一款网络流量监测工具&…

微服务SpringCloud ES分布式全文搜索引擎简介 下载安装及简单操作入门

Elasticsearch ES简介 分布式全文搜索引擎 我们天天在用ES 搜索的时候 要与多个信息进行匹配查找 然后返回给用户 首先 ES会将数据库中的信息 先进行一个拆分 这个叫做分词 是按照词语关键词拆的 然后就能进行搜索的时候匹配对应的id 每一个关键字对应若干id 每一个…

算法day32

第一题 207. 课程表 步骤一&#xff1a; 通过下图的课程数组,首先画出DAG图&#xff08;有向无环图&#xff09; 步骤二&#xff1a; 其次我们按照DAG图&#xff0c;来构建该图的拓扑排序&#xff0c;等有效的点都按照规则排完序后&#xff0c;观察是否有剩下的点的入度不为0&…

【靶场搭建】-01- 在kali上搭建DVWA靶机

1.DVWA靶机 DVWA&#xff08;Damn Vulnerable Web Application&#xff09;是使用PHPMysql编写的web安全测试框架&#xff0c;主要用于安全人员在一个合法的环境中测试技能和工具。 2.下载DVWA 从GitHub上将DVWA的源码clone到kali上 git clone https://github.com/digininj…

远程问诊软件哪款好?选欣九康诊疗系统

近几年国家相继推出了支持发展“互联网医疗”的政策&#xff0c;如今随着相关政策的不断落实推进&#xff0c;市场上涌现出了一大批在线咨询、电子处方和远程问诊的医疗平台&#xff0c;而在面对种类如此繁多的医疗平台究竟选择哪款更好便成了医疗机构非常头疼的事情&#xff0…

Mac平台上公认的最好的下载工具Folx Pro 5 for Mac激活码

Folx是什么 Folx Pro 5 for Mac是Mac平台上公认的最好的下载工具&#xff0c;功能可以与迅雷相媲美。 Folx是一款老牌下载神器&#xff0c;可通过URL链接和种子文件下载文件&#xff0c;同时提供了便捷的下载管理和灵活的应用设置&#xff0c;Folx可以对下载的资源进行分类&a…

解决Qt的multimedia库在clion中依赖库补全的问题

解决Qt的multimedia库在clion中使用报错的问题 在clion中&#xff0c;使用Qt的multimedia库时会报如下错误&#xff1a; defaultServiceProvider::requestService(): no service found for - "org.qt-project.qt.mediaplayer" 我猜测出现这个错误的原因很可能是因为…