install_ss-server.sh 3.4 KB

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