jwj 发布的文章

最近,发现网站的数据库连接不上,而且持续有一段时间了。主要还是平时太少管理网站,所以隔了几天才发现。
重启后,数据库恢复正常,但一分钟不到,内存不足,又挂了。
经过排查,原来是没使用swap虚拟内存。开启后,妥妥的稳定运行。

关闭配置文件/etc/fstab中所有的交换空间

sudo swapoff -a

一、创建交换分区的文件:增加2G大小的交换分区

sudo dd if=/dev/zero of=/var/swapfile bs=1M count=2048
  • if 代表输入文件。如果不指定if,默认就会从stdin中读取输入。
  • of 代表输出文件。如果不指定of,默认就会将stdout作为默认输出。
  • bs 代表字节为单位的块大小。
  • count 代表被复制的块数。
  • /dev/zero 是一个字符设备,会不断返回0值字节(\0)。

块大小可以使用的计量单位表

单位大小代码
字节1Bc
字节2Bw
512Bb
千字节1024Bk
兆字节1024KBM
吉字节1024MBG

二、设置交换分区文件

sudo mkswap /var/swapfile

三、启用交换分区

sudo swapon /var/swapfile

四、写入/etc/fstab,以便在引导时启用

echo '/var/swapfile swap swap defaults 0 0'>>sudo /etc/fstab

五、查看swap的情况

free -m

在使用input propertychange事件时,遇到一个问题。我输入一个字时,会重复执行五六次事件,事件里又包含了网络请求,体验非常差。经过搜索,找到了解决办法,详情如下。

代码

// 监听textarea的输入
$(document).on('input propertychange', 'textarea', function () {
    var detailsElement = $(this),
        details = $(this).val();
    // 确保是propertychange事件,并且是改变了内容
    if (window.event && event.type == 'propertychange' && event.propertyName != 'value')
        return;

    // 清除旧的定时器
    window.clearTimeout($(this).data('timeout'));
    // 设置新的定时器
    $(this).data('timeout', setTimeout(function () {
        // 这里放置要执行的代码
        console.log('值改变了~输入值:' + details);
    }, 5000)); // 延时值:5000 = 5秒
});

原理

1.监听textarea多行文本输入框的inputpropertychange事件
2.事件触发后,判断是否是propertychange事件,并且是改变内容的propertychange事件
3.清除旧的定时器,然后设置新的定时器。这样在一定时间内,回调函数不会重复执行,只会执行一次。

最近做一个项目,需要用到Gmail邮箱发送邮件,但发现发送不出去。
排查问题时,需要用到dig命令,但使用时,却提醒我dig命令不存在~
那就安装吧,习惯性的运行yum install dig,却提示我没这个包?
微信截图_20181017092818.png

经过查找资料,原来dig命令属于bind-utils工具包,安装这个包之后就可以使用dig命令了。

yum install bind-utils

最近有个做招聘网站的客户提出了个修改要求,要求报名列表上的某个元素可点击,点击后可以录取这个人。
这不是日了个狗了嘛,现在的列表项的每项是用a标签包着的,并且是多处调用这里,所以不能将a标签改成其它。
不过也得满足不是。
经过一番查找,找到一个方法:阻止冒泡事件

代码如下:

<div class="list">
    <a href="" class="list-item">
        麻花藤<br/>
        2018-10-15 18:52:33<br/>
        <!-- 给span元素加上pass类,点击这丫的录取此人 -->
        <span class="pass">点击录取</span>
    </a>
    <a href="" class="list-item">
        马云<br/>
        2018-10-15 18:52:33<br/>
        <span class="pass">点击录取</span>
    </a>
    <a href="" class="list-item">
        王健林<br/>
        2018-10-15 18:52:33<br/>
        <span class="pass">点击录取</span>
    </a>
</div>
<script>
// 这里用了JQuery,很多人说过时了,但我还是挺喜欢用的,方便!
$(document).on('click', '.pass', function (e) {
    // 这里执行你要执行的动作,例如请求同意录取接口
    // .....

    // 阻止冒泡事件
    e.stopPropagation();
    // 取消默认动作
    return false;
});
</script>

作为一个习惯追新的人,最近把nginx升级到了1.15.2,修改站点配置并重新加载配置文件时,发现报警告。
虽然不影响正常,也不是处女座,但还是看不顺眼,经过一番百度 Google,终于找到原因和解决方法!

报错内容

nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl" directive instead in /usr/local/nginx/conf/vhost/test.ll00.cn:24

原因

新版本不推荐使用ssl指令,所以会发出一段警告。使用listen 443 ssl;代替

解决方法

在配置文件里,找到ssl on;,将其注释掉

# ssl on;

然后修改监听端口处的配置后面加上ssl

listen 443 ssl;

相关Nginx更新日志:

Changes with nginx 1.15.0                                        05 Jun 2018

    *) Change: the "ssl" directive is deprecated; the "ssl" parameter of the
       "listen" directive should be used instead.

    *) Change: now nginx detects missing SSL certificates during
       configuration testing when using the "ssl" parameter of the "listen"
       directive.

    *) Feature: now the stream module can handle multiple incoming UDP
       datagrams from a client within a single session.

    *) Bugfix: it was possible to specify an incorrect response code in the
       "proxy_cache_valid" directive.

    *) Bugfix: nginx could not be built by gcc 8.1.

    *) Bugfix: logging to syslog stopped on local IP address changes.

    *) Bugfix: nginx could not be built by clang with CUDA SDK installed;
       the bug had appeared in 1.13.8.

    *) Bugfix: "getsockopt(TCP_FASTOPEN) ... failed" messages might appear
       in logs during binary upgrade when using unix domain listen sockets
       on FreeBSD.

    *) Bugfix: nginx could not be built on Fedora 28 Linux.

    *) Bugfix: request processing rate might exceed configured rate when
       using the "limit_req" directive.

    *) Bugfix: in handling of client addresses when using unix domain listen
       sockets to work with datagrams on Linux.

    *) Bugfix: in memory allocation error handling.