Skip to content

Commit

Permalink
CHG: update linux doc
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-js committed Jul 18, 2024
1 parent 4b87e80 commit 770148e
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 67 deletions.
35 changes: 35 additions & 0 deletions linux/0-3-install-vm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# install VirtualMachine

Both WSL1 and WSL2 add some weird network & fs hack to smuggle data ins and outs.

So use HyperV directly (or other VM software like VirtualBox) can be better when config dives deeper,
and backup/reuse is easier as whole system is in one huge file.

The idea is config a VM with an additional local 10.42.1.X network, for host to,
everything else is by default separated, like net & fs.

So this VM will have two network switch/device connected:
- an external network, random ip, for connect to Internet
- a internal/local network, on 10.42.1.X ip range: gate at 10.42.1.0, host should be at 10.42.1.1 and VM at 10.42.1.2

Here are the additional config required in VM linux:

```shell
# /etc/systemd/network/00-local-10.42.1.2.network

[Match]
MACAddress=00:00:22:22:44:44
# Name=eth1
# Name=enp0s8

[Network]
DHCP=no
LinkLocalAddressing=no

[Address]
Address=10.42.1.2/24
Scope=host
```

Note in the `Match` section, a static mac address is simpler to set from host side,
the net device name may change.
8 changes: 4 additions & 4 deletions linux/7-0-nodejs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ install `nodejs` and `npm`:
# so the DIY install here will only use npm self update
mkdir ~/DIY_NPM/
( cd ~/DIY_NPM/
wget https://registry.npmjs.org/npm/-/npm-8.12.1.tgz # find latest version from: npm.im/npm, or with: `npm view npm`
wget https://registry.npmjs.org/npm/-/npm-9.9.3.tgz # find latest version from: npm.im/npm, or with: `npm view npm`
tar xf ./*.tgz # extract
sudo mkdir -p /usr/lib/node_modules/ # `sudo rm -rf /usr/lib/node_modules/`
sudo cp -rT ./package /usr/lib/node_modules/npm
Expand All @@ -22,14 +22,14 @@ install `nodejs` and `npm`:
rm -rf ~/DIY_NPM/
)

( # debian/ubuntu, check: https://github.com/nodesource/distributions/blob/master/README.md#debinstall
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - # common node.js install
( # debian/ubuntu, check: https://github.com/nodesource/distributions/blob/master/README.md#using-debian-as-root-nodejs-22
curl -sL https://deb.nodesource.com/setup_22.x | sudo -E bash - # common node.js install
sudo apt-get install nodejs -y
)

# stop npm spawn many un-finishing update checking process
sudo npm config set --global update-notifier false # for `sudo npm i -g`
```

cn mirror: https://mirrors.tuna.tsinghua.edu.cn/help/nodesource/
cn mirror: https://npmmirror.com/
optionally setup `npm` proxy through `shadowsocks + privoxy`, check: `./8-9-proxy-config.md`
105 changes: 48 additions & 57 deletions linux/8-0-shadowsocks-privoxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,7 @@
## install `shadowsocks`

install `shadowsocks-rust`: (check https://github.com/shadowsocks/shadowsocks-rust/releases)
```shell script
( mkdir -p "/opt/dr/common/shadowsocks-rust/" && cd "/opt/dr/common/shadowsocks-rust/"
SS_PLATFORM="$(uname -m)"
SS_VERSION="v1.14.3"
dr-js -f "https://github.com/shadowsocks/shadowsocks-rust/releases/download/${SS_VERSION}/shadowsocks-${SS_VERSION}.${SS_PLATFORM}-unknown-linux-gnu.tar.xz" -O "ss-rust.tar.xz"
dr-js -xI "ss-rust.tar.xz" -O "./.ss-rust-${SS_VERSION}-${SS_PLATFORM}/"
rm "ss-rust.tar.xz"
ln -sfT "./.ss-rust-${SS_VERSION}-${SS_PLATFORM}/sslocal" "sslocal"
ln -sfT "./.ss-rust-${SS_VERSION}-${SS_PLATFORM}/ssserver" "ssserver"
)
```
use: https://www.npmjs.com/package/@min-pack/ss-rust

check manual at: https://github.com/shadowsocks/shadowsocks-rust#getting-started

Expand All @@ -23,14 +13,13 @@ check manual at: https://github.com/shadowsocks/shadowsocks-rust#getting-started
config `nano /opt/dr/common/shadowsocks-rust/config.json` and add:
```json
{
"servers": [
{ "server": "0.0.0.0", "server_port": 123, "password": "123456", "method": "chacha20-ietf-poly1305" },
{ "server": "0.0.0.0", "server_port": 1234, "password": "123456", "method": "chacha20-ietf-poly1305" },
{ "server": "0.0.0.0", "server_port": 12345, "password": "123456", "method": "chacha20-ietf-poly1305" }
],
"mode": "tcp_and_udp",
"servers": [ {
"server": "0.0.0.0", "server_port": 123, "password": "123456", "method": "chacha20-ietf-poly1305" }, {
"server": "0.0.0.0", "server_port": 1234, "password": "123456", "method": "chacha20-ietf-poly1305" }, {
"server": "0.0.0.0", "server_port": 12345, "password": "123456", "method": "chacha20-ietf-poly1305"
} ],
"timeout": 1000,
"fast_open": true,
"mode": "tcp_only",
"acl": "/opt/dr/common/shadowsocks-rust/server_block_local.acl"
}
```
Expand Down Expand Up @@ -61,56 +50,58 @@ fc00::/7
fe80::/10
```

start with `sudo /opt/dr/common/shadowsocks-rust/ssserver -c /opt/dr/common/shadowsocks-rust/config.json`
start with `sudo ss-rust server -c /opt/dr/common/shadowsocks-rust/config.json`

#### `shadowsocks` local config

config `nano /opt/dr/common/shadowsocks-rust/local-config.json` add:
```json
{
"local_address": "127.0.0.1", "local_port": 1081,
"locals": [
{ "local_address": "127.0.0.1", "local_port": 1081 },
{ "protocol": "http", "local_address": "127.0.0.1", "local_port": 1080 }
],
"server":"999.999.999.999", "server_port": 12345,
"password": "123456", "method": "chacha20-ietf-poly1305",
"mode": "tcp_and_udp",
"timeout": 1000,
"fast_open": true
"mode": "tcp_only", "timeout": 1000
}
```

start with `sudo /opt/dr/common/shadowsocks-rust/sslocal -c /opt/dr/common/shadowsocks-rust/local-config.json`


## install `privoxy`

```shell script
sudo pacman -S privoxy --noconfirm # arch
sudo apt install privoxy -y # ubuntu
```

to convert http to socks5 for local `shadowsocks`,
edit `sudo nano /etc/privoxy/config` and add:
```shell script
# listen-address 127.0.0.1:8118 # should already have this line
listen-address 127.0.0.1:1080 # change to port 1080, change to 0.0.0.0:1080 to allow LAN proxy connection

# check: https://www.privoxy.org/user-manual/config.html#SOCKS

# convert protocol to socks5 and forward to shadowsocks
forward-socks5 / 127.0.0.1:1081 .

# skip proxy common localhost connection
forward 192.168.*.*/ .
forward 10.*.*.*/ .
forward 127.*.*.*/ .
forward localhost/ .
```

apply config:
```shell script
sudo systemctl enable privoxy.service # enable server
sudo systemctl restart privoxy.service # apply config
sudo systemctl status privoxy.service # check status
```
start with `sudo ss-rust local -c /opt/dr/common/shadowsocks-rust/local-config.json`

this will open both `sock5@1081` and `http@1080`, so no `privoxy` needed

## install `privoxy`

```shell script
sudo pacman -S privoxy --noconfirm # arch
sudo apt install privoxy -y # ubuntu
```

to convert http to socks5 for local `shadowsocks`,
edit `sudo nano /etc/privoxy/config` and add:
```shell script
# listen-address 127.0.0.1:8118 # should already have this line
listen-address 0.0.0.0:1080 # change to port 1080, change to 0.0.0.0:1080 to allow LAN proxy connection

# check: https://www.privoxy.org/user-manual/config.html#SOCKS

# convert protocol to socks5 and forward to shadowsocks
forward-socks5 / 127.0.0.1:1081 .

# skip proxy common localhost connection
forward 192.168.*.*/ .
forward 10.*.*.*/ .
forward 127.*.*.*/ .
forward localhost/ .
```

apply config:
```shell script
sudo systemctl enable privoxy.service # enable server
sudo systemctl restart privoxy.service # apply config
sudo systemctl status privoxy.service # check status
```

basic usage:
```shell script
Expand Down
35 changes: 29 additions & 6 deletions linux/9-6-docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,48 @@ check: https://docs.docker.com/config/containers/logging/configure/#configure-th
basically run `sudo mkdir -p /etc/docker/ && sudo nano /etc/docker/daemon.json` and add:
```json
{
"log-driver": "json-file",
"log-opts": { "max-size": "8m", "max-file": "4" }
"experimental": true, "features": { "buildkit": true },
"log-driver": "json-file", "log-opts": { "max-size": "8m", "max-file": "4" }
}
```
Note: should restart `dockerd`, and re-create existing container for default log config to fully apply

#### install `[email protected]`
```json5
{
// change root
"data-root": "/mnt/some-disk/docker",

// enable latest features
"experimental": true, "features": { "buildkit": true }
}
```

#### install `docker-compose@2`

because docker-compose V2 is still not stable & reasonable enough (20220825)
use docker-compose V2 for faster compose
https://docs.docker.com/compose/install/standalone/

```shell
sudo curl \
-L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-x86_64" \
-L "https://github.com/docker/compose/releases/download/v2.29.0/docker-compose-linux-$(uname -m)" \
-o "/usr/local/bin/docker-compose"
sudo chmod +x "/usr/local/bin/docker-compose"
[[ -f /usr/lib/libcrypt.so.1 ]] || ( echo 'missing "/usr/lib/libcrypt.so.1"'; ls -al /usr/lib/libcrypt.*; sudo ln -sfT libcrypt.so /usr/lib/libcrypt.so.1 ) # patch old python lib for arch-linux
docker-compose -v
```

#### install `[email protected]`

because docker-compose V2 is still not stable & reasonable enough (20220825)

```shell
sudo curl \
-L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-Linux-$(uname -m)" \
-o "/usr/local/bin/docker-compose"
sudo chmod +x "/usr/local/bin/docker-compose"
[[ -f /usr/lib/libcrypt.so.1 ]] || ( echo 'missing "/usr/lib/libcrypt.so.1"'; ls -al /usr/lib/libcrypt.*; sudo ln -sfT libcrypt.so /usr/lib/libcrypt.so.1 ) # patch old python lib for arch-linux
docker-compose -v
```

#### WSL2

for WSL2 Debian extra patch will be needed: https://github.com/microsoft/WSL/discussions/4872#discussioncomment-76635
Expand Down

0 comments on commit 770148e

Please sign in to comment.