2014年10月13日 星期一

翻牆技巧,Shadowsocks與Softether (VPS服務器篇)

這幾天一時興起研究起中國這邊很流行的翻牆手段"架Shadowsocks在VPS",這個是我目前覺得『純上網』速度最快的方式,但因為同時有連vpn的需求,所以也順便研究了一下softether怎麼架在VPS上。

先簡單介紹一下什麼是VPS,VPS (Virtual Private Servers) 就是虛擬私人伺服器,把一台實體伺服器切割成不同的虛擬主機,這些虛擬主機本身按照不同的方案,給予用戶保證的記憶體容量、硬碟空間、CPU用量等。虛擬主機本身彼此不互相影響,同時可以視為實體主機般的操作(有root權限、可重開機)。有一點要注意的是,有些VPS是共享ip,而有些則有獨立ip,這點在架翻牆軟件尤其需要注意,用共享ip到時候被封可就欲哭無淚。

上網搜尋了一下,主要推薦的有我用的 DigitalOcean (簡稱DO) 、Ramnode、Linode、Bandwagon Host (中國暱稱為搬瓦工),這幾個的VPS教學也比較全 。原本因為價格還有評價等因素,打算使用Ramnode(OpenVZ架構),但最後看到了參考文章的一句話:『首先吧,再买OpenVZ架构就剁手。没错,假如你想买VPS折腾,只要支付得起,不要考虑OpenVZ,KVM和XEN都是可以的。』,對於VPS完全不怎麼瞭解的我,就決定先弄個非OpenVZ的來玩玩。

購買和啟動DigitalOcean步驟

  1. 前往官網 https://www.digitalocean.com/
  2. 註冊
  3. 充值 (可Google一下有首次充值贈10美元的連結方法)
  4. Create Droplet 創建主機,選擇5美元一個月的方案、舊金山的主機、CentOS 6.5 x32的主機
  5.  收mail,會有ip地址以及第一次用root登錄的密碼
參考

 安裝Shadosocks-libev(秋水逸冰一鍵安裝版)

  1. 下載putty http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
  2. 打開putty,輸入你vps主機的ip,點選open
  3. 帳號輸入root,密碼輸入mail收到的那個
  4. 再輸入一次該密碼,並改為你的個人密碼
  5. 輸入yum -y install wget
  6. 輸入
    wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-libev.sh
  7. 輸入
    chmod +x shadowsocks-libev.sh
  8. 輸入
    ./shadowsocks-libev.sh 2>&1 | tee shadowsocks-libev.log
  9. 輸入你想設定的密碼
  10. 確定你的信息,內容會呈現如下
    Congratulations, shadowsocks-libev install completed!
    Your Server IP:your_server_ip
    Your Server Port:8989
    Your Password:your_password
    Your Local IP:127.0.0.1
    Your Local Port:1080
    Your Encryption Method:aes-256-cfb

    Welcome to visit:http://teddysun.com/357.html
    Enjoy it!
  11. 個人偏好,喜歡把port設為80(443等下保留給softether管理程式使用),覺得無所謂的人可以跳過,輸入
    vi /etc/shadowsocks/config.json
    會看到以下內容
    {
    "server":"你的server ip",
    "server_port":8989,
    "local_address": "127.0.0.1",
    "local_port":1080,
    "password":"你的密码",
    "timeout":300,
    "method":"aes-256-cfb",
    "fast_open": false,
    "workers": 1
    }
    按下a進入插入模式,把紅色的部分改為80後,按下esc,再輸入:wq後,按下enter完成編輯
參考
http://teddysun.com/357.html
http://www.fanyue.info/2014/10/shadowsocks.html

