redis
redis mysql同步
redis持久化
RDB模式,较MBR省磁盘空间
systemctl start redis
redis-cli
vim /etc/redis/redis.conf ##编辑配置文件,打开日志,每秒刷新
appendfsync everysec
appendonly yes
cd /var/lib/redis
redis-cli
127.0.0.1:6379> INCR 1
(integer) 1
cat appendonly.aof ##查看日志
*2
$6
SELECT
redis-cli
info
role:master
connected_slaves:0
server1:
cd /usr/local
rsync -a nginx server2:/usr/local/ ##复制nginx已不属好的nginx文件
server2:
lftp 172.25.0.250
cd pub/docs/redis
mirror rhel7/
yum install php-* libgearman-1.1.12-18.el7.x86_64.rpm libgearman-devel-1.1.12-18.el7.x86_64.rpm libevent-devel-2.0.21-4.el7.x86_64.rpm
systemctl start php-fpm ##开启php
ps ax
netstat -antlp ##查看端口
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 3954/php-fpm: maste
cd /usr/local
ls
cd nginx
cd sbin
pwd
/usr/local/nginx/sbin
vim .bash_profile ##编辑环境变量
source .bash_profile
/usr/local/nginx/sbin
cd /usr/local/nginx/ ##复制默认配置文件,保持初始状态
cd conf/
cp nginx.conf.default nginx.conf
vim nginx.conf ##开启php服务
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;
}
nginx -t
nginx ##启动nginx
cp test.php test.sql /usr/local/nginx/html
vim test.php ##发布文件,redis服务连接主机1,mysql服务连接主机4
$redis->connect('172.25.9.1',6379
$connect = mysql_connect('172.25.9.4'
yum install -y mariadb-server
systemctl start mariadb
vim test.sql
mysql ##查看数据库,看test数据库是否存在
show databases;
mysql < test.sql
mysql
use test
show tables;
select * from test;
grant all on test.* to redis@'%' identified by 'westos'; ##与数据库文件保持一直,允许redis用户远程登录,密码为westos
test:
firefox -> http://172.25.9.2/test.php
第一次数据来源 mysql
第二次数据来源 redis’
server4:
update test set name=‘westos’; ##更新数据
server1:
redis-cli
127.0.0.1:6379> get 1
"test1"
(问题:redis和mysql不同步)
del 1
(integer) 1 ##删除数据
firefox 再次刷新,数据来源,mysql,同步
server4:
lftp 172.25.0.250
yum install unzip -y
unzip lib_mysqludf_json-master.zip
cd lib_mysqludf_json-master
yum install mariadb-devel.x86_64
yum install gcc -y
gcc $(mysql_config --cflags) -shared -fPIC -o lib_mysqludf_json.so lib_mysqludf_json.c
mysql
show global variables like 'plugin_dir';
+---------------+--------------------------+
| Variable_name | Value |
+---------------+--------------------------+
| plugin_dir | /usr/lib64/mysql/plugin/ |
+---------------+--------------------------+
cp lib_mysqludf_json.so /usr/lib64/mysql/plugin/
mysql
create function json_object returns string soname
-> 'lib_mysqludf_json.so';
cd
lftp 172.25.0.250
cd pub/docs/redis/
get gearman-mysql-udf-0.6.tar.gz
mget libgearman-*
get libevent-devel-2.0.21-4.el7.x86_64.rpm
tar zxf gearman-mysql-udf-0.6.tar.gz
yum install libgearman-* libevent-devel-2.0.21-4.el7.x86_64.rpm
cd gearman-mysql-udf-0.6
./configure --libdir=/usr/lib64/mysql/plugin
make
make install
mysql
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.9.2:4730');
vim test.sql
DELIMITER $$
CREATE TRIGGER datatoredis AFTER UPDATE ON test FOR EACH ROW BEGIN
SET @RECV=gman_do_background('syncToRedis', json_object(NEW.id as `id`, NEW.name as `name`));
END$$
DELIMITER ;
server2:
yum install gearmand-1.1.12-18.el7.x86_64.rpm
systemctl start gearmand
netstat -antlp
tcp 0 0 0.0.0.0:4730 0.0.0.0:* LISTEN 4102/gearmand
vim worker.php
redis->connect('172.25.9.1', 6379);
nohup php worker.php &
test:
server4:
mysql
use test;
select * from test;
update test set name='redhat';
select * from test;
server1:
redis-cli
127.0.0.1:6379> get 1
"redhat"
127.0.0.1:6379> get 2
"redhat"
firefox -> http://172.25.9.2/test.php
直接由redis导入