redis:实时同步( gearman + lib_mysqludf_json.so + gearman-mysql-udf)
######1.nginx端######
Gearman支持分布式任务的分发框架,用Gearman的worker端来完成redis同步数据库的更新。
###1.开启gearmand服务###
(上一章节已经将rhel7目录下的安装包全部安装过)
###2.查看端口是否打开###
######2.mariadb端######
###1.获取lib_mysqludf_json-master压缩包,解压###
lib_mysqludf_json-master可以将UDF库函数关系数据映射为JSON格式。
###2.安装mariadb-devel,并管理###
数据库中的数据映射为 JSON 格式。
###3.查看数据库模块目录,添加lib_mysqludf_json.so模块###
###4.获取gearman-mysql-udf,并安装依赖###
gearman-mysql-udf插件是用来管理调用Gearman的分布式队列。
###5.编译gearman-mysql-udf###
###6.添加libgearman_mysql_udf.so模块###
###7.指定gearman的服务信息###
###8.编写mysql触发器,并启动###
###9.查看触发器###
######3.编写gearman的worker端######
###1.编辑worker.php文件###
(修改第7行)
###2.运行worker###
######4.测试######
###1.修改数据库文件###
###2.在redis端测试访问数据库###
###3.补充###
[[email protected] rhel7]# systemctl stop gearmand ##关闭服务后,就无法同步数据库的变更了
[[email protected] rhel7]# systemctl start gearmand ##开启服务会报错
[1]- Done nohup php /usr/local/worker.php &>/dev/null (wd: ~)
(wd now: ~/rhel7)
[2]+ Done nohup php /usr/local/worker.php &>/dev/null (wd: ~)
(wd now: ~/rhel7)
[[email protected] rhel7]# nohup php /usr/local/worker.php &> /dev/null &
[1] 14557 ##必须先开启worker
[[email protected] rhel7]# systemctl restart gearmand ##然后重启服务,就可以同步了