最佳化Shadowsocks TCP效率(我目前還感覺不出來差別)

  1. 輸入
    vi /etc/security/limits.conf
  2. 增加以下兩行,然後按照上面的方式離開編輯模式
    * soft nofile 51200
    * hard nofile 51200
  3. 輸入
    ulimit -n 51200
  4. 重啟shadowsocks
    /etc/init.d/shadowsocks restart
  5. 輸入
    cp /etc/sysctl.conf /root/
    來備份檔案
  6. 輸入
    vi /etc/sysctl.conf
    開始修改
  7. 所有內容清除,並貼上下面內容後離開
    fs.file-max = 51200

    net.core.rmem_max = 67108864
    net.core.wmem_max = 67108864
    net.core.netdev_max_backlog = 250000
    net.core.somaxconn = 3240000

    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_tw_reuse = 1
    net.ipv4.tcp_tw_recycle = 0
    net.ipv4.tcp_fin_timeout = 30
    net.ipv4.tcp_keepalive_time = 1200
    net.ipv4.ip_local_port_range = 10000 65000
    net.ipv4.tcp_max_syn_backlog = 8192
    net.ipv4.tcp_max_tw_buckets = 5000
    net.ipv4.tcp_fastopen = 3
    net.ipv4.tcp_rmem = 4096 87380 67108864
    net.ipv4.tcp_wmem = 4096 65536 67108864
    net.ipv4.tcp_mtu_probing = 1
    net.ipv4.tcp_congestion_control = hybla
  8. 輸入
    /sbin/modprobe tcp_hybla
  9. 輸入
    sysctl -p
參考

安裝Softether伺服器(用來L2TP/IPSEC)

  1. 輸入yum update -y
  2. 輸入
    yum groupinstall "Development Tools" -y
  3. 輸入
    yum install gcc -y
  4. 輸入
    yum install libpcap -y
  5. 輸入
    wget http://www.softether-download.com/files/softether/v4.10-9473-beta-2014.07.12-tree/Linux/SoftEther_VPN_Server/32bit_-_Intel_x86/softether-vpnserver-v4.10-9473-beta-2014.07.12-linux-x86-32bit.tar.gz
  6. 輸入
    tar xzvf softether-vpnserver-v4.10-9473-beta-2014.07.12-linux-x86-32bit.tar.gz
  7. 輸入
    cd vpnserver
  8. 輸入
    make
  9. 所有的問題都輸入1
  10. 輸入
    cd ..
  11. 輸入
    mv vpnserver /usr/local
  12. 輸入
    cd /usr/local/vpnserver
  13. 輸入以下三行指令改變權限
    chmod 600 *
    chmod 700 vpncmd
    chmod 700 vpnserver
  14. 輸入
    vi /etc/init.d/vpnserver 
  15. 貼上以下內容後離開(按ESC後Shift+z,或輸入:wq)
    #!/bin/sh
    # chkconfig: 2345 99 01
    # description: SoftEther VPN Server
    DAEMON=/usr/local/vpnserver/vpnserver
    LOCK=/var/lock/subsys/vpnserver
    test -x $DAEMON || exit 0
    case "$1" in
    start)
    $DAEMON start
    touch $LOCK
    ;;
    stop)
    $DAEMON stop
    rm $LOCK
    ;;
    restart)
    $DAEMON stop
    sleep 3
    $DAEMON start
    ;;
    *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    esac
    exit 0
  16. 輸入以下三行指令後,看到成功訊息
    chmod 755 /etc/init.d/vpnserver
    /sbin/chkconfig --add vpnserver
    /etc/init.d/vpnserver start

管理Softether Server

在中國境內,管理Softehter server有被牆的風險,以下操作建議先想辦法翻牆再做
  1. 下載安裝Softether VPN Server Manager
    http://www.softether-download.com/en.aspx
  2. 初次使用,先新建Server,輸入名稱和server ip
  3. 在管理頁面先按下屬性,並勾選不要給匿名用戶枚舉


  4. 按下確定後回到管理頁面,按下管理虛擬hub後,分別去新增用戶以及啟用虛擬NAT






  5. 設定L2TP/IPSEC


參考


總算寫完了....有空再把用戶端的使用方式補上

沒有留言:

張貼留言