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