分类 Shell 下的文章

centos nodejs upgrade

# sudo model
# remove old
cd /etc/yum.repos.d/
rm nodesource-*.repo
yum remove nodejs
# install new
# change setup_8.x to your version
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
yum clean all
yum -y install nodejs

nodejs error: socket hang up

socket hang up 的可能原因有很多,大多是服务器资源不足引起。

检查 ulimit -n (所有的 port process 资源受它限制)
sudo lsof -i|wc -l
检查 memory (内存耗尽也会出错)
free -m

新方案:
使用nginx做反向代理请求nodejs可以有效的减小甚至避免这个问题

location / {
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-NginX-Proxy true;
  proxy_set_header Host $http_host;
  
  proxy_pass http://127.0.0.0:8000; // nodejs server 
  proxy_redirect off;
}

案例:

memory error
ulimit error

Create Apache crt & key

When we request a new certificate, we can specify how long the certificate should remain valid by changing the 365 to the number of days we prefer. As it stands this certificate will expire after one year.

sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout apache.key -out apache.crt

You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.

Country Name (2 letter code) [AU]:US
State or Province Name (full name) [Some-State]:New York
Locality Name (eg, city) []:NYC
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Awesome Inc
Organizational Unit Name (eg, section) []:Dept of Merriment
Common Name (e.g. server FQDN or YOUR name) []:example.com
Email Address []:webmaster@awesomeinc.com

Mac OS X下如何分卷压缩

一朋友的公司邮箱只能接受5M的附件,还世界500强企业真心落后。无奈只能分卷压缩大文件,Mac OS X下没有盗版的WinRar可用,所以只好采用ZIP格式分卷了

创建分卷压缩文件
将目录分卷压缩

zip -s 100m -x "*.DS_Store" -r split-foo.zip foo/

-s 切分单元的大小,可选的单位有k(kB), m(MB), g(GB), t(TB),默认为m
-r 或者 --recurse-paths 递归目录
-x 或者 --exclude 忽略文件

切分已有zip文件

zip existing.zip --out new.zip -s 50m

- 阅读剩余部分 -