centos安裝Shadowsocks

開發需要對接google,facebook接口調試代碼需要一個代理,找一網centos7.3 服務器來安裝代理:

[[email protected] ~]yum install python-pip

[[email protected] ~]$pip install shadowsocks

 

在後臺啓動 ss 客戶端命令:

nohup sslocal -s your_server_ip -p your_server_port -l 1080 -k your_server_passwd -t 600 -m rc4-md5 > /dev/null 2>&1 &

 

注意:

使用的是 sslocal 這個命令,表示 shadowsocks 以客戶端模式工作

將上述命令裏的 your_server_ip, your_server_port, your_server_passwd 換成自己的, 這三個分別代表服務器ip, 服務器上 shadowsocks 的端口以及密碼.後面的 rc4-md5 加密方式也要換成跟 server 端一致。

前面的nohub 和最後的 & 表示後臺執行且關閉 session 後仍然在後臺執行,否則將會阻塞shell端口.
爲了更方便, 建議新建一個.json的文件, 將上述信息放裏面,如新建/etc/shadowsocks.json文件, 內容爲:

 

{
    "server":"your_server_ip",      #ss服務器IP
    "server_port":your_server_port, #端口
    "local_address": "127.0.0.1",   #本地ip
    "local_port":1080,              #本地端口
    "password":"your_server_passwd",#連接ss密碼
    "timeout":300,                  #等待超時
    "method":"rc4-md5",             #加密方式 可能不一樣需要修改
    "fast_open": false,             # true false。如果你的服務器 Linux 內核在3.7+,可以開啓 fast_open 以降低延遲。開啓方法: echo 3 > /proc/sys/net/ipv4/tcp_fastopen 開啓之後,將 fast_open 的配置設置爲 true 即可
    "workers": 1                    # 工作線程數
}

 

然後運行一下命令啓動shadowsocks

nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &

 

如果想增加開啓自動啓動,執行:echo nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 & /etc/rc.local

執行ps aux |grep sslocal |grep -v grep”查看後臺sslocal是否運行

  

安裝Privoxy

上述安好了shadowsocks,但它是 socks5 代理,我門在 shell 裏執行的命令,發起的網絡請求現在還不支持 socks5 代理,只支持 http/https 代理。爲了我門需要安裝 privoxy 代理,它能把電腦上所有http請求轉發給 shadowsocks

[[email protected] ~] yum install privoxy -y

查看 vim /usr/local/etc/privoxy/config 或者/etc/privoxy/config文件,
先搜索關鍵字 listen-address 找到 listen-address 127.0.0.1:8118 這一句,保證這一句沒有註釋,8118就是將來http代理要輸入的端口。
然後搜索 forward-socks5t, forward-socks5t / 127.0.0.1:9050 改爲#forward-socks5t / 127.0.0.1:1080 . 此句前面的註釋去掉, 意思是轉發流量到本地的1080端口, 1080端口正是 ss 監聽的端口

啓動privoxy

systemctl restart privoxy

systemctl enable privoxy

或者:

privoxy  /etc/privoxy/config

配置/etc/profile

vim /etc/profile
export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118
 source /etc/profile

當前session執行:

export http_proxy=http://127.0.0.1:8118
export https_proxy=http://127.0.0.1:8118

 

執行vim /etc/profile,添加如下二句:

export http_proxy=http://127.0.0.1:8118 export https_proxy=http://127.0.0.1:8118

修改後使配置生效source /etc/profile

lsof –i1080

[[email protected] /etc/privoxy]$lsof -i:1080

COMMAND  PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME

sslocal 9551 root    3u  IPv4 6099160      0t0  TCP localhost:socks (LISTEN)

sslocal 9551 root    4u  IPv4 6099161      0t0  UDP localhost:socks

shadsockets正常監聽;

[[email protected] /etc/privoxy]$lsof -i:8118

COMMAND  PID    USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME

privoxy 9196 privoxy    4u  IPv4 6072039      0t0  TCP localhost:privoxy (LISTEN)

privoxy正常監聽;

[[email protected] /etc/privoxy]$echo $http_proxy

http://127.0.0.1:8118

[[email protected] /etc/privoxy]$echo $https_proxy

http://127.0.0.1:8118

測試:

wget www.google.com

--2018-11-14 11:43:30--  http://www.google.com/

Connecting to 127.0.0.1:8118... connected.

Proxy request sent, awaiting response... 200 OK

Length: unspecified [text/html]

Saving to: ‘index.html.1’

 

    [ <=>                                                                ] 12,084      --.-K/s   in 0s     

 

2018-11-14 11:43:30 (51.7 MB/s) - ‘index.html.1’ saved [12084]

 

 

執行wget www.google.com判斷是否成功

如果不能訪問,請重啓機器,依次打開shadowsocksprivoxy再測試

Ps:如果不需要用代理了,記得把bash裏的配置註釋上,免得把流量跑完了

 

測試:

Curl https://www.google.com

 

curl www.google.com

<!doctype html><html itemscope="" itemtype="http://schema.org/WebPage"><head><meta content="Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for." name="description"><meta content="noodp" name="robots"><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"><meta content="/images/branding/googleg/1x/googleg_standard_color_128dp.png" itemprop="image"><title>Google</title><script nonce="PwL0WCIukKULM1vnDzi81w==">(function(){window.google={kEI:'rpnrW5uHCIar8APVhIvwCg',kEXPI:'0,1353746,58,1957,583,434,281,344,494,287,697,528,731,31,111,183,293,879,301,30,524,27,275,401,101,140,107,389,2336367,190,32,68,329226,1294,12383,4855,32691,15248,867,317,10444,1402,6381,3335,2,2,4605,2196,369,1212,2102,5505,

……

  

Note

503 - Forwarding failure (Privoxy@localhost)報錯時候,應該轉發失敗,應該是json中配置的ip

  "local_address": "127.0.0.1",   #127.0.0.1可能寫成機器內網ip了改爲127.0.0.1即可;

不能訪問,重啓下機器,依次打開shadowsocksprivoxy再測試

 

nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &

privoxy --user privoxy /usr/local/etc/privoxy/config


轉自:https://bodyno.com/tool/2017/09/03/centos-ss.html 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章