golang 配置


環境變量配置 .zshrc

export GOROOT=/usr/local/go
export GOPATH=$HOME/gocode
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

設置代理 //https://goproxy.io/zh/

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

godoc安裝
go get -v -u golang.org/x/tools/cmd/godoc

縮減包體積
go build -ldflags "-s -w"
-s 的作用是去掉符號信息。去掉符號表,golang panic 時 stack trace 就看不到文件名及出錯行號信息了。
-w 的作用是去掉 DWARF tables 調試信息。結果就是得到的程序就不能用 gdb 調試了。

設置包中變量值
var Version = "1.0.1"
[root@bb ]# export TAG=1.0.7
[root@bb ]# go build -ldflags "-X main.Version='$TAG'"

golang編譯源碼(樹莓派3b armV7l)
cd go/src
GOOS=linux GOARM=7 GOARCH=arm CGO_ENABLED=0 ./bootstrap.bash
golang編譯openwrt 程序
GOARCH 可以為 mips/mipsle 分別對應處理器的大小端
GOOS=linux GOARCH=mipsle GOMIPS=softfloat CGO_ENABLED=0 go build

golang編譯路由器GL-AR750
GOOS=linux GOARCH=mips GOMIPS=softfloat CGO_ENABLED=0 go build -o xxx xxx.go

golang編譯小米路由器R3G

GOOS=linux GOARCH=mipsle GOMIPS=softfloat  go build -o xxx xxx.go

golang編譯小米路由器R2D

 GOOS=linux GOARM=5 GOARCH=arm CGO_ENABLED=0 go build 

golang編譯Android

 GOOS=linux GOARCH=arm CGO_ENABLED=0   go build

golang編譯Linux

 GOOS=linux GOARCH=amd64  go build

golang編譯Windows

 GOOS=windows GOARCH=amd64 CGO_ENABLED=0  go build

golang編譯Mac

 GOOS=darwin GOARCH=amd64 CGO_ENABLED=0  go build

查看生成的匯編代碼
go tool compile -S xx.go                          //編譯器對匯編代碼進行優化
go tool compile -S -N -l xx.go      //不優化
注:如果編譯時不使用 -N -l 參數,編譯器會對匯編代碼進行優化,編譯結果會有較大差別

各平台的GOOS和GOARCH參考
OS                ARCH                           OS version
linux          386/amd64/arm              >= Linux 2.6
darwin       386/amd64                     OS X (Snow Leopard + Lion)
freebsd      386/amd64                     >= FreeBSD 7
windows    386/amd64                      >= Windows 2000

 android 可執行文件路徑

/data/local/tmp/

v*ray 配置
v*ray-core/main go build -o v*ray
v*ray-core/infra/control/main go build -o v2ctl
v*ray,v2ctl,config.json 放在同一個文件夾下

nps 配置

git clone https://github.com/ehang-io/nps.git
服務器配置
cd nps/cmd/nps

go build nps.go

mv nps ../../
vi conf/nps.conf
//修改配置文件 注釋掉
====================
#HTTP(S) proxy port, no startup if empty
#http_proxy_ip=0.0.0.0
#http_proxy_port=80
#https_proxy_port=443
#https_just_proxy=true
#default https certificate setting
#ttps_default_cert_file=conf/server.pem
#https_default_key_file=conf/server.key
=====================
public_vkey=
#web
web_host=www.xxx.com
web_username=
web_password=
web_port =
======================

 

sudo ./nps install
sudo nps start

/etc/nps/conf/nps.conf    //配置文件位置

/var/log/nps.log               //log位置


客戶端配置
vi start_npc.sh
sudo nohup ~/work/npc -server=ip:8024 -vkey=xxxx > ~/work/npc.log 2>&1 &

開機自啟動

1.樹莓派3b開機自啟動

crontab -e  //添加

@reboot /home/user/work/start_npc.sh

crontab -l //查看

2.小米路由器R2D開機自啟動

vi /etc/init.d/mystart

==========================

#!/bin/sh /etc/rc.common
START=99
start(){
/mnt/sda1/myapp
}
stop(){
/mnt/sda1/myapp -s
}
restart(){
/mnt/sda1/myapp
}

==========================

chmod -R 777 init.d/mystart #設置權限,否則無法激活開機啟動,提示權限不足
/etc/init.d/mystart enable #激活開機啟動
/etc/init.d/mystart start #運行start函數啟動程序

第三方連接配置 

ssh -p 端口號 root@www.xxx.com

scp -P 端口號 -r xxx root@www.xxx.com:/root/  傳文件

文檔地址:https://github.com/51qiuzhu/nps

 doh-client 配置

vi ~/work/start-dohc.sh

sudo nohup ~/work/doh-client  -conf=~/work/doh-client.conf  > ~/work/dohc.log 2>&1 &

 加入開機啟動 /etc/init.d/mystart

 

dnsmasq 配置doh

sudo vi /etc/dnsmasq.conf

no-hosts
no-resolv
server=127.0.0.1#5380
conf-dir=/etc/dnsmasq.d/
log-queries
log-facility=/var/log/dnsmasq.log

 

配置國內的dns走國內查詢,國外的ip走doh

wget https://raw.githubusercontent.com/zwpaper/dotfile/master/archlinux/config/dnsmasq/install.sh
chmod 755 install.sh
sudo ./install.sh

 

進入目錄 /etc/dnsmasq.d
從 https://cokebar.github.io/gfwlist2dnsmasq/dnsmasq_gfwlist_ipset.conf 下載 dnsmasq_gfwlist_ipset.conf 后放入該目錄
里面的域名指定了使用127.0.0.1#5353 需要替換為5380(doh客戶端監聽的端口)
:%s/5353/5380/g       //vi替換命令

gost 客戶端配置透明代理 監聽1080端口
vi start_gostc.sh
#sudo nohup ~/work/gost -L=:1080 -F=ss2://AES-256-GCM:Password@Serverip:Serverport >> ~/work/gostc.log 2>&1 &
sudo nohup ~/work/gost -L redirect://:1080 -F ss2://AES-256-GCM:Password@Serverip:Serverport >> ~/work/gostc.log 2>&1 &

iptables ipset 配置gfwlist的流量轉發到代理端口

# 新建ipset叫gfwlist
sudo ipset -N gfwlist iphash
#匹配gfwlist的流量轉到1080端口(你ss客戶端監聽的端口)
sudo iptables -t nat -A PREROUTING -p tcp -m set --match-set gfwlist dst -j REDIRECT --to-port 1080
sudo iptables -t nat -A OUTPUT -p tcp -m set --match-set gfwlist dst -j REDIRECT --to-port 1080

上述命令加入開機自啟動,每次重啟都生效 

總結:客戶端dns請求通過路由dnsmasq把特殊域名通過DoH解析,結果存入ipset,iptables匹配ipset走ss 

https://golang.org/doc/install/source#go14

http://www.lstop.pub/2019/04/11/OpenWrt-DNS-over-Https%E7%BA%AF%E5%87%80%E4%B8%8A%E7%BD%91/

https://github.com/ginuerzh/gost


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM