昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期二, 七月 30, 2019

[网络技术]Linux 下免SUDO使用 docker 命令

在linux 使用 docker 需要ROOT权限, 所以每次使用 Docker 都需要 sudo docker, 

当然你也可以 sudo -s 直接在root 下运行, 但是总会有各种各样的问题

使用以下三个命令可以免 sudo 运行 docker

[bash]
sudo groupadd docker
sudo gpasswd -a $USER docker
newgrp docker  
[/bash]





--
Feng

星期一, 七月 29, 2019

[Youtube]如何使用 Nginx-proxy 做反向代理实现单端口多服务(网站)

tags: docker, reverse-proxy, nginx-proxy, nginx


如果你有一台VPS虚拟机, 而且已经在上面跑了一个网站, 现在你想在同一台虚拟机上再跑另一个网站, 但是你的VPS只开了80和443两个端口, 其它端口你不能开. 或者说,你的虚拟机可以开别的端口, 但是你觉得把网站跑在其它端口太LOW了, 别人一看到有端口的链接估计都不敢点. 所以, 问题来了, 怎么在同一个80端口或者443端口里面同时跑多个网站(或者服务)呢?

今天我来介绍一个超级好的docker 容器镜像  Nginx-proxy

为什么要介绍这个docker 版的而不是直接介绍 Nginx 本身呢? 因为我用的是这个, 我的大部分服务都在docker 里运行, 就算不是在docker 里运行的, 我也有办法和 nginx-proxy 一起使用. nginx-proxy 支持多服务, SSL 证书自动设置与更新, 而且还支持负载平衡, 实在是太方便了, 不需要自己去研究 nginx 的反向代理设置.

今天我先介绍在80端口实现多个网站. 之后如果有需要, 我再介绍如何让你的网站支持 HTTPS (SSL). 

以下是视频中用到的代码

[bash]

sudo docker network rm feng-net
sudo docker network create feng-net

sudo docker rm -f nginx-proxy
sudo docker run -p 80:80 -p 443:443 \
    -d \
    --name nginx-proxy \
    --network feng-net \
    --network-alias nginx-proxy-host\
    -v /usr/share/nginx/html \
    -v /etc/nginx/vhost.d \
    -v /var/run/docker.sock:/tmp/docker.sock:ro \
    jwilder/nginx-proxy


sudo docker rm -f www
sudo docker run \
    -d \
    -e VIRTUAL_HOST=www.fengnz.tk \
    --network feng-net \
    --network-alias  www-host \
    --name www  \
    -p 81:80 \
    nginxdemos/hello

sudo docker rm -f bbs
sudo docker run \
    -d \
    -e VIRTUAL_HOST=bbs.fengnz.tk \
    --network feng-net \
    --network-alias  bbs-host \
    --name bbs  \
    -p 82:8000 \
    crccheck/hello-world

sudo docker run --name web-test1 -p 80:80 -d --rm nginxdemos/hello
sudo docker run --name web-test2 -p 80:8000 -d --rm crccheck/hello-world


[/bash]



--
Feng

星期日, 七月 28, 2019

单面打印机打双面的方法, 无需重整页面顺序


我的打印机是一台兄弟的黑白激光打印机 Brother DCP 1610W
这是一台只能单面打印的打印机, 如果想打双面的话, 要先打单面, 再把打印好的纸放回打印机再打另外一面. 操作很简单, 但如果纸的顺序没有放好, 就会打错页哦. 如果按先打单页,再打双页的方法打印的话, 单面打完后, 要把纸张的顺序全部反过来, 第一页变成最后一页,再反过来重新插进打印机打. 这样就比较麻烦,而且容易出错.

今天我来教大家我的方法, 用这样的方法打印出来, 页面顺序就是直接正确的.

首先,我们只打双数页, 如图, 把页面顺序颠倒打印,这样打印机会从最后一页开始打印.



打印出来的纸拿出来, 直接翻转后塞回打印机, 注意以下两点

1 空白面朝上
2 页头朝打印机进纸口的里面

然后再打印单数页, 这回要把颠倒顺序的勾去掉, 这次从第一页开始打印.

这样打印出来, 顺序直接就是对的啦.

为什么要先打双数页呢? 因为如果碰到奇数页数的文档, 先打单数页的话, 要拿掉一张纸. 要么就容易把最后一页忘在打印机里.






