Visoon's Blog

会扯淡的程序猿


  • 首页

  • 标签

  • 分类

  • 归档

Trojan配置

发表于 2020-03-12 | 分类于 Trojan

服务器配置:

  1. sudo bash -c “$(curl -fsSL https://raw.githubusercontent.com/johnrosen1/trojan-gfw-script/master/vps.sh)"

Android端:

  1. https://github.com/trojan-gfw/igniter

Win端:

  1. https://github.com/trojan-gfw/trojan/releases

chrome端:

  1. https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif

VUE遇到的问题

发表于 2019-12-28 | 分类于 NODEJS , VUE

运行时遇到的问题

  1. Uncaught TypeError: Cannot assign to read only property ‘exports’ of object ‘#‘ at Module.eval (BaseClient.js?e917:12)

    原因:根据字面意思,猜测是解析JS的时候不认识 exports

    解决:/build/webpack.base.conf.js 中,注释下面代码

    1
    2
    3
    4
    5
    6
    {
    test: /\.js$/,
    loader: 'babel-loader',
    // include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')],
    include: [resolve('src'), resolve('test')]
    },

Djaong Rest 返回格式化后的时间

发表于 2019-01-15 | 分类于 Django , Python
  1. Django 中我们一般时间是这样写的,返回的格式太长了,一般前端显示不需要这么长

    # models
    create_time = models.DateTimeField(blank=True, auto_now_add=True, null=True)
    
  2. 在序列化类中重写你需要格式化的对象

    TestSerializer(serializers.ModelSerializer):
        create_time = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S", required=False, read_only=True)
    
        class Meta:
            model = Test
            fields = '__all__'
    
  3. 如果返回的时间是默认时区,需要在setting文件中修改一下时区

    LANGUAGE_CODE = 'zh-cn'
    
    TIME_ZONE = 'Asia/Shanghai'
    

Ubuntu配置V2Ray和BBR加速(最新技术,比SS和SSR更抗封锁)

发表于 2018-07-26 | 分类于 Shadowsocks
  1. 安装V2Ray

    bash <(curl -s -L https://233blog.com/v2ray.sh)
    
  2. 如果提示 curl: command not found ,那是因为你的服务器没装 Curl(没出错就跳过,出错就装这个然后重复1)

    ubuntu/debian 系统安装 Curl 方法: 
    apt-get update -y && apt-get install curl -y
    centos 系统安装 Curl 方法: 
    yum update -y && yum install curl -y
    
  3. 安装,不懂的话一路默认就好了

  4. 启动BBR,一般已经集成到了ubuntu 18.04里

    sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
    
    sed -i '/net.ipv4.tcp_congestion_control/d' /etc/sysctl.conf
    
    echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
    
    echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
    
    sysctl -p
    
  5. 把刚才安装V2Ray后给出的参数填入你的V2Ray客户端,即可上网。(一般重要参数如下)

    服务器地址(Address):
    端口(Port):
    用户ID(id):
    额外ID(alterID):
    加密方式(security):
    传输协议(netword):
    

Ubuntu部署SS和BBR加速

发表于 2018-04-11 | 分类于 Shadowsocks
  1. 首先你需要安装 python3
  2. 然后你需要安装 fabric3
     pip install fabric3
    
  3. 复制下面代码,保存到 fabfile.py (注意修改里面的hosts为你的服务器ip,password为你的服务器密码)
  4. 执行 fab deploy

    from fabric.api import *

“””
自动部署SS和BBR加速的Python3脚本
“””

env.user = ‘root’
env.password = ‘q,Q1%ySN6)f#cr7-‘
env.hosts = [‘140.82.36.100’] # 如果有多个主机,fabric会自动依次部署
#
env.current_ip = 0 # 当前执行到的ip

“””
常用命令

lcd(dir): 进入本机某目录
local(cmd): 本机上执行命令
cd(dir): 进入服务器某目录
run(cmd):服务器上执行命令

运行:
fab deploy
“””

def deploy():

# 部署SS
shadowsocks = """
{
    "server":"%s",
    "server_port":8388,
    "local_port":1080,
    "password":"plover.cloud",
    "timeout":600,
    "method":"aes-256-cfb"
}
""" % env.hosts[env.current_ip]
env.current_ip += 1
run("echo '%s' > /root/shadowsocks.json " % shadowsocks)
run("sudo apt-get update")
run("sudo apt-get install -y python-gevent python-pip -y")
run("sudo pip install setuptools")
run("sudo pip install shadowsocks")
run("sudo apt-get install -y python-m2crypto -y")
run("ssserver -c /root/shadowsocks.json -d start")
# 部署 BBR
run("wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh")
run("chmod +x bbr.sh")
run("./bbr.sh")

如果你觉得以上操作太复杂了。请注意看下面。
1. 请到我的应用:www.plover.cloud 中注册一个账号。
2. 然后在我的->SS里面->创建新的服务器,输入IP账号密码,即可一键搭建完成。

Djaong问题与解决方案一览

发表于 2018-03-28 | 分类于 Django , Python
  1. Django 拓展 User 表

    model中继承 AbstractUser:
    class User(AbstractUser)
    
    settings中添加:
    AUTH_USER_MODEL = 'app_user.User'
    
  2. settings按照环境自动选择数据库

    # 服务器本地环境
    DATABASES = {}
    if 'runserver' in sys.argv:
        print('使用远程数据库')
        ....省略代码....
    if 'test' in sys.argv:
        print('使用测试数据库')
        ....省略代码....
    
  3. django rest serializer 创建前调用

    例如创建前调用设置用户密码
    class UserCreateSerializer(serializers.ModelSerializer):
       class Meta:
           model = User
           fields = ('id', 'username', 'email', 'phone', 'password')
    
       def create(self, data):
           user = User(**data)
           user.set_password(data['password'])
           user.save()
           return user
    

Linux部署SSR

发表于 2018-03-08 | 分类于 Shadowsocks

首先,你需要一台运行在国外的服务器。
然后一行行运行下面脚本

wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocksR.sh
chmod +x shadowsocksR.sh
./shadowsocksR.sh 2>&1 | tee shadowsocksR.log

安装完成后,脚本提示如下:

Congratulations, ShadowsocksR server install completed!
Your Server IP        :your_server_ip
Your Server Port      :your_server_port
Your Password         :your_password
Your Protocol         :your_protocol
Your obfs             :your_obfs
Your Encryption Method:your_encryption_method

Welcome to visit:https://shadowsocks.be/9.html
Enjoy it!

卸载方法:
使用 root 用户登录,运行以下命令:

./shadowsocksR.sh uninstall

安装完成后即已后台启动 ShadowsocksR ,运行:

/etc/init.d/shadowsocks status

可以查看 ShadowsocksR 进程是否已经启动。
本脚本安装完成后,已将 ShadowsocksR 自动加入开机自启动。

使用命令:
启动:/etc/init.d/shadowsocks start
停止:/etc/init.d/shadowsocks stop
重启:/etc/init.d/shadowsocks restart
状态:/etc/init.d/shadowsocks status

配置文件路径:/etc/shadowsocks.json
日志文件路径:/var/log/shadowsocks.log
代码安装目录:/usr/local/shadowsocks

多用户配置示例:

{
"server":"0.0.0.0",
"server_ipv6": "[::]",
"local_address":"127.0.0.1",
"local_port":1080,
"port_password":{
    "8989":"password1",
    "8990":"password2",
    "8991":"password3"
},
"timeout":300,
"method":"aes-256-cfb",
"protocol": "origin",
"protocol_param": "",
"obfs": "plain",
"obfs_param": "",
"redirect": "",
"dns_ipv6": false,
"fast_open": false,
"workers": 1
}

如果你想修改配置文件,请参考:
https://github.com/shadowsocksr-backup/shadowsocks-rss/wiki/Server-Setup
https://github.com/shadowsocksr-backup/shadowsocks-rss/blob/master/ssr.md
https://github.com/shadowsocksr-backup/shadowsocks-rss/wiki/config.json

【IONIC2+】生命周期

发表于 2018-02-27 | 分类于 JAVASCRIPT , IONIC2+

IONIC2+ 的生命周期

  1. ionViewLoaded

    页面加载完毕触发。该事件发生在页面被创建成 DOM 的时候,且仅仅执行一次。如果页面被缓存(Ionic默认是缓存的)就不会再次触发该事件。该事件中可以放置初始化页面的一些事件。
    
  2. ionViewWillEnter

    即将进入一个页面变成当前激活页面的时候执行的事件。
    
  3. ionViewDidEnter

    进入了一个页面且变成了当前的激活页面,该事件不管是第一次进入还是缓存后进入都将执行。
    
  4. ionViewWillLeave

    将要离开了该页面之后变成了不是当前激活页面的时候执行的事件。
    
  5. ionViewDidLeave

    在页面完成了离开该页面并变成了不是当前激活页面的时候执行的事件。
    
  6. ionViewWillUnload

    在页面销毁和页面中有元素移除之前执行的事件。
    
  7. ionViewDidUnload

    在页面销毁和页面中有元素移除之后执行的事件。
    

Windows下快速删除Nodejs项目

发表于 2017-12-06 | 分类于 Nodejs

项目说明

  • 删除一个Node项目在Windows下面是一件非常操蛋的事情

删除工具

npm install rimraf -g
rimraf node_modules

直接Powershell删除

如删除 D:\temp\目录下的所有文件的写法如下:
rmdir d:\temp\

Ubuntu使用KCPRAW伪装UDP请求,防止运营商拦截

发表于 2017-11-21 | 分类于 Shadowsocks

kcptun

kcptun

-

原因及原理

因为KCP多倍发包原理,有些地方运营商会拦截多倍的UDP请求,使用KCPRAW可以把UDP伪装成TCP流量,防止运营商拦截

快速设定

客户端、服务器分别下载对应平台的预编译版本,并解压,通过下面的命令启动端口转发。

1
2
KCP客户端: ./client_darwin_amd64 -r "KCP服务器IP地址:4000" -l ":8388" -mode fast2
KCP服务器: ./server_linux_amd64 -t "目标服务器IP地址:8388" -l ":4000" -mode fast2

以上命令可以实现8388/tcp端口的转发(通过4000/udp端口),即:

Application -> KCP客户端(8388/tcp) -> KCP服务器(4000/udp) -> Server(8388/tcp)

从源码安装

1
2
$go get -u github.com/xtaci/kcptun/client
$go get -u github.com/xtaci/kcptun/server

注意: 如果出现错误提示,请确保依赖库能正确访问到。

Release中的所有二进制版本,是通过 build-release.sh 脚本生成并优化。

速度对比

fast.com

  • 测速网站: https://fast.com
  • 接入速度: 100Mbps
  • WIFI: 5GHz TL-WDR3320

使用方法

在Mac OS X El Capitan下的帮助输出,注意默认值:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
$ ./client_darwin_amd64 -h
NAME:
kcptun - client(with SMUX)

USAGE:
client_darwin_amd64 [global options] command [command options] [arguments...]

VERSION:
20170120

COMMANDS:
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--localaddr value, -l value local listen address (default: ":12948")
--remoteaddr value, -r value kcp server address (default: "vps:29900")
--key value pre-shared secret between client and server (default: "it's a secrect") [$KCPTUN_KEY]
--crypt value aes, aes-128, aes-192, salsa20, blowfish, twofish, cast5, 3des, tea, xtea, xor, none (default: "aes")
--mode value profiles: fast3, fast2, fast, normal (default: "fast")
--conn value set num of UDP connections to server (default: 1)
--autoexpire value set auto expiration time(in seconds) for a single UDP connection, 0 to disable (default: 0)
--mtu value set maximum transmission unit for UDP packets (default: 1350)
--sndwnd value set send window size(num of packets) (default: 128)
--rcvwnd value set receive window size(num of packets) (default: 512)
--datashard value, --ds value set reed-solomon erasure coding - datashard (default: 10)
--parityshard value, --ps value set reed-solomon erasure coding - parityshard (default: 3)
--dscp value set DSCP(6bit) (default: 0)
--nocomp disable compression
--snmplog value collect snmp to file, aware of timeformat in golang, like: ./snmp-20060102.log
--snmpperiod value snmp collect period, in seconds (default: 60)
--log value specify a log file to output, default goes to stderr
-c value config from json file, which will override the command from shell
--help, -h show help
--version, -v print the version

$ ./server_darwin_amd64 -h
NAME:
kcptun - server(with SMUX)

USAGE:
server_darwin_amd64 [global options] command [command options] [arguments...]

VERSION:
20170120

COMMANDS:
help, h Shows a list of commands or help for one command

GLOBAL OPTIONS:
--listen value, -l value kcp server listen address (default: ":29900")
--target value, -t value target server address (default: "127.0.0.1:12948")
--key value pre-shared secret between client and server (default: "it's a secrect") [$KCPTUN_KEY]
--crypt value aes, aes-128, aes-192, salsa20, blowfish, twofish, cast5, 3des, tea, xtea, xor, none (default: "aes")
--mode value profiles: fast3, fast2, fast, normal (default: "fast")
--mtu value set maximum transmission unit for UDP packets (default: 1350)
--sndwnd value set send window size(num of packets) (default: 1024)
--rcvwnd value set receive window size(num of packets) (default: 1024)
--datashard value, --ds value set reed-solomon erasure coding - datashard (default: 10)
--parityshard value, --ps value set reed-solomon erasure coding - parityshard (default: 3)
--dscp value set DSCP(6bit) (default: 0)
--nocomp disable compression
--snmplog value collect snmp to file, aware of timeformat in golang, like: ./snmp-20060102.log
--snmpperiod value snmp collect period, in seconds (default: 60)
--log value specify a log file to output, default goes to stderr
-c value config from json file, which will override the command from shell
--help, -h show help
--version, -v print the version

分层参数图

params

两端参数必须一致的有:

  • datashard –前向纠错
  • parityshard –前向纠错
  • nocomp –压缩
  • key –密钥
  • crypt –加密算法

其余为两边可独立设定的参数

内置模式

响应速度:
fast3 > fast2 > [fast] > normal > default
有效载荷比:
default > normal > [fast] > fast2 > fast3
中间-mode参数比较均衡,总之就是越快,包重传越激进。
更高级的 手动档 需要理解KCP协议,并通过 隐藏参数 调整,例如:

1
-mode manual -nodelay 1 -resend 2 -nc 1 -interval 20

  • 搭配1. fast + FEC(5,5)
  • 搭配2. fast2 + FEC(10,3)
  • 搭配3. fast2 + FEC(0,0)

默认profile参考: https://github.com/xtaci/kcptun/blob/master/client/main.go#L248

前向纠错

前向纠错采用Reed Solomon纠删码, 它的基本原理如下: 给定n个数据块d1, d2,…, dn,n和一个正整数m, RS根据n个数据块生成m个校验块, c1, c2,…, cm。 对于任意的n和m, 从n个原始数据块和m 个校验块中任取n块就能解码出原始数据, 即RS最多容忍m个数据块或者校验块同时丢失。

reed-solomon

通过参数

n -parityshard m``` 在两端同时设定。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

数据包发送顺序严格遵循: n个datashard紧接m个parityshard,重复。

注意:为了发挥FEC最佳效果,设置 parityshard/(parity+datashard) > packet loss,比如5/(5+5) > 30%

### 窗口调整
**简易窗口自我调优方法**:

> 第一步:同时在两端逐步增大client rcvwnd和server sndwnd;
> 第二步:尝试下载,观察如果带宽利用率(服务器+客户端两端都要观察)到达预期则停止,否则跳转到第一步。

**注意:产生大量重传时,一定是窗口偏大了**

### 安全

无论你上层如何加密,如果```-crypt none```,那么**协议头部**都是**明文**的,建议至少采用```-crypt aes-128```加密,并修改密码。

密码可以通过`-key`指定,也可以通过环境变量`KCPTUN_KEY`指定。

注意: ```-crypt xor``` 也是不安全的,除非你知道你在做什么。

附加密速度Benchmark:

BenchmarkAES128-4 200000 11182 ns/op
BenchmarkAES192-4 200000 12699 ns/op
BenchmarkAES256-4 100000 13757 ns/op
BenchmarkTEA-4 50000 26441 ns/op
BenchmarkSimpleXOR-4 3000000 441 ns/op
BenchmarkBlowfish-4 30000 48036 ns/op
BenchmarkNone-4 20000000 106 ns/op
BenchmarkCast5-4 20000 60222 ns/op
BenchmarkTripleDES-4 2000 878759 ns/op
BenchmarkTwofish-4 20000 68501 ns/op
BenchmarkXTEA-4 20000 77417 ns/op
BenchmarkSalsa20-4 300000 4998 ns/op

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

### 内存控制

路由器,手机等嵌入式设备通常对**内存用量敏感**,通过调节环境变量GOGC(例如GOGC=20)后启动client,可以降低内存使用。
参考:https://blog.golang.org/go15gc


### DSCP

DSCP差分服务代码点(Differentiated Services Code Point),IETF于1998年12月发布了Diff-Serv(Differentiated Service)的QoS分类标准。它在每个数据包IP头部的服务类别TOS标识字节中,利用已使用的**6比特**和未使用的2比特,通过编码值来区分优先级。
常用DSCP值可以参考[Wikipedia DSCP](https://en.wikipedia.org/wiki/Differentiated_services#Commonly_used_DSCP_values),至于有没有用,完全取决于数据包经过的设备。

通过 ```-dscp ``` 参数指定dscp值,两端可分别设定。

注意:设置dscp不一定会更好,需要尝试。

### Snappy数据流压缩

> Snappy is a compression/decompression library. It does not aim for maximum
> compression, or compatibility with any other compression library; instead,
> it aims for very high speeds and reasonable compression. For instance,
> compared to the fastest mode of zlib, Snappy is an order of magnitude faster
> for most inputs, but the resulting compressed files are anywhere from 20% to
> 100% bigger.

> Reference: http://google.github.io/snappy/

压缩对于非加密,非压缩的数据能降低传输数据量,比如点对点的HTTP数据转发。

通过参数 ```-nocomp``` 在两端同时设定以关闭压缩。
> 提示: 关闭压缩可能会降低延迟。

### 流量控制

**必要性: 针对流量敏感的服务器,做双保险。**

> 基本原则: SERVER的发送速率不能超过ADSL下行带宽,否则只会浪费您的服务器带宽。

在server通过linux tc,可以限制服务器发送带宽。
举例: 用linux tc限制server发送带宽为32mbit/s:

root@kcptun:~# cat tc.sh
tc qdisc del dev eth0 root
tc qdisc add dev eth0 root handle 1: htb
tc class add dev eth0 parent 1: classid 1:1 htb rate 32mbit
tc filter add dev eth0 protocol ip parent 1:0 prio 1 handle 10 fw flowid 1:1
iptables -t mangle -A POSTROUTING -o eth0 -j MARK –set-mark 10
root@kcptun:~#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
其中eth0为网卡,有些服务器为ens3,有些为p2p1,通过ifconfig查询修改。

### SNMP

```go
// Snmp defines network statistics indicator
type Snmp struct {
BytesSent uint64 // raw bytes sent
BytesReceived uint64
MaxConn uint64
ActiveOpens uint64
PassiveOpens uint64
CurrEstab uint64 // count of connections for now
InErrs uint64 // udp read errors
InCsumErrors uint64 // checksum errors from CRC32
KCPInErrors uint64 // packet iput errors from kcp
InSegs uint64
OutSegs uint64
InBytes uint64 // udp bytes received
OutBytes uint64 // udp bytes sent
RetransSegs uint64
FastRetransSegs uint64
EarlyRetransSegs uint64
LostSegs uint64 // number of segs infered as lost
RepeatSegs uint64 // number of segs duplicated
FECRecovered uint64 // correct packets recovered from FEC
FECErrs uint64 // incorrect packets recovered from FEC
FECSegs uint64 // FEC segments received
FECShortShards uint64 // number of data shards that's not enough for recovery
}

使用

-SIGUSR1 pid``` 可以在控制台打印出SNMP信息,通常用于精细调整**当前链路的有效载荷比**。
1
2
3
观察```RetransSegs,FastRetransSegs,LostSegs,OutSegs```这几者的数值比例,用于参考调整```-mode manual,fec```的参数。    

#### 带宽计算公式

在不丢包的情况下,有最大-rcvwnd 个数据包在网络上正在向你传输,以平均数据包大小avgsize计算,在任意时刻,有:

network_cap = rcvwnd*avgsize

数据流向你,这个值再除以ping值(rtt),等于最大带宽使用量。

max_bandwidth = network_cap/rtt = rcvwnd*avgsize/rtt

举例,设rcvwnd = 1024, avgsize = 1KB, rtt = 400ms,则:

max_bandwidth = 1024 * 1KB / 400ms = 2.5MB/s ~= 25Mbps

(注:以上计算不包括前向纠错的数据量)

前向纠错是最大带宽量的一个固定比例增加:

max_bandwidth_fec = max_bandwidth*(datashard+parityshard)/datashard

举例,设datashard = 10 , partiyshard = 3,则:

max_bandwidth_fec = max_bandwidth * (10 + 3) /10 = 1.3*max_bandwidth = 1.3 * 25Mbps = 32.5Mbps

`

故障排除

Q: 客户端和服务器端皆无 stream opened信息。
A: 连接客户端程序的端口设置错误。

Q: 客户端有 stream opened信息,服务器端没有。
A: 连接服务器的端口设置错误,或者被防火墙拦截。

Q: 客户端服务器皆有 stream opened信息,但无法通信。
A: 上层软件的设定错误。

免责申明

用户以各种方式使用本软件(包括但不限于修改使用、直接使用、通过第三方使用)的过程中,不得以任何方式利用本软件直接或间接从事违反中国法律、以及社会公德的行为。软件的使用者需对自身行为负责,因使用软件引发的一切纠纷,由使用者承担全部法律及连带责任。作者不承担任何法律及连带责任。

对免责声明的解释、修改及更新权均属于作者本人所有。

特别鸣谢

GITHUB上的各位大佬,就不打名字了

好人一生平安!

123
Visoon

Visoon

多动脑,少动手

26 日志
18 分类
15 标签
RSS
友情链接
  • K . J Blog
© 2020 Visoon
由 Hexo 强力驱动
|
主题 — NexT.Gemini v5.1.3