doina

一个小菜鸟运维工程师.

CentOS7安装 Shadowsocks-客户端(Linux科学上网)

安装 pip

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py

安装Shadowsocks客户端

pip install --upgrade pip
pip install shadowsocks

新建配置文件

# vi /etc/shadowsocks.json
{
  "server":"xxx.xxx.xxx.xxx",
  "server_port":8388,
  "local_address": "127.0.0.1",
  "local_port":1888,
  "password":"Password",
  "timeout":300,
  "method":"aes-256-cfb",
  "workers": 1
}

启动

nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &
echo " nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &" /etc/rc.local   #设置自启动

访问google测试

运行 curl –socks5 127.0.0.1:1888 http://httpbin.org/ip,如果返回你的 ss 服务器 ip 则测试成功:


[root@master tmp]# curl http://httpbin.org/ip { "origin": "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx" } [root@master tmp]# curl --socks5 127.0.0.1:1888 http://httpbin.org/ip { "origin": "203.124.13.125, 203.124.13.125" } [root@master tmp]# curl -I --socks5 127.0.0.1:1888 https://google.com HTTP/1.1 301 Moved Permanently Location: https://www.google.com/ Content-Type: text/html; charset=UTF-8 Date: Mon, 15 Jul 2019 03:08:41 GMT Expires: Wed, 14 Aug 2019 03:08:41 GMT Cache-Control: public, max-age=2592000 Server: gws Content-Length: 220 X-XSS-Protection: 0 X-Frame-Options: SAMEORIGIN Alt-Svc: quic=":443"; ma=2592000; v="46,43,39"

安装Privoxy

Shadowsocks 是一个 socket5 服务,我们需要使用 Privoxy 把流量转到 http/https 上。

yum install epel-release
yum install privoxy -y

# rpm -qa|grep privoxy
privoxy-3.0.26-1.el7.x86_64

配置Privoxy

修改一下配置,其他不用改

# vim /etc/privoxy/config
listen-address  0.0.0.0:8118    #Privoxy监听地址
forward-socks5t   /               127.0.0.1:1888 .  #本地Shadowsocks地址
forward         192.168.*.*/     .  #不转发的地址
forward            10.*.*.*/     .  #不转发的地址
forward           127.*.*.*/     .  #不转发的地址
forwarded-connect-retries  1    #重试次数

# systemctl start privoxy
# systemctl status privoxy
● privoxy.service - Privoxy Web Proxy With Advanced Filtering Capabilities
   Loaded: loaded (/usr/lib/systemd/system/privoxy.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-07-15 11:24:23 CST; 13s ago
  Process: 16582 ExecStart=/usr/sbin/privoxy --pidfile /run/privoxy.pid --user privoxy /etc/privoxy/config (code=exited, status=0/SUCCESS)
 Main PID: 16583 (privoxy)
    Tasks: 1
   Memory: 936.0K
   CGroup: /system.slice/privoxy.service
           └─16583 /usr/sbin/privoxy --pidfile /run/privoxy.pid --user privoxy /etc/privoxy/config

Jul 15 11:24:22 master systemd[1]: Starting Privoxy Web Proxy With Advanced Filtering Capabilities...
Jul 15 11:24:23 master systemd[1]: Started Privoxy Web Proxy With Advanced Filtering Capabilities.

配置http_proxy

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

# curl google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

[root@master ~]# curl -I google.com 
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Mon, 15 Jul 2019 03:27:26 GMT
Expires: Wed, 14 Aug 2019 03:27:26 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Proxy-Connection: keep-alive
点赞

发表评论

电子邮件地址不会被公开。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据