redis实现mysql的数据缓存

本文介绍了如何在base2(nginx+php)环境中搭建nginx和php服务,然后探讨了在mysql更新后redis无法同步的问题。为解决此问题,文章详细讲解了通过gearman-mysql-udf插件安装及编写mysql触发器,以及在base2上配置gearman worker端,最终测试数据在mysql端更新后能否成功同步到redis。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

环境设定
base2 172.25.78.12 nginx+php
base3 172.25.78.13 redis端
base4 172.25.78.14 mysql端
# 1.在base2(nginx+php)上

配置nginx和php(这里的nginx只是提供了负载均衡,所以版本要求不高)

[root@base2 ~]# killall redis-server
[root@base2 ~]# ls
gearmand-1.1.12-18.el7.x86_64.rpm          
php-fpm-5.4.16-46.el7.x86_64.rpm
libevent-devel-2.0.21-4.el7.x86_64.rpm     
php-mysql-5.4.16-46.el7.x86_64.rpm
libgearman-1.1.12-18.el7.x86_64.rpm        
php-pdo-5.4.16-46.el7.x86_64.rpm
libgearman-devel-1.1.12-18.el7.x86_64.rpm  
php-pecl-gearman-1.1.2-1.el7.x86_64.rpm
libzip-0.10.1-8.el7.x86_64.rpm             
php-pecl-igbinary-1.2.1-1.el7.x86_64.rpm
openssl-1.0.2k-16.el7.x86_64.rpm           
php-pecl-redis-2.2.8-1.el7.x86_64.rpm
openssl-libs-1.0.2k-16.el7.x86_64.rpm      
php-process-5.4.16-46.el7.x86_64.rpm
php-cli-5.4.16-46.el7.x86_64.rpm           
php-xml-5.4.16-46.el7.x86_64.rpm
php-common-5.4.16-46.el7.x86_64.rpm

[root@base2 ~]# yum install -y *.rpm   # 安装php

注:当服务器上有openssl-devel开发包时,会有冲突,所以要先删除
[root@base2 ~]# tar zxf nginx-1.14.2.tar.gz 
[root@base2 ~]# cd nginx-1.14.2
[root@base2 nginx-1.14.2]# vim auto/cc/gcc 
171 # debug
172 #CFLAGS="$CFLAGS -g"
[root@base2 nginx-1.14.2]# vim src/core/nginx.h 
 14 #define NGINX_VER          "nginx/"
[root@base2 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx
[root@base2 nginx-1.14.2]# make && make install
[root@base2 ~]# cd /usr/local/nginx/conf/
[root@base2 conf]# vim nginx.conf
     location / {
             root   html;
             index  index.php index.html index.htm;
         }

    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;
    }

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

[root@base2 conf]# ln -s /usr/local/nginx/sbin/nginx /sbin
[root@base2 conf]# nginx -t
[root@base2 conf]# nginx    # 开启nginx服务
[root@base2 conf]# vim /etc/php.ini 
 878 date.timezone =Asia/Shanghai
 [root@base2 conf]# vim /etc/php-fpm.d/www.conf 
 39 user = nginx
 41 group = nginx
[root@base2 conf]# systemctl start php-fpm
[root@base2 conf]# systemctl status php-fpm    # 开启php服务

在这里插入图片描述

[root@base2 conf]# netstat -antlp    # 查看php的端口

在这里插入图片描述

# nginx服务搭建成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值