分类目录归档:Linux

高效的简洁的inotify+rsync同步代码

#!/bin/bash
inotifywait -mrq /mnt/www/xxxx--format "%w%f %e" -e modify,attrib,close_write,moved_to,moved_from,move,create,delete,delete_self,unmount | while read line
do
  echo $line
  e=`echo ${line##* }`
  f=`echo ${line% *}`
  if [[ ! -e "$f" ]]; then
    continue
  fi
  if [[ "$e" =~ "MOVED_TO" ]] || [[ "$e" =~ "CLOSE_WRITE" ]] || [[ "$e" =~ "ATTRIB" ]] || [[ "$e" =~ "CREATE,ISDIR" ]]; then
    rsync -a --delete-after $f f22@host1:$f
    rsync -a --delete-after $f f22@host2:$f
  elif [[ "$e" =~ "DELETE" ]] || [[ "$e" =~ "MOVED_FROM" ]]; then
    rsync --delete -a $f f22@host1:$f
    rsync --delete -a $f f22@host2:$f
  fi
  # echo $e
  # echo $f
done

LVM ext4缩容

缩减逻辑卷,xfs不支持,缩减前先unmount

e2fsck -f /dev/vg1/lv1 #检查磁盘错误 (针对ext4执行)
resize2fs /dev/vg1/lv1 100M #更新逻辑卷信息(针对ext4执行)
lvresize -L 100M /dev/vg1/lv1 #重新设定大小

作者:pcct
来源:CSDN
原文:https://blog.csdn.net/lovektm/article/details/78461453
版权声明:本文为博主原创文章,转载请附上博文链接!

pt-online-schema-change 最佳参数

pt-online-schema-change \
--user username \
--password 123456 \
--host x.x.x.x D=db,t=table \
--execute --alter "ADD COLUMN vip_version TINYINT NOT NULL DEFAULT 0" \
--charset utf8mb4 \
--no-version-check \
--nocheck-replication-filters \
--max-load Threads_running=10 \
--critical-load Threads_running=200 \
--chunk-time=0.5

–charset utf8mb4 设置下编码

–max-load Threads_running=10 低负载才运行,设置尽量小点

–critical-load Threads_running=200 终止条件 设置大点防止容易失败

–no-version-check 阿里云rds可能需要此参数

–chunk-time=0.5 这个优于设置chunk-size

–nocheck-replication-filters 有主从配置的时候需要 阿里云rds可能不需要这个参数

beanstalkd 安装和配置

安装
安装以centos为例

yum  install beanstalkd

配置

使用centos yum安装,通过查看服务脚本发现有这个配置文件

cat /etc/sysconfig/beanstalkd

主要修改几个地方
ADDR=-l 10.1.3.16 # 修改为内网或本地地址,否则会开放外网非常危险
PORT=-p 11111 # 修改下端口
BINLOG_DIR=-b /var/lib/beanstalkd/binlog # 启用二进制日志防止意外断电或重启导致数据丢失

 

客户端连接问题:

Connection error 113: No route to host

解决办法:防火墙开放对应端口

性能:

$start = microtime(true);
for ($i = 0; $i < 100000; $i ++) {
    $beansClient->useTube('myAwesomeTube')->put("哈哈哈job's payload呵呵呵呵");
}
echo microtime(true) - $start, "\n";

插入一万条数据一秒(本地连接)

插入十万条数据十秒(本地连接)

插入一万条数据14秒(内网连接)

本地取出1w条数据要1.5秒

内网取出1w条数据要33秒

本地取出 1173359条数据 要 200秒

结论:吃内存,快还是慢你觉得呢?

upstream timed out (110: Connection timed out) while reading upstream

2018/04/26 23:34:39 [error] 10872#0: *268906 upstream timed out (110: Connection timed out) while reading upstream, client: 119.103.223.107, server: ****, request: “GET /**** HTTP/1.1”, upstream: “****”, host: “****”

#fastcgi_connect_timeout 600;
#fastcgi_read_timeout 600;
#fastcgi_send_timeout 600;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;

upstream timed out (110: Connection timed out) while reading upstream,

upstream timed out (110: Connection timed out) while reading response header from upstream