Shadowsocks-go一键安装脚本

PengTdy · · 4482 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

Shadowsocks-go一键安装脚本

本脚本适用环境:
系统支持:CentOS,Debian,Ubuntu
内存要求:≥128M

关于本脚本:
一键安装 Go 版的 shadowsocks 最新版本 1.1.5。据说 go 版本有 buff 。与 Python 版不同的是,其客户端程序能使用多个服务端配置,本脚本安装的是服务端程序。作者默认推荐 aes-128-cfb 加密,基于一致性,脚本使用了 aes-256-cfb 加密方式。

默认配置:
服务器端口:自己设定(如不设定,默认为 8989)
客户端端口:1080
密码:自己设定(如不设定,默认为teddysun.com)
客户端下载:
https://github.com/shadowsocks/shadowsocks-windows/releases
使用方法:
使用root用户登录,运行以下命令:
wget –no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-go.sh
chmod +x shadowsocks-go.sh
./shadowsocks-go.sh 2>&1 | tee shadowsocks-go.log

安装完成后,脚本提示如下:
Congratulations, shadowsocks-go install completed!
Your Server IP:your_server_ip
Your Server Port:your_server_port
Your Password:your_password
Your Local Port:1080
Your Encryption Method:aes-256-cfb

Welcome to visit:https://teddysun.com/392.html
Enjoy it!

卸载方法:
使用 root 用户登录,运行以下命令:
./shadowsocks-go.sh uninstall

其他事项:
客户端配置的参考链接:https://teddysun.com/339.html
安装完成后即已后台启动 shadowsocks-go ,运行:
/etc/init.d/shadowsocks status

可以查看 shadowsocks-go 进程是否已经启动。
本脚本安装完成后,已将 shadowsocks-go 加入开机自启动。
统一回复:
在 Bandwagonhost 的 VPS 上出现 Trace/breakpoint trap 现象的,初步认为是 Bandwagonhost 的系统问题。
经过测试发现,和版本升级无关,唯独在 Bandwagonhost 才会出现这个现象。建议换成 libev 版,或者将系统换为 CentOS 7 可以解决该问题。
本人不是 Shadowsocks Go 作者,安装程序均来自于这里。
使用命令:
启动:/etc/init.d/shadowsocks start
停止:/etc/init.d/shadowsocks stop
重启:/etc/init.d/shadowsocks restart
状态:/etc/init.d/shadowsocks status
多用户多端口配置文件 sample(2015年01月08日):
配置文件路径:/etc/shadowsocks/config.json
{
“port_password”:{
“8989”:”password0”,
“9001”:”password1”,
“9002”:”password2”,
“9003”:”password3”,
“9004”:”password4”
},
“method”:”aes-256-cfb”,
“timeout”:600
}

官方版本的 sample ,详见这里。
更多版本 Shadowsocks 服务端一键安装脚本:
ShadowsocksR 版一键安装脚本(CentOS,Debian,Ubuntu)
Shadowsocks Python 版一键安装脚本(CentOS,Debian,Ubuntu)
CentOS 下 shadowsocks-libev 一键安装脚本
Debian 下 shadowsocks-libev 一键安装脚本
更新日志:
更新(2016年05月12日):新增在 CentOS 7 下的防火墙规则设置。
更新(2016年05月04日):更新 Shadowsocks-go 到版本 1.1.5。
更新(2015年08月01日):新增自定义服务器端口功能(如不设定,默认为 8989)。
更新(2015年05月11日):更新 Shadowsocks-go 到版本 1.1.4。
更新(2015年03月09日):新增支持在 Debian,Ubuntu 下安装。
更新(2015年01月08日):修改了启动脚本 /etc/init.d/shadowsocks ,按照 CentOS 的 chkconfig 标准语法修改了一下(原来使用的是作者 Github 上自带的)。去掉了以 nobody 用户启动 shadowsocks 的方式,改为直接以当前登录用户直接启动(一般是 root 用户)。开机自启动,以及修改端口号提示无权限的问题已经解决。

## go一键安装脚本 #######################################################################