--
Feng

星期三, 七月 24, 2019

[网络技术]在 VIM中, 如何打开最近使用过的文件

打开最近文件是个非常基本的编辑器功能. 但是在VIM中却没有那么好找. 不过当你找到后, 发现其实还是很容易的.

在VIM的命令模式输入

:browse oldfiles

就会弹出最近打开过的100个文件.

如果清单很长的话, 按空格翻页, 或者直接按q停止翻页. 这个时候输入序号, 回车就可以直接跳到你要的文件.



觉得麻烦你可以直接把这个命令MAP到一个快捷键 , 比如

[bash]
:map <F2> :browse oldfiles<cr>
[/bash]

这样, 直接按F2就可以弹出最近打开过的文件了.

--
Feng

[网络技术]给想学AI的新手指一条明路

注: 这里讲的AI特指神经网络的深度学习, 也就是 Deep Learning, Artificial Neural Network.

师父领进门, 修行靠个人. 虽然说修行是靠个人, 但是如果没有这个领进门,你就不得其门而入, 你在门外的修行, 总是事倍而功半, 修了半天, 还是个门外汉. 所以, 这个领进门的份量龙其的重.

如果你对神经网络的深度学习很有兴趣, 但是看了一堆的网上的文章以后,也还是糊糊涂涂, 不得其门而入, 那你应该听听我的建议.

你也许对深度学习有点熟悉, 至少很熟悉里面的一些专有名词, 比如说 DNN, CNN, Stochastic Gradient Descent, Adam, Adaptive learning rates, Momentum, softmax 等等. 但你只是熟悉这些名词而已, 却不明了它们真正的意思. 你在网上爬了很多文章, 甚至看了不少的论文, 但是总还是感觉云里雾里的, 感觉好像有点懂了, 但是一看到数学的公式就懵圈了.  那是因为你没有真正的学过一个系统的课程.

不要看网上那些文章了, 在这之前, 你应该学习一下以下两个课程.




这两个课程的主讲是Andrew NG. 这个课程可以免费学习 (用 audit course).  这个课程真的非常好, 由线入深的讲解了深度学习的原理(其实原理很简单). 懂得原理以后,你再理解起其它的东西就会事半功倍. 而且也有能力分辨网上的一些文章是否对你有用. 而不会浪费时间在看那些千篇一律的文章上面,一直重复的看同样的东西, 同样的名词. 总之,学完这两个课程以后, 你再去看网上的文章最觉得不会太难了.


 
 

--
Feng

星期二, 七月 23, 2019

Jupyter Notebook 里面奇怪的符号 !, % 还有*都是啥意思?

! 和 %号是 IPython 的 magic commands. 其实就是在python 里面命令 shell 命令. 比如 cd, wget 这种本来应该在 bash shell 里面跑的命令, 加个 ! 就可以直接在 python 环境里面运行了.



以下这种情况里的*号是python3 里面的unpacking operator, 以下的错误是因为用了 python2 的环境. 换成 python3 来运行就正常了.

 File "go.py", line 149
    weight = tf.Variable(tf.truncated_normal([*conv_ksize, x_tensor.shape.as_list()[3], conv_num_outputs],stddev=5e-2))
                                              ^
SyntaxError: invalid syntax

错误命令 python go.py

正确命令 python3 go.py

--
Feng

星期日, 七月 14, 2019

你的LINUX VPS 虚拟机超载了吗? 全面了解Linux 的 Load Average 指标

tags: linux, load average


在Linux 下如何查看机器的负载情况呢? 除了CPU, 内存, 磁盘读写还有哪个关键指标非常值得关注呢? 跟着我来了解 Linux 负载最关键的指标  Load Average

-~-~~-~~~-~~-~-

本频道旨在分享生活中各种小技巧, 如用小米盒子看国内视频, 如何使用KODI看电影等等. 同时我也会分享一些编程的教程, 如编写Telegram机器人, 建站等。 点击进入我的频道: goo.gl/5tyxcf

🔷 订阅我的频道: goo.gl/KuF3bY
🔷 telegram电报群: t.me/fengsharegroup
🔷 我的博客: www.dengnz.com/blog
🔷 Facebook: www.facebook.com/fengnz

觉得我的视频对你帮助很大的话, 请我喝杯咖啡吧
微信赞赏码: goo.gl/uKoE8w
-~-~~-~~~-~~-~-

