2020年9月

六间房直播间 聊天室, 刷屏脚本


let str = '1.绿色要正,我们都知道翡翠是以绿为贵,所以对于一块好翡翠来说,绿色的色调越纯正越好,尽可能不偏黄、不偏蓝、不偏灰,绿色越纯正,翡翠价值越高。2.绿色分布要均匀,一般来说一件翡翠作品,它的绿色分布的越均匀,价值高,比如满绿的翡翠那是翡翠中价值最高的翡翠。3.水头要足,俗话说内行看种,外行看色,一件翡翠种水好的话,就算翡翠不是绿色,它的价值也会很低,而且是水头越好,翡翠的价值越高,如果翡翠的水头达到了半透明以上,那么这块翡翠就是特级翡翠了。4.瑕疵要少,不管是任何的宝石,瑕疵越少,价值越高,翡翠越是一样的,不过由于翡翠是天然的玉石,多少都会有一定瑕疵,因此在瑕疵不影响翡翠价值的情况下,我们要学会接受翡翠的瑕疵。5.裂纹要少,裂纹那是翡翠价值的杀手,因为裂纹不仅仅影响翡翠的美观,还影响翡翠的强度。翡翠裂纹对翡翠影响是致命的,所以我们在挑选翡翠的千万要看清楚,因为裂纹轻者有断裂的隐患,严重的情况就是翡翠饰品在佩戴的时候有可能会从裂纹处断裂。';
let i = 0;
window.setInterval(function(){
let end = Math.floor(Math.random()*10+1)
Room.chatList.sendPubMsg({tuid: "",con: str.substr(i, end)});
i += end;
},3100);

对于sendPubMsg 方法, 进一步跟踪, 得到以下代码

function echo(str){
var b = {
 r: page.rid,
 ak: page.authKey,
 t: "",
            m: str,
            ttt: new Date().getTime()
        };
        jQuery.extend(b, zhangZhiParam(Room.chatList._tracing));
b = '{"t":"msg_room", "content":' + jQuery.toJSON(b) + "}";
Room.Socket.proxy.convey(["command=sendmessage", "content=" + Room.Socket.proxy.encode(b)])
}

vi /usr/java/restart.sh

#!/bin/bash

/usr/java/apache-tomcat-8.0.45/bin/shutdown.sh

ps -ef|grep java|grep -v grep|awk '{print $2}'|xargs kill -9

/usr/java/apache-tomcat-8.0.45/bin/startup.sh

chmod +x restart.sh

crontab -e -u root

36 20 * * * /usr/java/restart.sh

location表达式类型

~ 表示执行一个正则匹配,区分大小写
~* 表示执行一个正则匹配,不区分大小写
^~ 表示普通字符匹配。使用前缀匹配。如果匹配成功,则不再匹配其他location。
= 进行普通字符精确匹配。也就是完全匹配。
@ "@" 定义一个命名的 location,使用在内部定向时,例如 error_page, try_files

location优先级说明

在nginx的location和配置中location的顺序没有太大关系。正location表达式的类型有关。相同类型的表达式,字符串长的会优先匹配。

以下是按优先级排列说明:

第一优先级:等号类型(=)的优先级最高。一旦匹配成功,则不再查找其他匹配项。
第二优先级:^~类型表达式。一旦匹配成功,则不再查找其他匹配项。
第三优先级:正则表达式类型(~ ~*)的优先级次之。如果有多个location的正则能匹配的话,则使用正则表达式最长的那个。
第四优先级:常规字符串匹配类型。按前缀匹配。

location优先级示例 配置项如下:

location = / {
# 仅仅匹配请求 /
[ configuration A ]
}

location / {
# 匹配所有以 / 开头的请求。但是如果有更长的同类型的表达式,则选择更长的表达式。如果有正则表达式可以匹配,则
# 优先匹配正则表达式。
[ configuration B ]
}

location /documents/ {
# 匹配所有以 /documents/ 开头的请求。但是如果有更长的同类型的表达式,则选择更长的表达式。
#如果有正则表达式可以匹配,则优先匹配正则表达式。
[ configuration C ]
}

location ^~ /images/ {
# 匹配所有以 /images/ 开头的表达式,如果匹配成功,则停止匹配查找。所以,即便有符合的正则表达式location,也
# 不会被使用
[ configuration D ]
}

location ~* \.(gif|jpg|jpeg)$ {
# 匹配所有以 gif jpg jpeg结尾的请求。但是 以 /images/开头的请求,将使用 Configuration D
[ configuration E ]
}

请求匹配示例

/ -> configuration A
/index.html -> configuration B
/documents/document.html -> configuration C
/images/1.gif -> configuration D
/documents/1.jpg -> configuration E

注意,以上的匹配和在配置文件中定义的顺序无关。

Linux内核从2.6.13开始,引入了inotify机制。通过intofity机制,能够对文件系统的变化进行监控,如对文件进行创建、删除、修改等操作,可以及时通知应用程序进行相关事件的处理。这种响应处理机制,避免了频繁的文件轮询任务,提高了任务的处理效率。

inotify-tools 支持事件类型

IN_ACCESS
IN_ATTRIB
IN_CLOSE_WRITE
IN_CLOSE_NOWRITE
IN_CREATE
IN_DELETE
IN_DELETE_SELF
IN_MODIFY
IN_MOVE_SELF
IN_MOVED_FROM
IN_MOVED_TO
IN_OPEN

查看inotify参数

sysctl -a | grep max_queued_events
输出:
fs.inotify.max_queued_events = 16384