#!/usr/bin/env bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
#=================================================================#
# System Required: CentOS, Debian, Ubuntu #
# Description: One click Install Shadowsocks-go server #
# Author: Teddysun <i@teddysun.com> #
# Thanks: @cyfdecyf <https://twitter.com/cyfdecyf> #
# Intro: https://teddysun.com/392.html #
#==================================================================

clear
echo
echo "#############################################################"
echo "# One click Install Shadowsocks-go server #"
echo "# Intro: https://teddysun.com/392.html #"
echo "# Author: Teddysun <i@teddysun.com> #"
echo "# Github: https://github.com/shadowsocks/shadowsocks-go #"
echo "#############################################################"
echo

#Current folder
cur_dir=`pwd`

# Make sure only root can run our script
rootness(){
    if [[ $EUID -ne 0 ]]; then
      echo "Error:This script must be run as root!" 1>&2
      exit 1
    fi
}

#Check system
check_sys(){
    local checkType=$1
    local value=$2

    local release=''
    local systemPackage=''

    if [[ -f /etc/redhat-release ]]; then
        release="centos"
        systemPackage="yum"
    elif cat /etc/issue | grep -q -E -i "debian"; then
        release="debian"
        systemPackage="apt"
    elif cat /etc/issue | grep -q -E -i "ubuntu"; then
        release="ubuntu"
        systemPackage="apt"
    elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
        release="centos"
        systemPackage="yum"
    elif cat /proc/version | grep -q -E -i "debian"; then
        release="debian"
        systemPackage="apt"
    elif cat /proc/version | grep -q -E -i "ubuntu"; then
        release="ubuntu"
        systemPackage="apt"
    elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
        release="centos"
        systemPackage="yum"
    fi

    if [[ ${checkType} == "sysRelease" ]]; then
        if [ "$value" == "$release" ]; then
            return 0
        else
            return 1
        fi
    elif [[ ${checkType} == "packageManager" ]]; then
        if [ "$value" == "$systemPackage" ]; then
            return 0
        else
            return 1
        fi
    fi
}

# Get version
getversion(){
    if [[ -s /etc/redhat-release ]]; then
        grep -oE  "[0-9.]+" /etc/redhat-release
    else
        grep -oE  "[0-9.]+" /etc/issue
    fi
}

# CentOS version
centosversion(){
    if check_sys sysRelease centos; then
        local code=$1
        local version="$(getversion)"
        local main_ver=${version%%.*}
        if [ "$main_ver" == "$code" ]; then
            return 0
        else
            return 1
        fi
    else
        return 1
    fi
}

# is 64bit or not
is_64bit(){
    if [ `getconf WORD_BIT` = '32' ] && [ `getconf LONG_BIT` = '64' ] ; then
        return 0
    else
        return 1
    fi
}

# Disable selinux
disable_selinux(){
    if [ -s /etc/selinux/config ] && grep 'SELINUX=enforcing' /etc/selinux/config; then
        sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
        setenforce 0
    fi
}

get_ip(){
    local IP=$( ip addr | egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | egrep -v "^192\.168|^172\.1[6-9]\.|^172\.2[0-9]\.|^172\.3[0-2]\.|^10\.|^127\.|^255\.|^0\." | head -n 1 )
    [ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipv4.icanhazip.com )
    [ -z ${IP} ] && IP=$( wget -qO- -t1 -T2 ipinfo.io/ip )
    [ ! -z ${IP} ] && echo ${IP} || echo
}

