Stop

Stop, 是一个行程的中止。

Stop,也是一个站点,下车,上车,继续前进。

2010.6 - 2018.5.

Nginx + Websocket

upstream ws {
    server 127.0.0.1:8080;
    server 127.0.0.1:8081;
}

server {
    listen  8090;

    location / {
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_pass http://ws;
    }
}

在 Nginx reload 的时候,socket 连接并不会中断。

Quote

什么都不放弃实际上是怕放弃后自己什么都没有,无所畏惧的人生要敢于放弃。

via

Linux Performance Analysis in 60s

uptime/w --------------------> load average
dmesg | tail ----------------> kernel errors
vmstat 1 --------------------> overall stats every second
mpstat -P ALL 1 -------------> CPU balance
pidstat 1 -------------------> process usage, every second
iostat -xz 1 ----------------> disk I/O
free -m ---------------------> memory usage
sar -n DEV 1 ----------------> network I/O
sar -n TCP,ETCP 1 -----------> TCP stats
top -------------------------> check overview

dmidecode

You can use dmidecode to display server physical info, for example RAM max capacity.

dmidecode -t 16

Handle 0x0032, DMI type 16, 15 bytes
Physical Memory Array
	Location: System Board Or Motherboard
	Use: System Memory
	Error Correction Type: Multi-bit ECC
	Maximum Capacity: 48 GB
	Error Information Handle: Not Provided
	Number Of Devices: 6

App Store Front Code

X-Apple-Store-Front header is needed to scrape in App Store.

CN 143465-19,29
US 143441-1,29
JP 143462-9,29
KR 143466-13,29
HK 143463-18,29
AU 143460,29
TW 143470-18,29
CA 143455-6,29

App info:

curl -H 'x-apple-store-front: 143465-19,29' 'https://itunes.apple.com/cn/app/id1318151064?mt=8'

Top Free iPhone Apps:

curl -H 'x-apple-store-front: 143465-0,9' 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/topChartFragmentData?=&popId=27&pageNumbers=0&pageSize=1000'

curl -H 'x-apple-store-front: 143465-19,29' 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewTop?id=25204&popId=27&genreId=36'

Nginx map

map $room $room_server {
    default 192.168.1.101:8080;
    1 192.168.1.101:8080;
    2 192.168.1.102:8080;
}

server {
    listen  80;

    location ~ /api/(\d+)/room {
        set $room $1;
        echo $room_server;
    }
}

Shell Notes

&& || ; in shell command:

  • cmd1 && cmd2 means cmd2 will only run while cmd1 success.
  • cmd1 || cmd2 means cmd2 will only run while fmd1 fails.
  • cmd1 ; cmd2 will run cmd2 regardless cmd1 success or not.

通过 Debian Snapshot 安装旧版本包

某个项目需要 PHP 5.3 支持,通过 APT 没办法直接安装,编译安装又是一大堆依赖,最后通过 Debian Snapshot 解决。

  1. http://snapshot.debian.org/ 搜索需要的包, 比如 php5
  2. Got http://snapshot.debian.org/archive/debian-ports/20120225T023111Z/pool-m68k/main/p/php5/
  3. 添加到 source.list:
deb http://snapshot.debian.org/archive/debian/20120225T023111Z/ unstable main
deb-src http://snapshot.debian.org/archive/debian/20120225T023111Z/ unstable main
  1. apt-get -o Acquire::Check-Valid-Until=false update
  2. apt-get install php5=5.3.10-2 php5-fpm php5-cgi, done.

docker-compose for MySQL + phpMyAdmin

version: '3'
services:
  mysql:
    image: 'mysql:5'
    container_name: 'mysql'
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --init-connect='SET NAMES UTF8;'
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: 'test'
  phpmyadmin:
    image: 'phpmyadmin/phpmyadmin'
    container_name: 'phpmyadmin'
    links:
      - mysql
    ports:
      - '8080:80'
    environment:
      PMA_HOST: mysql