基本架构
client -> app -> redis (如果没有缓存再访问)->mysql -> redis -> client
redis 和mysql 的数据结构不通用,需要转换
client -> php/py/java ->(r/w) redis -> 钩子函数 -> mysql
钩子函数过滤需要的数据存储到mysql
lnmp框架
scp test.php test.sql worker.php root@server4:/root/
server 4 需要 nginx php
yum remove openssl-devel -y
yum install 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 -y
systemctl start php-fpm
cp /root/test.php /usr/local/nginx/html/index.php
脚本在下一篇博客https://blog.csdn.net/m493096871/article/details/88032952
vim /usr/local/nginx/html/index.php
将redis 和mysql 的地址写对
vim /usr/local/nginx/conf/nginx.conf
server5 redis
安装好直接开
redis-server /etc/redis/6379.conf
server 6 mariadb-server
rpm -e `rpm -qa| grep mysql` --nodeps
yum install mariadb-server -y
rm -fr /var/lib/mysql/
systemctl start mariadb
mysql_secure_installation
mysql -pwestos
show databases;
create database test;
grant all on test.* to redis@'%' identified by 'westos';
flush privileges;
scp /root/test.sql root@server6:/root/
mysql -pwestos < /root/test.sql
然后访问
开启数据同步
server4 作为gearmand
systemctl start gearmand
mysql (client) -> germand:4730 (job server) -> worker (php/python/java) 自己编写
worker.php
https://blog.csdn.net/m493096871/article/details/88032952
server6mysql端
需要转换json
lib_mysqludf_json-master.zip #数据映射
gearman-mysql-udf-0.6.tar.gz #数据发送
yum install -y unzip
unzip lib_mysqludf_json-master.zip
cd lib_mysqludf_json-master
#获取当前数据库的devel
yum install -y mariadb-devel
gcc $(mysql_config --cflags) -shared -fPIC -o lib_mysqludf_json.so lib_mysqludf_json.c
cp lib_mysqludf_json.so /usr/lib64/mysql/plugin/
把模块放进去
mysql -pwestos
show global variables like 'plugin_dir';
创建函数
CREATE FUNCTION json_object RETURNS STRING SONAME 'lib_mysqludf_json.so';
select * from mysql.func;
tar zxf gearman-mysql-udf-0.6.tar.gz
需要 libgearman* libevent-*
libgearman-1.1.8-2.el7.x86_64.rpm libgearman-devel-1.1.8-2.el7.x86_64.rpm
./configure --libdir=/usr/lib64/mysql/plugin --with-mysql
make && make install
mysql -pwestos
CREATE FUNCTION gman_do_background RETURNS STRING SONAME
'libgearman_mysql_udf.so';
CREATE FUNCTION gman_servers_set RETURNS STRING SONAME
'libgearman_mysql_udf.so';
select * from mysql.func;
SELECT gman_servers_set('172.25.11.4:4730');
触发器的test.
mysql -p < test.sql
SHOW TRIGGERS FROM test;
找到触发器trigger
cp worker.php /usr/local/
修改worker的redis地址
vim /usr/local/worker.php
nohup php /usr/local/worker.php &>/dev/null
mysql -pwestos
use test;
update test set name='redhat' where id=1;
再访问redis服务器就可以了
已经在redis中变更了数据
数据库语句
DQL 查询
DCL 控制语句
DML 修改
DDL 删除