# Pre-installation settings
pre_install(){
    if ! check_sys packageManager yum && ! check_sys packageManager apt; then
        echo "Error: Your OS is not supported. please change OS to CentOS/Debian/Ubuntu and try again."
        exit 1
    fi
    # Set shadowsocks-go config password
    echo "Please input password for shadowsocks-go:"
    read -p "(Default password: teddysun.com):" shadowsockspwd
    [ -z "${shadowsockspwd}" ] && shadowsockspwd="teddysun.com"
    echo
    echo "---------------------------"
    echo "password = ${shadowsockspwd}"
    echo "---------------------------"
    echo
    # Set shadowsocks-go config port
    while true
    do
    echo -e "Please input port for shadowsocks-go [1-65535]:"
    read -p "(Default port: 8989):" shadowsocksport
    [ -z "${shadowsocksport}" ] && shadowsocksport="8989"
    expr ${shadowsocksport} + 0 &>/dev/null
    if [ $? -eq 0 ]; then
        if [ ${shadowsocksport} -ge 1 ] && [ ${shadowsocksport} -le 65535 ]; then
            echo
            echo "---------------------------"
            echo "port = ${shadowsocksport}"
            echo "---------------------------"
            echo
            break
        else
            echo "Input error, please input correct number"
        fi
    else
        echo "Input error, please input correct number"
    fi
    done
    get_char(){
        SAVEDSTTY=`stty -g`
        stty -echo
        stty cbreak
        dd if=/dev/tty bs=1 count=1 2> /dev/null
        stty -raw
        stty echo
        stty $SAVEDSTTY
    }
    echo
    echo "Press any key to start...or Press Ctrl+C to cancel"
    char=`get_char`
    #Install necessary dependencies
    if check_sys packageManager yum; then
        yum install -y wget unzip gzip curl
    elif check_sys packageManager apt; then
        apt-get -y update
        apt-get install -y wget unzip gzip curl
    fi
    echo

}

# Download shadowsocks-go
download_files(){
    cd ${cur_dir}
    if is_64bit; then
        if ! wget --no-check-certificate -c https://github.com/shadowsocks/shadowsocks-go/releases/download/1.1.5/shadowsocks-server-linux64-1.1.5.gz; then
            echo "Failed to download shadowsocks-server-linux64-1.1.5.gz"
            exit 1
        fi
        gzip -d shadowsocks-server-linux64-1.1.5.gz
        if [ $? -eq 0 ]; then
            echo "Decompress shadowsocks-server-linux64-1.1.5.gz success."
        else
            echo "Decompress shadowsocks-server-linux64-1.1.5.gz failed! Please check gzip command."
            exit 1
        fi
        mv -f shadowsocks-server-linux64-1.1.5 /usr/bin/shadowsocks-server
    else
        if ! wget --no-check-certificate -c https://github.com/shadowsocks/shadowsocks-go/releases/download/1.1.5/shadowsocks-server-linux32-1.1.5.gz; then
            echo "Failed to download shadowsocks-server-linux32-1.1.5.gz"
            exit 1
        fi
        gzip -d shadowsocks-server-linux32-1.1.5.gz
        if [ $? -eq 0 ]; then
            echo "Decompress shadowsocks-server-linux32-1.1.5.gz success."
        else
            echo "Decompress shadowsocks-server-linux32-1.1.5.gz failed! Please check gzip command."
            exit 1
        fi
        mv -f shadowsocks-server-linux32-1.1.5 /usr/bin/shadowsocks-server
    fi

    # Download start script
    if check_sys packageManager yum; then
        if ! wget --no-check-certificate -O /etc/init.d/shadowsocks https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-go; then
            echo "Failed to download shadowsocks-go auto start script!"
            exit 1
        fi
    elif check_sys packageManager apt; then
        if ! wget --no-check-certificate -O /etc/init.d/shadowsocks https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-go-debian; then
            echo "Failed to download shadowsocks-go auto start script!"
            exit 1
        fi
    fi
}

# Config shadowsocks
config_shadowsocks(){
    if [ ! -d /etc/shadowsocks ]; then
        mkdir -p /etc/shadowsocks
    fi
    cat > /etc/shadowsocks/config.json<<-EOF
{
    "server":"0.0.0.0",
    "server_port":${shadowsocksport},
    "local_port":1080,
    "password":"${shadowsockspwd}",
    "method":"aes-256-cfb",
    "timeout":600
}
EOF
}

