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.

// 29 or 26 or 9
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
DK 143458-2,29
RU 143469-16,29
ID 143476-2,29
TR 143480-2,29
GR 143448-2,29
DE 143443-4,29
IT 143450-7,29
NO 143457-2,29
FR 143442-3,29
TH 143475-2,29
SE 143456-17,29
FI 143447-2,29
GB 143444,29
NL 143452-10,29
BR 143503-15,29
PT 143453-24,29
MX 143468-28,29
ES 143454-8,29
VN 143471-2,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'

Rating & reviews:

curl -H 'x-apple-store-front: 143441-0,9'  'https://itunes.apple.com/us/customer-reviews/id284882215?dataOnly=true&displayable-kind=11'
curl -H 'x-apple-store-front: 143441-1,29' 'https://itunes.apple.com/us/customer-reviews/id284882215?dataOnly=true&displayable-kind=11'
curl -H 'x-apple-store-front: 143441-1,29' 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/userReviewsRow?id=284882215&displayable-kind=11&startIndex=0&endIndex=100&sort=1'

Search:

curl -H 'x-apple-store-front: 143441-1,29' 'https://itunes.apple.com/WebObjects/MZStore.woa/wa/search?clientApplication=Software&term=NBA'
curl -H 'x-apple-store-front: 143441-1,29' 'https://search.itunes.apple.com/WebObjects/MZSearchHints.woa/wa/trends?maxCount=10'
curl -H 'x-apple-store-front: 143465-1,29' 'https://search.itunes.apple.com/WebObjects/MZSearchHints.woa/wa/hints?clientApplication=Software&term=NBA'

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;
    }
}

split_clients 类似的结构,可以用来做请求 A/B 测试:

split_clients $arg_app_key $variant {
    0.5%    .one;
    2.0%    .two;
    *       "";
}

nginx mirroring tips and tricks

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