Skip to content

Instantly share code, notes, and snippets.

@wujcheng
wujcheng / nginx-dynamic-cache.conf
Created August 26, 2018 02:42 — forked from ericksond/nginx-dynamic-cache.conf
nginx dynamic caching using proxy_store with reverse-proxy fallback
# servers to proxy to
upstream servers {
server 10.0.0.1;
server 10.0.0.2;
}
server {
listen 80;
server_name www.domain.com;
server_name www2.domain.com
tier1.sources = filename-source1
tier1.channels = channel1
tier1.sinks = hdfs-sink1
tier1.channels.channel1.type = file
tier1.channels.channel1.checkpointDir = /mnt/data/tenny/flume/checkpoint
tier1.channels.channel1.dataDirs = /mnt/data/tenny/flume/data
tier1.channels.channel1.capacity = 1000000
tier1.channels.channel1.transactionCapacity = 10000

#Shadowsocks服务端性能优化(CentOS6)

##ss加密算法 常用算法aes-256-cfb速度较慢,在路由器等arm平台表现不佳。 用于arm平台时,采用算法rc4-md5即可。 "method":"rc4-md5" 为加速加密速度,安装m2crypto

yum install m2crypto
@wujcheng
wujcheng / merge-cidr.pl
Created August 23, 2018 00:23 — forked from wongsyrone/merge-cidr.pl
merge-cidr.pl
#!/usr/bin/perl
## ArchLinux install package via pacman: perl-net-cidr-lite
use strict;
use warnings;
use Net::CIDR::Lite;
my $cidr = Net::CIDR::Lite->new;
while (my $line=<>) {
$cidr->add($line);
}
foreach my $line( @{$cidr->list} ) {
@wujcheng
wujcheng / cidr.py
Created August 23, 2018 00:23 — forked from toringe/cidr.py
Merge CIDR blocks into super blocks if possible
#!/usr/bin/env python
#
# Example 1: All blocks in list.txt, one CIDR per line
# cat list.txt | cidr.py
#
# Example 2: Echo CIDR blocks to stdout
# echo 1.2.3.0/25 1.2.3.128/25 | cidr.py
import sys
from netaddr import *
@wujcheng
wujcheng / chnroute_update.txt
Created August 23, 2018 00:19 — forked from lixingcong/chnroute_update.txt
chinaroute路由表更新命令
路由表使用cidrmerge进行合并
cat route.txt| cidrmerge > route_merged.txt
ChinaRoute ipv4路由表
wget -O- 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | awk -F\| '/CN\|ipv4/ { printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > /tmp/route.txt
Adblock_china_easylist去广告:
wget -4 --no-check-certificate -O - https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt | grep -E '^\|\|[^\*]*\^$' | sed -e 's:||:address\=\/:' -e 's:\^:/127\.0\.0\.1:' | sort | uniq > /tmp/adblock.conf
AdAway去广告:大体积版本:2.1MB...注意这个ad_server.txt行尾是DOS,这里使用sed替换为Unix!
#!/bin/sh
export PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/bin"
# download chnroute, if faied, then stop
echo "* * * begin"
curl 'http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | grep ipv4 | grep CN | awk -F\| '{ printf("%s/%d\n", $4, 32-log($5)/log(2)) }' > chnroute.txt && echo "chnroute.txt generated" || exit 1
# use cidrmerge to compress chnroute, if tailed, then exit
cat chnroute.txt | cidrmerge > chnroute.lite.txt && echo "chnroute.lite.txt generated" || exit 1
# generate new chnroute-action to use with ~/bin/acd
rm -f chnroute-action
while read cnip ; do echo "route -nq \${_action} ${cnip} \${current_gw}" >> chnroute-action ; done < chnroute.lite.txt && echo "chnroute-action generated, copy them to the script"
@wujcheng
wujcheng / apnic_pku.sh
Created August 23, 2018 00:17 — forked from lsylsy2/apnic_pku.sh
从APNIC下载中国IP,并挑出免费地址
#!/bin/bash
echo "Downloading IP list from APNIC...."
apniclist=`wget -q -O- http://ftp.apnic.net/stats/apnic/delegated-apnic-latest |grep "apnic|CN|ipv4|"`
echo "Checking blocks..."
rm cidr.txt
for ipblock in ${apniclist[@]}
do
ip=`echo $ipblock | cut -d "|" -f4`
@wujcheng
wujcheng / setup_proxy.sh
Created August 20, 2018 16:05 — forked from RichardBronosky/setup_proxy.sh
transparent proxy on a router
#!/usr/bin/env sh
PROXY_PORT=8080
if uname -a | grep -iq 'linux'; then
# Since the "ip route" command only changes the destination IP, it still comes in port 80 and must be rerouted (unless you run your proxy on port 80)
iptables --append PREROUTING --table nat --in-interface eth0 --protocol tcp --destination-port 80 -j REDIRECT --to-port $PROXY_PORT
else
# or on a Mac...
ipfw add 100 fwd 127.0.0.1,$PROXY_PORT tcp from any to me 80
fi
@wujcheng
wujcheng / nginx.conf
Created August 19, 2018 17:20 — forked from huacnlee/nginx.conf
Nginx http proxy cache to mirror of Rubygems.org
# 在本地服务器建立 rubygems.org 的镜像缓存,以提高 gem 的安装速度
# 此配置设置缓存过期为1天,也就是说,新上的 gem 无法马上安装
# 做这个起什么作用?
# rubygems 的很多资源文件是存放到 Amazon S3 上面的,由于 GFW 对某些 S3 服务器又连接重置或丢包,导致 gem 安装异常缓慢或有时候根本无法连接安装。
# 而通过这种跳板的方式可以很好的解决这个问题,当然前提是 Nginx反向代理 服务器需要在国外
proxy_cache_path /var/cache/rubygems levels=1:2 keys_zone=RUBYGEMS:10m
inactive=24h max_size=1g;
server {
listen 80;