EverKB

Knowledge Base Ever

在CentOS7上使用TeddySun腳本安裝Shadowsocks服務並優化TcpBBR

2020-01-13 14:39:19

標籤: Shadowsocks,ShadowsocksR,Shadowsocks-Python,Shadowsocks-Libev,CentOS,CentOS7,Tcp BBR,

某些場景需要使用Shadowsocks服務,在CentOS7上安裝Shadowsocks可以參考官方文檔,也可以使用來自TeddySun的一段很方便的腳本。

準備工作,安裝必要的軟件

sudo -i
yum install wget vim -y

三行命令,使用腳本安裝Shadowsocks服務

wget --no-check-certificate -O shadowsocks-all.sh https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-all.sh

chmod +x shadowsocks-all.sh

./shadowsocks-all.sh 2>&1 | tee shadowsocks-all.log
腳本會詢問你使用哪一種服務器,有Python, R, Go, libev四種,按筆者理解,
Python:成熟
R:加入了混淆
Go:可能有更好的並發
libev:基於異步庫,理論上並發最好

如果沒有特別苛刻的需求,採用默認的Shadowsocks-Python即可,接著腳本會提示輸入密碼和端口,以及加密方法,可使用:xchacha20-ietf-poly1305、chacha20-ietf-poly1305、aes-256-gcm等
Which Shadowsocks server you'd select:
1.Shadowsocks-Python
2.ShadowsocksR
3.Shadowsocks-Go
4.Shadowsocks-libev
Please enter a number (default 1):
安裝完成後,腳本會給與一個安裝配置信息的反饋,這個配置在/etc/shadowsocks-python/config.json中,如果有需要,也可以安裝後使用VIM修改。
Congratulations, Shadowsocks-Python server install completed!
Your Server IP        :  x.x.x.x
Your Server Port      :  12345
Your Password         :  PASSWORD
Your Encryption Method:  aes-256-gcm

高級配置部分

BBR是Bottleneck Bandwidth and Round-trip Time的簡稱,這裡TeddySun也提供了一個腳本來安裝。
wget --no-check-certificate https://github.com/teddysun/across/raw/master/bbr.sh

chmod +x bbr.sh

./bbr.sh
執行完成以後,可以使用sysctl命令查看並確認配置的值如下
[root@instance-1 ~]# sysctl net.ipv4.tcp_available_congestion_control
net.ipv4.tcp_available_congestion_control = reno cubic bbr
[root@instance-1 ~]# sysctl net.ipv4.tcp_congestion_control
net.ipv4.tcp_congestion_control = bbr
[root@instance-1 ~]# sysctl net.core.default_qdisc
net.core.default_qdisc = fq
[root@instance-1 ~]# lsmod | grep bbr
tcp_bbr                20480  12
如果返回值和上述不同,則執行如下代碼:
echo "net.core.default_qdisc = fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
最後,啟動服務。也可以編寫一個腳本。
/etc/init.d/shadowsocks-python restart
非CentOS使用Linux通用方法創建控制腳本
sudo vim /etc/init.d/shadowsocks
#!/bin/sh
### BEGIN INIT INFO
# Provides: shadowsocks
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start shadowsocks
# Description: start shadowsocks
### END INIT INFO
start(){
   ssserver -c /etc/ss-conf.json -d start
}
stop(){
   ssserver -c /etc/ss-conf.json -d stop
}
case “$1” in
start)
   start
   ;;
stop)
   stop
   ;;
reload)
   stop
   start
   ;;
*)
   echo “Usage: $0 {start|reload|stop}”
   exit 1
   ;;
esac
sudo chmod +x /etc/init.d/shadowsocks
添加到開機啟動中
sudo vim /etc/init/shadowsocks.conf
start on (runlevel [2345])stop on (runlevel [016])pre-start script
/etc/init.d/shadowsocks start
end script
post-stop script
/etc/init.d/shadowsocks stop
end script
sudo update-rc.d shadowsocks defaults

標籤

CentOS7 CentOS PHP Linux Python Python3 MySQL MariaDB YUM JavaScript mysql_native_password PHP7 CSS Redis MySQL8 caching_sha2_password HTML Bluetooth Failed to build these modules: _ctypes Minimal ISO substr date sub INTERVAL PECL SQL Date Funcitons Wi-Fi CodeIgniter font-size root Tag Cloud apache httpd dual network interfaces Laravel ss5 CURLFille horiz-align node.js ShadowsocksR vertical-align BarManager exec mb_substr PyCharm SUBDATE date add IntelliJIDEA PEAR SOCKS5 Proxy Server WebStorm Chrome find remi Tag Apache du jQuery PHP5.5 src cURL hide nginx Shadowsocks-Python V2Ray availability eth0 MariaDB10.4 PostgreSQL sub folder date Install MongoDB pdo_sqlsrv SOCKS5 Web Server File Upload mssql-tools register_shutdown_function Symfony ADDDATE DevExpress JetBrain php-fpm sqlsrv Zend Framework height network interface Shadowsocks-Libev unixODBC-devel Aura error_get_last Port 80 string data INDENTIFIED BY password policy requirements SOCKS Web Development Fedora Media Writer msodbcsql Redis5 SVN absolute Deepin jemalloc SQLAlchemy convert FuelPHP mysqlclient Shadowsocks toggle at-symbol Error Control Operator margin PHPUnit Framework ss5.passwd daemon process IIS password SOCKET vps center Fatal Errors MongoDB4 sudoers .htaccess DATE_SUB Phalcon SQL Server 2017 WiFi Compiling PHP frequency conflict set_error_handler TestCase apr Elasticsearch7.3 PHPUnit ss5.conf daemon HTTP particles.js Slim Vincent Garreau Failed to build these modules: _uuid MongoDB Sudo DATE_ADD ip command pg_bha.conf SQL Server width Compiling Apache Frameworks MySQL-python scrollbar Tcp BBR Apache2.4 Elasticsearch libpython3.7m.so.1.0 PHPStorm ss5-3.8.9 CURLOPT_POSTFIELDS NodeJs show VIM