install_ss-server.sh 3.3 KB

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