阿里云優(yōu)惠購買鏈接:阿里云·云小站
一、 git網(wǎng)絡(luò)問題
git? 有兩種獲取代碼的方式,一種是ssh 第二種是http或者h(yuǎn)ttps
https 和ssh 更為安全一點
我們使用ssh 方式,可能你的gitlab服務(wù)器沒有使用22默認(rèn)端口如下地址:
ssh://git@gitlab.abc.com:10022/afuos/afuos-config.git
1、做代理。
推薦使用haproxy 去做端口轉(zhuǎn)發(fā),這樣對小白來說簡單一點,如下配置
listen gitlab
? ? mode tcp
? ? bind *:10022
? ? server? git? ? gitlab.abc.com:10022
重載haproxy? ,service? reload haproxy , 使用ss? -tnlp | grep 10022?
如果不喜歡使用haproxy代理你還可以使用openresty去做tcp代理,如下配置
stream {
log_format basic '$remote_addr [$time_local] '
? ? ? ? '$protocol $status $bytes_sent $bytes_received '
? ? ? ? '$session_time $upstream_addr';
? ? ? ? access_log? logs/stream-access.log basic;
upstream? gitlab {
? ? ? ? server gitlab.raiyee.cn:10022? max_fails=3 fail_timeout=30s;
? ? ? ? ? ? ? }
server {
? ? listen? 10022 so_keepalive=2m:2s:3;
? ? proxy_connect_timeout 1s;
? ? proxy_pass? gitlab;
? ? ? }
}
在http? 塊之外引入配置文件,需要注意的是這個配置文件不能和http 配置文件放在一塊,避免語法檢查出錯。
include? /path/stram.conf ;
2、在沒有公網(wǎng)的主機上使用端口代理
首先配置內(nèi)網(wǎng)主機DNS ,這里我直接配置hosts,讓域名指向我們可以訪問公網(wǎng)的主機。
[root@test02 ~]# cat /etc/hosts
127.0.0.1? ? ? localhost? ? ? localhost.localdomain? localhost4? ? ? localhost4.localdomain4
::1? ? localhost? ? ? localhost.localdomain? localhost6? ? ? localhost6.localdomain6
192.168.10.36? ? ?gitlab.abc.com
到此大功基本告成,安裝git??
yum? install? ?git? ?-y
這個時候就可以使用git? 命令去clone 代碼了
git clone ssh://git@gitlab.abc.com:10022/afuos/afuos-config.git
#可以不做hosts這一步,直接把gitlab 的域名換成內(nèi)網(wǎng)代理的IP地址如下,端口可以根據(jù)代理的端口修改:
git clone ssh://git@ 192.168.10.36:10022/afuos/afuos-config.git
二、 mvn 打包的問題
方法有哪些呢? socket5 代理或http代理,由于倉庫地址可能會好多個我們使用正向代理可解決問題,最簡單的辦法當(dāng)然是squid,但是如果沒有root 我們沒法安裝squid 怎么辦?
沒事有時候我們不想安裝那么多應(yīng)用,我們使用openresty 來搞定它
我們使用第三方模塊https://github.com/chobits/ngx_http_proxy_connect_module.git
編譯安裝,注意版本號,不同的版本打的補丁是有區(qū)別的。
./configure --user=nginx --group=nginx --prefix=/usr/local/nginxserver --with-http_sub_module --with-http_stub_status_module --with-http_ssl_module --with-pcre --add-module=/root/soft/ngx_http_proxy_connect_module
補?。簄ginx-1.15.8? 對應(yīng)的是proxy_connect_rewrite_101504.patch ,其它版本參考github?
patch -d build/nginx-1.15.8/ -p 1 < /root/soft/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_101504.patch?
make? && make? install??
cat proxy_connect.conf
server {
? listen? 3128;
? resolver? 114.114.114.114;
? proxy_connect;
? proxy_connect_allow? ? ? ? ? ? 443 563;
? proxy_connect_connect_timeout? 10s;
? proxy_connect_read_timeout? ? ? 10s;
? proxy_connect_send_timeout? ? ? 10s;
? location? / {
? ? proxy_pass http://$host;
? ? proxy_set_header? Host $host;
? ? }
}
在需要使用公網(wǎng)轉(zhuǎn)發(fā)的主機上配置轉(zhuǎn)發(fā):?
export? http_proxy=XXXXXX:3128;? export? https_proxy=XXXXXX:3128
或者修改/etc/profile??
printf -v no_proxy '%s,' 172.17.0.{1..255}; ## 生成內(nèi)網(wǎng)所有ip
http_proxy=http://172.17.0.16:8080
https_proxy=http://172.17.0.16:8080
no_proxy="${no_proxy%,},localhost,127.0.0.1,localaddress,.localdomain.com" ## 排除本地ip
export http_proxy https_proxy no_proxy
這個時候就能 curl 訪問百度,這個步驟是給nodejs 使用npm 或者yarn? 打包用的,maven還不能打包,需要修改seting.xml 文件,打開文件找到模塊proxies。
<proxies>
? ? <proxy>
? ? ? <id>optional</id>
? ? ? <active>true</active>
? ? ? <protocol>http</protocol>
? ? ? <host>192.168.10.36</host>
? ? ? <port>3128</port>
? ? ? <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
? ? </proxy>
? </proxies>
三、npm 打包問題
發(fā)現(xiàn)npm 使用環(huán)境變量做代理沒有那么穩(wěn)定,可以做個npm 的配置。
?npm config set proxy http://192.168.10.36:3128
?npm config set https-proxy http://192.168.10.36:3128
使用阿里云倉庫可以告別卡頓慢的問題。
npm config set registry https://registry.npm.taobao.org/