1
0

install_ss-server.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/bash
  2. # 定义文字颜色
  3. Green="\033[32m" && Red="\033[31m" && GreenBG="\033[42;37m" && RedBG="\033[41;37m" && Font="\033[0m"
  4. echo -e "${Green}:: Quick install Shadowsocks-libev For Linux X64 (Debian 8/9/10 Ubuntu 16/18/19 Centos 7) ${Font}"
  5. echo -e "${Green}:: Compile/Update: ${RedBG} bash <(curl -L -s git.io/fhExJ) update ${Font}"
  6. def_install(){
  7. # Download the binary release of Pure Compilation.
  8. wget -O /tmp/ss.tgz https://git.io/ss.tgz
  9. tar xvf /tmp/ss.tgz -C /
  10. echo "/usr/local/lib" > /etc/ld.so.conf.d/ss-libev.conf
  11. ldconfig
  12. export PATH=$PATH:/usr/local/bin
  13. rm /tmp/ss.tgz
  14. }
  15. old_def_install(){
  16. if [[ ${release} == "centos" ]]; then
  17. # 安装所需运行库 Centos 7
  18. yum update -y
  19. yum install -y libev-devel c-ares-devel mbedtls-devel libsodium-devel
  20. else
  21. # 安装所需运行库 Debian 9 & Ubuntu 18
  22. apt update
  23. apt install -y libev-dev libc-ares-dev libmbedtls-dev libsodium-dev
  24. fi
  25. # 下载 ss-server 对应各系统
  26. wget https://raw.githubusercontent.com/hongwenjun/vps_setup/master/shadowsocks/${release}/ss-server
  27. chmod +x ss-server && mv ss-server /usr/local/bin/ss-server
  28. }
  29. debian_ubuntu_dev(){
  30. # Debian 9 & Ubuntu 安装编译环境和运行库
  31. apt update
  32. apt install -y gcc g++ git gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake libmbedtls-dev libsodium-dev
  33. }
  34. centos7_dev(){
  35. # Cetons 安装编译环境和运行库
  36. yum install epel-release git -y
  37. yum groupinstall "Development Tools" -y
  38. yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y
  39. }
  40. inst_ss-server(){
  41. # 下载shadowsocks代码
  42. git clone --recursive https://github.com/shadowsocks/shadowsocks-libev --depth=1
  43. cd shadowsocks-libev
  44. git submodule update --init --recursive
  45. # 编译安装ss-server
  46. ./autogen.sh
  47. ./configure
  48. make
  49. make install
  50. cd ..
  51. # rm shadowsocks-libev -rf
  52. }
  53. # 检查系统
  54. check_sys(){
  55. if [[ -f /etc/redhat-release ]]; then
  56. release="centos"
  57. elif cat /etc/issue | grep -q -E -i "debian"; then
  58. release="debian"
  59. elif cat /etc/issue | grep -q -E -i "ubuntu"; then
  60. release="ubuntu"
  61. elif cat /etc/issue | grep -q -E -i "centos|red hat|redhat"; then
  62. release="centos"
  63. elif cat /proc/version | grep -q -E -i "debian"; then
  64. release="debian"
  65. elif cat /proc/version | grep -q -E -i "ubuntu"; then
  66. release="ubuntu"
  67. elif cat /proc/version | grep -q -E -i "centos|red hat|redhat"; then
  68. release="centos"
  69. fi
  70. bit=`uname -m`
  71. }
  72. sysctl_config() {
  73. sed -i '/net.core.default_qdisc/d' /etc/sysctl.conf
  74. sed -i '/net.all.tcp_congestion_control/d' /etc/sysctl.conf
  75. echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
  76. echo "net.all.tcp_congestion_control = bbr" >> /etc/sysctl.conf
  77. sysctl -p >/dev/null 2>&1
  78. }
  79. # 开启 BBR
  80. sysctl_config
  81. lsmod | grep bbr
  82. # 判断系统安装软件
  83. update_ss-server(){
  84. if [[ ${release} == "centos" ]]; then
  85. centos7_dev
  86. inst_ss-server
  87. fi
  88. if [[ ${release} == "ubuntu" ]]; then
  89. debian_ubuntu_dev
  90. inst_ss-server
  91. fi
  92. if [[ ${release} == "debian" ]]; then
  93. debian_ubuntu_dev
  94. inst_ss-server
  95. fi
  96. }
  97. # 安装 ss-server
  98. check_sys
  99. if [[ $# > 0 ]]; then
  100. key="$1"
  101. case $key in
  102. update)
  103. update_ss-server
  104. ;;
  105. esac
  106. else
  107. if [ ! -f '/usr/local/bin/ss-server' ]; then
  108. def_install
  109. fi
  110. # 如果运行库错误,编译/更新安装
  111. /usr/local/bin/ss-server -v >/dev/null 2>&1
  112. if [ $? == 127 ]; then
  113. update_ss-server
  114. fi
  115. fi