sysctl -a | grep max_user_watches
输出:
fs.epoll.max_user_watches = 790384
fs.inotify.max_user_watches = 8192

sysctl -a | grep max_user_instances
输出:
fs.inotify.max_user_instances = 128

修改参数

sysctl -w fs.inotify.max_user_instances=130
fs.inotify.max_user_instances = 130

vi /etc/sysctl.conf
#添加如下代码
fs.inotify.max_user_instances=130

参数说明:

max_user_instances:每个用户创建inotify实例最大值

max_queued_events:inotify队列最大长度,如果值太小,会出现错误,导致监控文件不准确

max_user_watches:要知道同步的文件包含的目录数,可以用:

find /home -type d|wc -l 统计,必须保证参数值大于统计结果(/home为同步文件目录)。

创建实时监控脚本

vi inotify_start.sh
chmod a+x ./inotify_start.sh

/usr/local/inotify/bin/inotifywait -mrq -e modify,create,move,delete \
--fromfile '/opt/scripts/ffile' \
--timefmt '%y-%m-%d %H:%M' --format '%T %f %e' \
--outfile '/tmp/rsync.log'

ifnotifywait常用参数

--timefmt 时间格式 %y年 %m月 %d日 %H小时 %M分钟
--format 输出格式 %T时间 %w路径 %f文件名 %e状态
-m 始终保持监听状态,默认触发事件即退出。
-r 递归查询目录
-q 打印出监控事件
-e 定义监控的事件,可用参数:
    open 打开文件
    access 访问文件
    modify 修改文件
    delete 删除文件
    create 新建文件
    attrb  属性变更
inotifywait -h
inotifywait 3.13
Wait for a particular event on a file or set of files.
Usage: inotifywait [ options ] file1 [ file2 ] [ file3 ] [ ... ]
Options:
    -h|--help         Show this help text.
    @<file>           Exclude the specified file from being watched.
    --exclude <pattern>
                      Exclude all events on files matching the
                      extended regular expression <pattern>.
    --excludei <pattern>
                      Like --exclude but case insensitive.
    -m|--monitor      Keep listening for events forever.  Without
                      this option, inotifywait will exit after one
                      event is received.
    -r|--recursive    Watch directories recursively.
    --fromfile <file>
                      Read files to watch from <file> or `-' for stdin.
    -q|--quiet        Print less (only print events).
    -qq               Print nothing (not even events).
    --format <fmt>    Print using a specified printf-like format
                      string; read the man page for more details.
    --timefmt <fmt>    strftime-compatible format string for use with
                      %T in --format string.
    -c|--csv          Print events in CSV format.
    -t|--timeout <seconds>
                      When listening for a single event, time out after
                      waiting for an event for <seconds> seconds.
                      If <seconds> is 0, inotifywait will never time out.
    -e|--event <event1> [ -e|--event <event2> ... ]
        Listen for specific event(s).  If omitted, all events are 
        listened for.

Exit status:
    0  -  An event you asked to watch for was received.
    1  -  An event you did not ask to watch for was received
          (usually delete_self or unmount), or some error occurred.
    2  -  The --timeout option was given and no events occurred
          in the specified interval of time.

Events:
    access        file or directory contents were read
    modify        file or directory contents were written
    attrib        file or directory attributes changed
    close_write    file or directory closed, after being opened in
                   writeable mode
    close_nowrite    file or directory closed, after being opened in
                   read-only mode
    close        file or directory closed, regardless of read/write mode
    open        file or directory opened
    moved_to    file or directory moved to watched directory
    moved_from    file or directory moved from watched directory
    move        file or directory moved to or from watched directory
    create        file or directory created within watched directory
    delete        file or directory deleted within watched directory
    delete_self    file or directory was deleted
    unmount        file system containing file or directory unmounted

inotifywatch帮助手册

inotifywatch -h
inotifywatch 3.13
Gather filesystem usage statistics using inotify.
Usage: inotifywatch [ options ] file1 [ file2 ] [ ... ]
Options:
    -h|--help        Show this help text.
    -v|--verbose     Be verbose.
    @<file>           Exclude the specified file from being watched.
    --fromfile <file>
        Read files to watch from <file> or `-' for stdin.
    --exclude <pattern>
        Exclude all events on files matching the extended regular
        expression <pattern>.
    --excludei <pattern>
        Like --exclude but case insensitive.
    -z|--zero
        In the final table of results, output rows and columns even
        if they consist only of zeros (the default is to not output
        these rows and columns).
    -r|--recursive    Watch directories recursively.
    -t|--timeout <seconds>
        Listen only for specified amount of time in seconds; if
        omitted or 0, inotifywatch will execute until receiving an
        interrupt signal.
    -e|--event <event1> [ -e|--event <event2> ... ]
        Listen for specific event(s).  If omitted, all events are 
        listened for.
    -a|--ascending <event>
        Sort ascending by a particular event, or `total'.
    -d|--descending <event>
        Sort descending by a particular event, or `total'.

Exit status:
    0  -  Exited normally.
    1  -  Some error occurred.

Events:
    access        file or directory contents were read
    modify        file or directory contents were written
    attrib        file or directory attributes changed
    close_write    file or directory closed, after being opened in
                   writeable mode
    close_nowrite    file or directory closed, after being opened in
                   read-only mode
    close        file or directory closed, regardless of read/write mode
    open        file or directory opened
    moved_to    file or directory moved to watched directory
    moved_from    file or directory moved from watched directory
    move        file or directory moved to or from watched directory
    create        file or directory created within watched directory
    delete        file or directory deleted within watched directory
    delete_self    file or directory was deleted
    unmount        file system containing file or directory unmounted