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

本文主要是介绍企业化运维(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 programsPATH=$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来作为keyset $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

这篇关于企业化运维(3)_PHP、nginx结合php-fpm、memcache、openresty、goaccess日志可视化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1065185

相关文章

使用Python实现矢量路径的压缩、解压与可视化

《使用Python实现矢量路径的压缩、解压与可视化》在图形设计和Web开发中,矢量路径数据的高效存储与传输至关重要,本文将通过一个Python示例,展示如何将复杂的矢量路径命令序列压缩为JSON格式,... 目录引言核心功能概述1. 路径命令解析2. 路径数据压缩3. 路径数据解压4. 可视化代码实现详解1

Python 交互式可视化的利器Bokeh的使用

《Python交互式可视化的利器Bokeh的使用》Bokeh是一个专注于Web端交互式数据可视化的Python库,本文主要介绍了Python交互式可视化的利器Bokeh的使用,具有一定的参考价值,感... 目录1. Bokeh 简介1.1 为什么选择 Bokeh1.2 安装与环境配置2. Bokeh 基础2

Nginx location匹配模式与规则详解

《Nginxlocation匹配模式与规则详解》:本文主要介绍Nginxlocation匹配模式与规则,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、环境二、匹配模式1. 精准模式2. 前缀模式(不继续匹配正则)3. 前缀模式(继续匹配正则)4. 正则模式(大

Java程序进程起来了但是不打印日志的原因分析

《Java程序进程起来了但是不打印日志的原因分析》:本文主要介绍Java程序进程起来了但是不打印日志的原因分析,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录Java程序进程起来了但是不打印日志的原因1、日志配置问题2、日志文件权限问题3、日志文件路径问题4、程序

springboot上传zip包并解压至服务器nginx目录方式

《springboot上传zip包并解压至服务器nginx目录方式》:本文主要介绍springboot上传zip包并解压至服务器nginx目录方式,具有很好的参考价值,希望对大家有所帮助,如有错误... 目录springboot上传zip包并解压至服务器nginx目录1.首先需要引入zip相关jar包2.然

Java使用SLF4J记录不同级别日志的示例详解

《Java使用SLF4J记录不同级别日志的示例详解》SLF4J是一个简单的日志门面,它允许在运行时选择不同的日志实现,这篇文章主要为大家详细介绍了如何使用SLF4J记录不同级别日志,感兴趣的可以了解下... 目录一、SLF4J简介二、添加依赖三、配置Logback四、记录不同级别的日志五、总结一、SLF4J

如何使用Nginx配置将80端口重定向到443端口

《如何使用Nginx配置将80端口重定向到443端口》这篇文章主要为大家详细介绍了如何将Nginx配置为将HTTP(80端口)请求重定向到HTTPS(443端口),文中的示例代码讲解详细,有需要的小伙... 目录1. 创建或编辑Nginx配置文件2. 配置HTTP重定向到HTTPS3. 配置HTTPS服务器

Python结合PyWebView库打造跨平台桌面应用

《Python结合PyWebView库打造跨平台桌面应用》随着Web技术的发展,将HTML/CSS/JavaScript与Python结合构建桌面应用成为可能,本文将系统讲解如何使用PyWebView... 目录一、技术原理与优势分析1.1 架构原理1.2 核心优势二、开发环境搭建2.1 安装依赖2.2 验

python logging模块详解及其日志定时清理方式

《pythonlogging模块详解及其日志定时清理方式》:本文主要介绍pythonlogging模块详解及其日志定时清理方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地... 目录python logging模块及日志定时清理1.创建logger对象2.logging.basicCo

Qt spdlog日志模块的使用详解

《Qtspdlog日志模块的使用详解》在Qt应用程序开发中,良好的日志系统至关重要,本文将介绍如何使用spdlog1.5.0创建满足以下要求的日志系统,感兴趣的朋友一起看看吧... 目录版本摘要例子logmanager.cpp文件main.cpp文件版本spdlog版本:1.5.0采用1.5.0版本主要