--
Feng

星期一, 七月 08, 2019

[youtube]比上海垃圾分类还麻烦? 世界上最后一片净士 - 新西兰是如何做垃圾分类的?

tags: rubbish classification, new zealand, 上海, 垃圾分类


新西兰是个很干净的国家, 出门走一圈回来不胶鞋, 家里的地毯也不会被踩脏的. 这样一个国家的垃圾分类是怎么样的呢?  他们的垃圾又是怎么处理的?

本视频包含以下内容.

垃圾分类的好处
公用垃圾筒
家庭垃圾投放与回收
大型垃圾
如果不分类呢?
垃圾出国
禁塑令

-~-~~-~~~-~~-~-

本频道旨在分享生活中各种小技巧, 如用小米盒子看国内视频, 如何使用KODI看电影等等. 同时我也会分享一些编程的教程, 如编写Telegram机器人, 建站等。 点击进入我的频道: goo.gl/5tyxcf

🔷 订阅我的频道: goo.gl/KuF3bY
🔷 telegram电报群: t.me/fengsharegroup
🔷 我的博客: www.dengnz.com/blog
🔷 Facebook: www.facebook.com/fengnz

觉得我的视频对你帮助很大的话, 请我喝杯咖啡吧
微信赞赏码: goo.gl/uKoE8w
-~-~~-~~~-~~-~-



--
Feng

星期六, 七月 06, 2019

[网络技术]Mac os 使用nmap 和 arp 快速找到局域网其它设备的IP地址

因为换了路由器, 所以家里面所有设备的IP都变了。 当我要用这台MAC RDP ( 远程协助)到我的Surface book2 的时候, 发现IP设备不对了。 那要怎么快速的找到那台电脑的IP呢?

首先, 马上想到我以前发过的一篇文章里讲到的 nmap, 于是我输入了以下命令 (你需要使用 ifconfig 命令先找出ip 段, 一般是 eth1 网卡)。

[bash]
YuFengs-Mini:~ fennng$ nmap -sn 192.168.1.0/24
Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-06 12:08 NZST
Nmap scan report for router.asus.com (192.168.1.1)
Host is up (0.0069s latency).
Nmap scan report for 192.168.1.11
Host is up (0.038s latency).
Nmap scan report for android-2978145522146f5e (192.168.1.74)
Host is up (0.045s latency).
Nmap scan report for YuFengs-Mini (192.168.1.91)
Host is up (0.0013s latency).
Nmap done: 256 IP addresses (4 hosts up) scanned in 3.32 seconds
[/bash]

可是结果令我惊讶, 那台PC的IP地址并没有列出来, 不知道 什么原因。但是我想到扫描过的地址都会缓存在 arp 表里, 所以,我马上又运行了 arp 命令, 果然, 找到了我要的主机 CL221 的IP, 192.168.1.204.

技多不压身呀, 多学几个命令准没错!