# Firewall set
firewall_set(){
    echo "firewall set start..."
    if centosversion 6; then
        /etc/init.d/iptables status > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            iptables -L -n | grep -i ${shadowsocksport} > /dev/null 2>&1
            if [ $? -ne 0 ]; then
                iptables -I INPUT -m state --state NEW -m tcp -p tcp --dport ${shadowsocksport} -j ACCEPT
                iptables -I INPUT -m state --state NEW -m udp -p udp --dport ${shadowsocksport} -j ACCEPT
                /etc/init.d/iptables save
                /etc/init.d/iptables restart
            else
                echo "port ${shadowsocksport} has been set up."
            fi
        else
            echo "WARNING: iptables looks like shutdown or not installed, please manually set it if necessary."
        fi
    elif centosversion 7; then
        systemctl status firewalld > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
            firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
            firewall-cmd --reload
        else
            echo "Firewalld looks like not running, try to start..."
            systemctl start firewalld
            if [ $? -eq 0 ]; then
                firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/tcp
                firewall-cmd --permanent --zone=public --add-port=${shadowsocksport}/udp
                firewall-cmd --reload
            else
                echo "WARNING: Try to start firewalld failed. please enable port ${shadowsocksport} manually if necessary."
            fi
        fi
    fi
    echo "firewall set completed..."
}

# Install Shadowsocks-go
install(){

    if [ -s /usr/bin/shadowsocks-server ]; then
        echo "shadowsocks-go install success!"
        chmod +x /usr/bin/shadowsocks-server
        chmod +x /etc/init.d/shadowsocks

        if check_sys packageManager yum; then
            chkconfig --add shadowsocks
            chkconfig shadowsocks on
        elif check_sys packageManager apt; then
            update-rc.d -f shadowsocks defaults
        fi

        /etc/init.d/shadowsocks start
        if [ $? -eq 0 ]; then
            echo "Shadowsocks-go start success!"
        else
            echo "Shadowsocks-go start failed!"
        fi
    else
        echo
        echo "Shadowsocks-go install failed!"
        exit 1
    fi

    clear
    echo
    echo "Congratulations, Shadowsocks-go install completed!"
    echo -e "Your Server IP: \033[41;37m $(get_ip) \033[0m"
    echo -e "Your Server Port: \033[41;37m ${shadowsocksport} \033[0m"
    echo -e "Your Password: \033[41;37m ${shadowsockspwd} \033[0m"
    echo -e "Your Local Port: \033[41;37m 1080 \033[0m"
    echo -e "Your Encryption Method: \033[41;37m aes-256-cfb \033[0m"
    echo
    echo "Welcome to visit:https://teddysun.com/392.html"
    echo "Enjoy it!"
    echo
}

# Uninstall Shadowsocks-go
uninstall_shadowsocks_go(){
    printf "Are you sure uninstall shadowsocks-go? (y/n) "
    printf "\n"
    read -p "(Default: n):" answer
    [ -z ${answer} ] && answer="n"
    if [ "${answer}" == "y" ] || [ "${answer}" == "Y" ]; then
        ps -ef | grep -v grep | grep -i "shadowsocks-server" > /dev/null 2>&1
        if [ $? -eq 0 ]; then
            /etc/init.d/shadowsocks stop
        fi
        if check_sys packageManager yum; then
            chkconfig --del shadowsocks
        elif check_sys packageManager apt; then
            update-rc.d -f shadowsocks remove
        fi
        # delete config file
        rm -rf /etc/shadowsocks
        # delete shadowsocks
        rm -f /etc/init.d/shadowsocks
        rm -f /usr/bin/shadowsocks-server
        echo "Shadowsocks-go uninstall success!"
    else
        echo
        echo "Uninstall cancelled, nothing to do..."
        echo
    fi
}

# Install Shadowsocks-go
install_shadowsocks_go(){
    rootness
    disable_selinux
    pre_install
    download_files
    config_shadowsocks
    if check_sys packageManager yum; then
        firewall_set
    fi
    install
}

# Initialization step
action=$1
[ -z $1 ] && action=install
case "$action" in
    install|uninstall)
    ${action}_shadowsocks_go
    ;;
    *)
    echo "Arguments error! [${action}]"
    echo "Usage: `basename $0` {install|uninstall}"
    ;;
esac

本文来自:开源中国博客

感谢作者:PengTdy

查看原文:Shadowsocks-go一键安装脚本

入群交流(和以上内容无关):Go中文网 QQ 交流群:798786647 或加微信入微信群:274768166 备注:入群;关注公众号:Go语言中文网

4482 次点击  
加入收藏 微博
下一篇:go中的interface
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传