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

news2024/10/7 5:30:59

###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.coloradmin.cn/o/1826648.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于Nios-II实现流水灯

基于Nios-II实现流水灯的主要原理 涉及到FPGA&#xff08;现场可编程门阵列&#xff09;上的嵌入式软核处理器Nios II与LED控制逻辑的结合。以下是详细的实现原理&#xff0c;分点表示并归纳&#xff1a; Nios II软核处理器介绍&#xff1a; Nios II是Altera公司推出的一种应用…

Camtasia2024破解永久激活码注册码分享最新

随着数字时代的到来&#xff0c;视频制作已成为许多人日常生活和工作中不可或缺的一部分。而在众多视频编辑软件中&#xff0c;Camtasia凭借其强大的功能和易用性&#xff0c;赢得了广泛的用户喜爱。近期&#xff0c;Camtasia 2024的破解版本在网络上引起了广泛关注。本文旨在为…

外链建设如何进行?

理解dofollow和nofollow链接&#xff0c;所谓dofollow链接&#xff0c;就是可以传递权重到你的网站的链接&#xff0c;这种链接对你的网站排名非常有帮助&#xff0c;这种链接可以推动你的网站在搜索结果中的位置向上爬&#xff0c;但一个网站全是这种有用的链接&#xff0c;反…

scrapy爬取豆瓣书单存入MongoDB数据库

scrapy爬取豆瓣书单存入MongoDB数据库 一、安装scrapy库二、创建scrapy项目三、创建爬虫四、修改settings,设置UA,开启管道五、使用xpath解析数据六、完善items.py七、在douban.py中导入DoubanshudanItem类八、爬取所有页面数据九、管道中存入数据,保存至csv文件十、将数据写…

解决javadoc一直找不到路径的问题

解决javadoc一直找不到路径的问题 出现以上问题就是我们在下载jdk的时候一些运行程序安装在C:\Program Files\Common Files\Oracle\Java\javapath下&#xff1a; 一开始是没有javadoc.exe文件的&#xff0c;我们只需要从jdk的bin目录下找到复制到这个里面&#xff0c;就可以使用…

玄机平台应急响应—MySQL应急

前言 这个是比较简单的&#xff0c;其实和MySQL没啥太大的关系&#xff0c;没涉及太多MySQL的知识。看一下它的flag要求吧。 flag1 它说黑客写入的shell&#xff0c;那我们就去它的网站目录去看看&#xff0c;果然有一个叫sh.php的文件。 flag1{ccfda79e-7aa1-4275-bc26-a61…

excel中按多列进行匹配并对数量进行累加

公司的生产计划是按订单下发&#xff0c;但不同订单的不同产品中可能有用到相同的配件&#xff0c;按单1对1时&#xff0c;对计算机十分友好&#xff0c;但对于在配件库检料的工人来说就比较麻烦&#xff0c;上百条产品里可能会有多条都是相同的产品&#xff0c;首先考虑的办法…

Android采用Scroller实现底部二楼效果

需求 在移动应用开发中&#xff0c;有时我们希望实现一种特殊的布局效果&#xff0c;即“底部二楼”效果。这个效果类似于在列表底部拖动时出现额外的内容区域&#xff0c;用户可以继续向上拖动查看更多内容。这种效果可以用于展示广告、推荐内容或其他信息。 效果 实现后的…

回答网友的一个Delphi问题

网友想在grid 中 加一个水印&#xff0c;俺就给他写了个例子。先靠效果&#xff1a; 这个例子 包含下面几步&#xff1a; 1、创建背景 dg_bmp:Tbitmap.Create; w: Image1.Picture.Bitmap.width; h: Image1.Picture.Bitmap.height; dg_bmp.width: w*2; dg_bmp.height: …

[渗透测试学习] Runner-HackTheBox

Runner-HackTheBox 信息搜集 nmap扫描端口 nmap -sV -v 10.10.11.13扫描结果如下 PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0) 80/tcp open http nginx 1.18.0 (Ubuntu) 8000…

算法day32

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

基于VSCode和MinGW-w64搭建LVGL模拟开发环境

目录 概述 1 运行环境 1.1 版本信息 1.2 软件安装 1.2.1 下载安装VS Code 1.2.1.1 下载软件 1.2.1.1 安装软件 1.2.2 下载安装MinGW-w64 1.2.2.1 下载软件 1.2.2.2 安装软件 1.2.3 下载安装SDL 1.2.3.1 下载软件 ​1.2.3.2 安装软件 1.2.4 下载安装CMake 1.2.4.…

微服务链路追踪ELK

微服务链路追踪&ELK 链路追踪概述链路追踪sluthzipkinelk日志管理平台 一 链路追踪 1 概述 1.1 为什么需要链路追踪 ​ 微服务架构是一个分布式架构&#xff0c;它按业务划分服务单元&#xff0c;一个分布式系统往往有很多个服务单元。由于服务单元数量众多&#xff0…

紫光展锐5G处理器T750__国产手机芯片5G方案

展锐T750核心板采用6nm EUV制程工艺&#xff0c;CPU架构采用了八核设计&#xff0c;其中包括两个主频为2.0GHz的Arm Cortex-A76性能核心和六个主频为1.8GHz的A55小核。这种组合使得T750具备卓越的处理能力&#xff0c;并能在节能的同时提供出色的性能表现。该核心模块还搭载了M…

Kafka 如何保证消息顺序及其实现示例

Kafka 如何保证消息顺序及其实现示例 Kafka 保证消息顺序的机制主要依赖于分区&#xff08;Partition&#xff09;的概念。在 Kafka 中&#xff0c;消息的顺序保证是以分区为单位的。下面是 Kafka 如何保证消息顺序的详细解释&#xff1a; ⭕分区内消息顺序 顺序写入&#…

基于JSP技术的定西扶贫惠农推介系统

开头语&#xff1a;你好呀&#xff0c;我是计算机学长猫哥&#xff01;如果有相关需求&#xff0c;文末可以找到我的联系方式。 开发语言&#xff1a;JSP 数据库&#xff1a;MySQL 技术&#xff1a;B/S架构、JSP技术 工具&#xff1a;Eclipse、MySQL、Tomcat 系统展示 首…

并查集C++

并查集的原理 并查集&#xff08;Union-Find Set&#xff09;。可以把每个连通分量看成一个集合&#xff0c;该集合包含了连通分量中的所有点。这些点两两连通&#xff08;连通性&#xff09;&#xff0c;而具体的连通方式无关紧要&#xff0c;就好比集合中的元素没有先后顺序之…

AI 客服定制:LangChain集成订单能力

为了提高AI客服的问题解决能力&#xff0c;我们引入了LangChain自定义能力&#xff0c;并集成了订单能力。这使得AI客服可以根据用户提出的问题&#xff0c;自动调用订单接口&#xff0c;获取订单信息&#xff0c;并结合文本知识库内容进行回答。这种能力的应用&#xff0c;使得…

java:spring使用【XXXPostProcessor】添加bean定义,修改bean定义、代理bean

# 项目代码资源&#xff1a; 可能还在审核中&#xff0c;请等待。。。 https://download.csdn.net/download/chenhz2284/89433361 # 项目代码 【pom.xml】 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-start…