[bash]
YuFengs-Mini:~ fennng$ arp -a
? (169.254.8.61) at c4:9d:ed:2c:45:f on en1 [ethernet]
? (192.168.1.0) at ff:ff:ff:ff:ff:ff on en1 ifscope [ethernet]
router.asus.com (192.168.1.1) at 40:b0:76:5a:4d:4c on en1 ifscope [ethernet]
? (192.168.1.2) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.3) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.4) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.5) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.6) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.7) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.8) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.9) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.10) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.11) at 28:56:5a:2d:70:c4 on en1 ifscope [ethernet]
? (192.168.1.12) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.13) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.14) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.15) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.16) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.17) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.18) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.19) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.20) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.21) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.22) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.23) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.24) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.25) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.26) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.27) at (incomplete) on en1 ifscope [ethernet]
minde-iphone (192.168.1.28) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.29) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.30) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.31) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.32) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.33) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.34) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.35) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.36) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.37) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.38) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.39) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.40) at (incomplete) on en1 ifscope [ethernet]
galaxy-s6-edge (192.168.1.41) at ec:1f:72:21:d0:1c on en1 ifscope [ethernet]
? (192.168.1.42) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.43) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.44) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.45) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.46) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.47) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.48) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.49) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.50) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.51) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.52) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.53) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.54) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.55) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.56) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.57) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.58) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.59) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.60) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.61) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.62) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.63) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.64) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.65) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.66) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.67) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.68) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.69) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.70) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.71) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.72) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.73) at (incomplete) on en1 ifscope [ethernet]
android-2978145522146f5e (192.168.1.74) at 3c:bd:3e:28:55:88 on en1 ifscope [ethernet]
? (192.168.1.75) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.76) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.77) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.78) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.79) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.80) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.81) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.82) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.83) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.84) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.85) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.86) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.87) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.88) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.89) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.90) at (incomplete) on en1 ifscope [ethernet]
yufengs-mini (192.168.1.91) at 70:73:cb:be:55:ad on en1 ifscope permanent [ethernet]
? (192.168.1.92) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.93) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.94) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.95) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.96) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.97) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.98) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.99) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.100) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.101) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.102) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.103) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.104) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.105) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.106) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.107) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.108) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.109) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.110) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.111) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.112) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.113) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.114) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.115) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.116) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.117) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.118) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.119) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.120) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.121) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.122) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.123) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.124) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.125) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.126) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.127) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.128) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.129) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.130) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.131) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.132) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.133) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.134) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.135) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.136) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.137) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.138) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.139) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.140) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.141) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.142) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.143) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.144) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.145) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.146) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.147) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.148) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.149) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.150) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.151) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.152) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.153) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.154) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.155) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.156) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.157) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.158) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.159) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.160) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.161) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.162) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.163) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.164) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.165) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.166) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.167) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.168) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.169) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.170) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.171) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.172) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.173) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.174) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.175) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.176) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.177) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.178) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.179) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.180) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.181) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.182) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.183) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.184) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.185) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.186) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.187) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.188) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.189) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.190) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.191) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.192) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.193) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.194) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.195) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.196) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.197) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.198) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.199) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.200) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.201) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.202) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.203) at (incomplete) on en1 ifscope [ethernet]
cl221 (192.168.1.204) at c4:9d:ed:2c:45:f on en1 ifscope [ethernet]
? (192.168.1.205) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.206) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.207) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.208) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.209) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.210) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.211) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.212) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.213) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.214) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.215) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.216) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.217) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.218) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.219) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.220) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.221) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.222) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.223) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.224) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.225) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.226) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.227) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.228) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.229) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.230) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.231) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.232) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.233) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.234) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.235) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.236) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.237) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.238) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.239) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.240) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.241) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.242) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.243) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.244) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.245) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.246) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.247) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.248) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.249) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.250) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.251) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.252) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.253) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.254) at (incomplete) on en1 ifscope [ethernet]
? (192.168.1.255) at ff:ff:ff:ff:ff:ff on en1 ifscope [ethernet]
? (224.0.0.251) at 1:0:5e:0:0:fb on en1 ifscope permanent [ethernet]
? (239.255.255.250) at 1:0:5e:7f:ff:fa on en1 ifscope permanent [ethernet]
YuFengs-Mini:~ fennng$
[/bash]




--
Feng

星期四, 七月 04, 2019

在 Windows Server 上使用Powershell 一键安装 Chrome

把 Windows 2012 服务器当客户机用是非常难用的,因为安全上的设置, IE浏览器超难用。一直弹窗不说, 还不让你下载。



但是, 解决方法也是超级简单, 点开Powershell, 粘贴以下命令。

[bash]
$Path = $env:TEMP; $Installer = "chrome_installer.exe"; Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $Path\$Installer; Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path\$Installer
[/bash]

等两分钟, Chome 就会出现在你的任务栏上, 全自动静默安装。




--
Feng

微软 Azure 学生机 b1s 要跑 windows server 2012, 别跑2019

昨天用我的Azure 学生帐号开了一台 Windows Server 2019 Data center, 超慢。 因为只有1G内存。 因为只有b1s 是免费的, 所以不能升级内存。

于是我删了重新开了一台 2012 的 window server, 明显快多了。RDP不会无缘无故的退出。 程序响应速度也快得多。 内存占用75%。 2019的内存占用是90%. 



--
Feng

星期二, 七月 02, 2019

在 nodejs expressjs 中使用 async-lock 模块实现多线程安全代码

模块链接



昨天正式发布了用nodejs 重写的 Telegram抽奖机器人 @fengdrawbot 后, 马上在第一次被使用中就发现了一超级大BUG。

由于机器人有人数到了就会自动开奖的机制, 所以在每次有人加入抽奖的时候就会判断是否达到人数, 达到人数后就会开奖。 

