2022年1月

fn main() {
    // In general, the `{}` will be automatically replaced with any
    // arguments. These will be stringified.
    println!("{} days", 31);

    // Without a suffix, 31 becomes an i32. You can change what type 31 is
    // by providing a suffix. The number 31i64 for example has the type i64.

    // There are various optional patterns this works with. Positional
    // arguments can be used.
    println!("{0}, this is {1}. {1}, this is {0}", "Alice", "Bob");

    // As can named arguments.
    println!("{subject} {verb} {object}",
             object="the lazy dog",
             subject="the quick brown fox",
             verb="jumps over");

    // Special formatting can be specified after a `:`.
    println!("{} of {:b} people know binary, the other half doesn't", 1, 2);

    // You can right-align text with a specified width. This will output
    // "     1". 5 white spaces and a "1".
    println!("{number:>width$}", number=1, width=6);

    // You can pad numbers with extra zeroes. This will output "000001".
    println!("{number:0>width$}", number=1, width=6);

    // Rust even checks to make sure the correct number of arguments are
    // used.
    println!("My name is {0}, {1} {0}", "Bond");
    // FIXME ^ Add the missing argument: "James"

    // Create a structure named `Structure` which contains an `i32`.
    #[allow(dead_code)]
    struct Structure(i32);

    // However, custom types such as this structure require more complicated
    // handling. This will not work.
    println!("This struct `{}` won't print...", Structure(3));
    // FIXME ^ Comment out this line.
}

Ubuntu / APT

Ubuntu 的软件源配置文件是 /etc/apt/sources.list

sudo sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

Proxy代理

export HTTP_PROXY=http://your.proxy:8888
export HTTPS_PROXY=http://your.proxy:8888

Docker

修改 /etc/docker/daemon.json 文件。

echo '{"registry-mirrors":["https://reg-mirror.qiniu.com/","https://t3yqbami.mirror.aliyuncs.com"]}' > /etc/docker/daemon.json

shell执行命令

sudo systemctl daemon-reload
sudo systemctl restart docker

Git

Git 没有镜像站,此为代理设置方法。

git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080

若是 HTTP/HTTPS 协议的代理:

git config --global http.https://github.com.proxy https://127.0.0.1:1080
git config --global https.https://github.com.proxy https://127.0.0.1:1080

取消方法:

git config --global --unset http.proxy
git config --global --unset https.proxy

GO

go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

NPM / Yarn

yarn config set registry https://registry.npm.taobao.org --global
npm config set registry https://registry.npm.taobao.org --global

对于一些具体包,还需另外具体设置,如 Electron 就需要单独设置。

yarn config set ELECTRON_MIRROR https://npm.taobao.org/mirrors/electron/ --global
npm config set ELECTRON_MIRROR https://npm.taobao.org/mirrors/electron/ --global

对于 NVM 安装的 Node/NPM 来说,--global 法在一些场合不好用,这是因为此法安装的 global npmrc 并不能被识别,需要手动在 ~/.npmrc 中指定 global npmrc 的位置。

若不用 --global 法,则亦可在 ~/.npmrc 中写如下行:

registry=https://registry.npm.taobao.org
ELECTRON_MIRROR=https://npm.taobao.org/mirrors/electron/

如果不需要设置代理,单纯只想增加超时时限,可以写:

fetch-retry-maxtimeout=6000000
fetch-retry-mintimeout=1000000

Pypi / Pip

在文件 ~/.pip/pip.conf 中加入以下:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com

Rust / Cargo

Rustup 时需要环境变量:

export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup

cargo 下载库时需要 ~/.cargo/config 有如下内容(默认使用中科大源)

