<commit_before>---
bg: "dance.jpg"
layout: post
title: "mac配置ss记录"
summary: ""
tags: ['mac']
categories: mac
---

习惯使用Google，就不想用用百度了，fck the fw，走清末闭关政策，买的付费tunnel又不靠谱，而且还有隐私/安全问题，无奈只能自己搭一个了

[1 服务器](#vps)

[2 服务端](#server)

[3 客户端](#client)

#### 1 服务器 {#vps}

服务器可以选择AWS，阿里云，或者国外的一些VPS，只要买国外区域的，配置1c1g，加一个公网IP(EIP) 就好了，然后登录方式选择密钥登录，取消密码登录

#####1.1 配置系统参数

Create `/etc/sysctl.d/local.conf` with the following content:

```shell
# max open files
fs.file-max = 51200
# max read buffer
net.core.rmem_max = 67108864
# max write buffer
net.core.wmem_max = 67108864
# default read buffer
net.core.rmem_default = 65536
# default write buffer
net.core.wmem_default = 65536
# max processor input queue
net.core.netdev_max_backlog = 4096
# max backlog
net.core.somaxconn = 4096

# resist SYN flood attacks
net.ipv4.tcp_syncookies = 1
# reuse timewait sockets when safe
net.ipv4.tcp_tw_reuse = 1
# turn off fast timewait sockets recycling
net.ipv4.tcp_tw_recycle = 0
# short FIN timeout
net.ipv4.tcp_fin_timeout = 30
# short keepalive time
net.ipv4.tcp_keepalive_time = 1200
# outbound port range
net.ipv4.ip_local_port_range = 10000 65000
# max SYN backlog
net.ipv4.tcp_max_syn_backlog = 4096
# max timewait sockets held by system simultaneously
net.ipv4.tcp_max_tw_buckets = 5000
# turn on TCP Fast Open on both client and server side
net.ipv4.tcp_fastopen = 3
# TCP receive buffer
net.ipv4.tcp_rmem = 4096 87380 67108864
# TCP write buffer
net.ipv4.tcp_wmem = 4096 65536 67108864
# turn on path MTU discovery
net.ipv4.tcp_mtu_probing = 1

# for high-latency network
net.ipv4.tcp_congestion_control = hybla

# for low-latency network, use cubic instead
# net.ipv4.tcp_congestion_control = cubic
```

Then:

```
sysctl --system
```

Older system:

```shell
sysctl -p /etc/sysctl.d/local.conf
```

#### 2 服务端 {#server}

ssh登录到远端服务器

#####2.1 安装shadowsocks

```bash
pip install shadowsocks
```

#####2.2 编辑/etc/shadowsocks.json

```shell
{
    "server":"my_server_ip",
    "server_port":8388,
    "local_address": "127.0.0.1",
    "local_port":1080,
    "password":"<PASSWORD>",
    "timeout":300,
    "method":"aes-256-cfb",
    "fast_open": false
}
```

Explanation of the fields:

| Name          | Explanation                              |
| ------------- | ---------------------------------------- |
| server        | the address your server listens          |
| server_port   | server port                              |
| local_address | the address your local listens           |
| local_port    | local port                               |
| password      | password used for encryption             |
| timeout       | in seconds                               |
| method        | default: "aes-256-cfb", see [Encryption](https://github.com/shadowsocks/shadowsocks/wiki/Encryption) |
| fast_open     | use [TCP_FASTOPEN](https://github.com/shadowsocks/shadowsocks/wiki/TCP-Fast-Open), true / false |
| workers       | number of workers, available on Unix/Linux |

##### 2.3 启动server

```shell
ssserver -c /etc/shadowsocks.json -d start
```

日志默认在/var/log/shadowsocks.log

#### 3 客户端(mac) {#client}

##### 3.1 下载ShadowsocksX-NG

https://github.com/shadowsocks/ShadowsocksX-NG

输入服务端IP及配置的密码，即可连接

##### 3.2 终端配置

编辑配置文件/etc/profile

```shell
function proxy_off(){
    unset http_proxy
    unset https_proxy
    git config --global unset http.proxy 
    git config --global unset https.proxy 
    echo -e "已关闭代理"
}

function proxy_on() {
    git config --global http.proxy://github.com.proxy https://127.0.0.1:1080
    git config --global https.proxy://github.com.proxy https://127.0.0.1:1080
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    export http_proxy="http://127.0.0.1:1080"
    export https_proxy=$http_proxy
    echo -e "已开启代理"
}
proxy_on
```

source /etc/profile<commit_msg>修改ss中git配置<commit_after>---
bg: "dance.jpg"
layout: post
title: "mac配置ss记录"
summary: ""
tags: ['mac']
categories: mac
---

习惯使用Google，就不想用用百度了，fck the fw，走清末闭关政策，买的付费tunnel又不靠谱，而且还有隐私/安全问题，无奈只能自己搭一个了

[1 服务器](#vps)

[2 服务端](#server)

[3 客户端](#client)

#### 1 服务器 {#vps}

服务器可以选择AWS，阿里云，或者国外的一些VPS，只要买国外区域的，配置1c1g，加一个公网IP(EIP) 就好了，然后登录方式选择密钥登录，取消密码登录

#####1.1 配置系统参数

Create `/etc/sysctl.d/local.conf` with the following content:

```shell
# max open files
fs.file-max = 51200
# max read buffer
net.core.rmem_max = 67108864
# max write buffer
net.core.wmem_max = 67108864
# default read buffer
net.core.rmem_default = 65536
# default write buffer
net.core.wmem_default = 65536
# max processor input queue
net.core.netdev_max_backlog = 4096
# max backlog
net.core.somaxconn = 4096

# resist SYN flood attacks
net.ipv4.tcp_syncookies = 1
# reuse timewait sockets when safe
net.ipv4.tcp_tw_reuse = 1
# turn off fast timewait sockets recycling
net.ipv4.tcp_tw_recycle = 0
# short FIN timeout
net.ipv4.tcp_fin_timeout = 30
# short keepalive time
net.ipv4.tcp_keepalive_time = 1200
# outbound port range
net.ipv4.ip_local_port_range = 10000 65000
# max SYN backlog
net.ipv4.tcp_max_syn_backlog = 4096
# max timewait sockets held by system simultaneously
net.ipv4.tcp_max_tw_buckets = 5000
# turn on TCP Fast Open on both client and server side
net.ipv4.tcp_fastopen = 3
# TCP receive buffer
net.ipv4.tcp_rmem = 4096 87380 67108864
# TCP write buffer
net.ipv4.tcp_wmem = 4096 65536 67108864
# turn on path MTU discovery
net.ipv4.tcp_mtu_probing = 1

# for high-latency network
net.ipv4.tcp_congestion_control = hybla

# for low-latency network, use cubic instead
# net.ipv4.tcp_congestion_control = cubic
```

Then:

```
sysctl --system
```

Older system:

```shell
sysctl -p /etc/sysctl.d/local.conf
```

#### 2 服务端 {#server}

ssh登录到远端服务器

#####2.1 安装shadowsocks

```bash
pip install shadowsocks
```

#####2.2 编辑/etc/shadowsocks.json

```shell
{
    "server":"my_server_ip",
    "server_port":8388,
    "local_address": "127.0.0.1",
    "local_port":1080,
    "password":"<PASSWORD>",
    "timeout":300,
    "method":"aes-256-cfb",
    "fast_open": false
}
```

Explanation of the fields:

| Name          | Explanation                              |
| ------------- | ---------------------------------------- |
| server        | the address your server listens          |
| server_port   | server port                              |
| local_address | the address your local listens           |
| local_port    | local port                               |
| password      | password used for encryption             |
| timeout       | in seconds                               |
| method        | default: "aes-256-cfb", see [Encryption](https://github.com/shadowsocks/shadowsocks/wiki/Encryption) |
| fast_open     | use [TCP_FASTOPEN](https://github.com/shadowsocks/shadowsocks/wiki/TCP-Fast-Open), true / false |
| workers       | number of workers, available on Unix/Linux |

##### 2.3 启动server

```shell
ssserver -c /etc/shadowsocks.json -d start
```

日志默认在/var/log/shadowsocks.log

#### 3 客户端(mac) {#client}

##### 3.1 下载ShadowsocksX-NG

https://github.com/shadowsocks/ShadowsocksX-NG

输入服务端IP及配置的密码，即可连接

##### 3.2 终端配置

编辑配置文件/etc/profile

```shell
function proxy_off(){
    unset http_proxy
    unset https_proxy
    git config --global unset http.proxy 
    git config --global unset https.proxy 
    echo -e "已关闭代理"
}

function proxy_on() {
    git config --global http.proxy 'socks5://127.0.0.1:1080'
    git config --global https.proxy 'socks5://127.0.0.1:1080'
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
    export http_proxy="http://127.0.0.1:1080"
    export https_proxy=$http_proxy
    echo -e "已开启代理"
}
proxy_on
```

source /etc/profile
{'fraction_non_alphanumeric': 0.13971266640305785, 'fraction_numerical': 0.051667325688678004, 'mean_word_length': 3.064274236743439, 'pattern_counts': {'":': 16, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2874468', 'n_tokens_mistral': 3239, 'n_tokens_neox': 3075, 'n_words': 623}