当即将开奖的时候, 如果有几人同时参加抽奖, 由于是几乎同时参加的, 所以有机率同时触发抽奖代码使机器人开奖多次。

原来机器人是在Google App Script (GAS) 上运行,使用的也是GAS上面的锁 (LockService),除了慢点并没有什么问题。当我改用nodejs 后, 我使用了 async-lock 这个模块。 但是其实我在使用的过程中,代码没有使用正确,而我也没有模拟多人同时参与的情况进行测试,所以出现了一个大BUG。

上一篇博客我写了如何使用fiddler 进行BUG的复原。这一篇博客我想讲讲 async-lock 的具体用法, 官方的说明文档太简短,我当时没有完全看懂, 所以才会犯错。


async-lock 的安装和导入请直接看官方文档。 我这里给出示例代码来讲讲它的用法。

[javascript]
        // 设置一个用来锁的对像,我这里使用抽奖码来锁
        // 用抽奖码的好处是,每个抽奖都有独立的锁
        // 当有好几个抽奖同时开奖的时候,它们互不干涉
        let key = draw.joinCode;

        // 这个只是我用来测试的,标记当前的线程
        let uuid = uuidv4();
       
        // 拿锁, 只有拿到锁才能执行里面的代码
        // 没拿到锁的线程会在这里卡住,直到拿到锁为止
        lock.acquire(key, function(done) {
          // async work
          // 拿到锁后, 这个匿名函数里面的代码才会被执行
          console.log("got lock" + uuid);
          // Draw the result and modify payloads array
          let task = DrawCommon.drawResult(draw, payloads, payload5, uuid);
          task.then(r => {
            // I previous used done in a wrong place, so the lock didn't work
            console.log("release lock" + uuid);
            // 这里使用 done 这个 callback 来释放锁, 释放后,别的线程才能进来
            // 这个时候,之前的线程已经开奖完毕, 新进来的进程会重新查数据库,如果
            // 发现开奖完毕则不会做任何事, 避免了多次开奖
            // 如果没有锁的话, 所以进程一起进到这里面, 当它们查询数据库的时候发现还没有开奖,
            // 就会一起执行开奖的代码
            done("no error", "ok");
          });
          tasks.push(task);
        }, function(err, ret) {
            // lock released
        }, null);
[/javascript]


上面的这个例子是使用了传进来的done 这个callback函数来释放锁的, 如果我的开奖函数不需要返回值则使用这面的方法就可以。 但是我的 drawResult 这个函数会返回一个  promise, 而且我要反这个promise 再返回到上一级函数, 所以我需要 lock.acquire 能够返回 promise. 幸运的是  async-lock 也有 promise 模式, 看下面的例子。


[javascript]  
        // promise 模式会返回一个 promise, 在 promise 模式中, 不需要传入
        // done 这个 callback 去释放锁, 锁会自动被释放
        return lock.acquire(key, function () {
          // return value or promise
          // async work
          console.log("got lock" + uuid);
          // Draw the result and modify payloads array
          // 调用 drawResult 函数, 这个函数返回一个 promise
          // 这样 promise 里面的 payloads 可以被传到上一级函数
          return DrawCommon.drawResult(draw, payloads, payload5, uuid);
          //这里timeout 设定了多久超时, 如果5秒内拿不到锁就超时
        }, {timeout: 5000}).catch(function(err) {
          // 超时后会跑这里面的代码
            console.log(err.message); // output: error
        });


[/javascript]  


--
Feng

Use fiddler to do quick load testing

I rewrote my Telegram draw bot @fengdrawbot using nodejs express recently. Although I  used async-lock in the critical piece of code.  It didn't work well. The code draw multiple times if many people join the draw at the same time and reach the threshold number.

To debug this, I need a tool to simulate the heavy load in a short period of time. I tried Postman's runner,  it only runs the requests sequentially, which doesn't meet my purpose.

As I only need to simulate around 10 requests sent simultaneously, Fiddler fit this role very well. I used its composer to generate the request, then sent it.  The response came back correctly. I then selected the request and pressed "R" on the keyboard to resend it a few more times. Now I have around 10 same request in fiddler's history. I then selected all these 10 requests with "Shift" key + mouse. Then I pressed R to rerun all these requests simultaneously, issue reproduced.

Ok, now I have to debug and find out the problem then fix it.













--
Feng

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.