[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"
replace-with = 'ustc'
# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"
# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

对于需要额外单独替换的可参考如下:

[patch.crates-io]
mysqlclient-sys = { git = 'https://github.com/sgrif/mysqlclient-sys' }

第一步,初始化用户和节点

docker run --rm -it --network host --volume $HOME/.ironfish:/root/.ironfish ghcr.io/iron-fish/ironfish:latest config:set blockGraffiti "planter"

第二步,将下方的配置复制到目录的docker-compose.yml中

version: "3"
services:
    ironfish:
        image: ghcr.io/iron-fish/ironfish:latest
        network_mode: host
        container_name: ironfish
        volumes:
            - ${HOME}/.ironfish:/root/.ironfish
    miner:
        image: ghcr.io/iron-fish/ironfish:latest
        network_mode: host
        container_name: miner
        volumes:
            - ${HOME}/.ironfish:/root/.ironfish
        entrypoint: ["./bin/run", "miners:start", "--threads", "-1"] 
        depends_on:
            - ironfish

第三步,更新镜像及启动

docker-compose pull && docker-compose up -d

第四步,查看状态

docker exec -it ironfish ./bin/run status -f

查看日志 docker-compose logs -f
重启docker docker-compose restart

curl -fsSL https://gitee.com/simon4546/ethlistener/raw/master/ironfish_install.sh|sudo bash

国内安装docker

apt remove docker docker-engine docker.io containerd runc 
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 
echo '{"registry-mirrors":["https://reg-mirror.qiniu.com/"]}' > /etc/docker/daemon.json
systemctl daemon-reload 
systemctl restart docker 
docker info 
curl -L https://get.daocloud.io/docker/compose/releases/download/1.28.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose 
chmod +x /usr/local/bin/docker-compose 
docker-compose --version 

清空docker日志

truncate -s 0 /var/lib/docker/containers/*/*-json.log

删除所有容器和卷

docker rm -f $(docker ps -a -q) &&docker volume rm $(docker volume ls -q)

过滤查看日志

docker-compose logs --follow --tail=1|grep "get your Goerli ETH" 

根据镜像删除docker

docker rm $(docker stop $(docker ps -a -q --filter ancestor=ethersphere/bee:0.6.2 --format="{{.ID}}"))

查看运行中的docker的启动命令

alias runlike="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock:ro assaflavie/runlike"
docker ps
runlike YOUR-CONTAINER 

前端的准备工作,在中转机上执行

echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
sysctl -p
echo "1"> /proc/sys/net/ipv4/ip_forward

1.打开中转机的包转发能力(假定eth0为指向公网的网卡)

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

-t nat :用于指定处理的是nat网络的规则
-A :追加规则 Append缩写
POSTROUTING:声明这条规则用于出站
-o : 指定目标网卡
-j : 指定下一跳的执行计划
MASQUERADE : 地址伪装,在本条规则里,代表把出站的包头的源地址改为eth0

2.将本地的8888端口转发到本机6666端口

iptables -t nat -A PREROUTING -p tcp --dport 8888 -j REDIRECT --to-port 6666

PREROUTING:数据包进入本机,进入路由器之前。可以用于目标地址转换(DNAT)。在此时数据包还没有经过任何处理,指向8888的请求会在本条命令指行后生效
POSTROUTIONG 通过路由表后,发送到网卡接口之前。可以用于转发数据(SNAT,MASQUERADE)

可以使用以下命令测试

nc -l 6666 启动tcp监控器
nc -v 192.168.1.2(该机的ip) 8888

*说明:PREROUTING链修改的是从外部连接过来时的转发,如果本机连接到本机的转发,需要修改 OUTPUT链。

iptables -t nat -A OUTPUT -p tcp --dport 8888 -j REDIRECT --to-port 6666

iptables一共有四表(filter,nat,mangle,raw)五链(PREROUTING,INPUT,FORWARD,OUTPUT,POSTROUTING),可以上网查查资料

3.将本机(192.168.1.9)的端口转发到其他机器(192.168.1.8)

iptables -t nat -A PREROUTING -p tcp --dport 6666 -j DNAT --to-destination 192.168.1.8:8080
iptables -t nat -A POSTROUTING -p tcp -d 192.168.1.8 --dport 8080 -j SNAT --to-source 192.168.1.9

这里要处理两条规则,分别是出站和入站。为什么要处理两处?
1.其它处理传入的包,经过命令1之后,会使用DNAT处理,可以理解为,为把ip包头的dest改为192.168.1.8 8080,这很好理解,如果不修改,就还是本地在处理
2.在出站POSTROUTING时,这个时间我们需要使用SNAT(源NAT)把包头再改为本机(192.168.1.9),否则在对方机器收到命令再握手回来的时候,指定的目标是192.168.1.8,则192.168.1.9无法再收到报文,不能再行使中转器的职责,具体细节,可以上网查阅tcp三次握手。
如果有一堆端口要转发,可以使用下面的指令

ufw route allow proto tcp to 10.0.0.3 port 10002
iptables -t nat -A PREROUTING -i eth0 -p tcp -m multiport --dports 10001,10002 -j DNAT --to-destination 10.0.0.3

查看路由表:
netstat -rn 或 route -n

查看iptables规则:
iptables -L或者iptables -t nat -L(只查看nat规则)
iptables -L -v -n | more
iptables -t nat -nL --line

删除该端口转发:
删除指定表的指定链上的规则, -D 并指定序号即可。
iptables -t nat -D PREROUTING 1