Shadowsocks 服务器安装--针对Centos 7 x64

MacOS 连接 远程服务器

sudo -i //切换到root

ssh root@ip //进行连接

搭建 Shadowsocks 服务

1
2
3
$ yum install m2crypto python-setuptools
$ easy_install pip
$ pip install shadowsocks

安装完成后配置服务器参数

$ vi /etc/shadowsocks.json

json 内容

1
2
3
4
5
6
7
8
9
10
11
{
"server":"0.0.0.0",
"server_port":443,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"123456", #自行修改
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false
}

配置防火墙

$ yum install firewalld
$ systemctl start firewalld

开启防火墙相应的端口

$ firewall-cmd --permanent --zone=public --add-port=443/tcp
$ firewall-cmd --reload

启动 Shadowsocks 服务

前台运行

$ ssserver -c /etc/shadowsocks.json

后台运行服务

sudo ssserver -c /etc/shadowsocks.json -d start

开机自启动

Google BBR VPS加速

BBR 是 Google 提出的一种新型拥塞控制算法,可以使 Linux 服务器显著地提高吞吐量和减少 TCP 连接的延迟。

BBR解决了两个问题:

再有一定丢包率的网络链路上充分利用带宽。非常适合高延迟,高带宽的网络链路。

降低网络链路上的buffer占用率,从而降低延迟。非常适合慢速接入网络的用户。

项目地址:https://github.com/google/bbr

升级内核
开启 BBR 要求 4.10 以上版本 Linux 内核,可使用如下命令查看当前内核版本:

uname -r
可以得到类似如下的结果:

3.10.0-514.10.2.el7.x86_64
如果当前内核版本低于 4.10,可使用 ELRepo 源更新:

1
2
3
sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
sudo yum --enablerepo=elrepo-kernel install kernel-ml -y

安装完成后,查看已安装的内核:

rpm -qa | grep kernel
得到结果如下:

1
2
3
4
5
6
kernel-3.10.0-123.el7.x86_64
kernel-headers-3.10.0-514.16.1.el7.x86_64
kernel-ml-4.11.0-1.el7.elrepo.x86_64
kernel-tools-3.10.0-514.16.1.el7.x86_64
kernel-3.10.0-514.16.1.el7.x86_64
kernel-tools-libs-3.10.0-514.16.1.el7.x86_64

在输出中看到 kernel-ml-4.11.0-1.el7.elrepo.x86_64 类似的内容,表示安装成功。

修改grub2引导
执行:

sudo egrep ^menuentry /etc/grub2.cfg | cut -f 2 -d \'
会得到如下结果:

1
2
3
4
5
CentOS Linux 7 Rescue a0cbf86a6ef1416a8812657bb4f2b860 (4.11.0-1.el7.elrepo.x86_64)
CentOS Linux (4.11.0-1.el7.elrepo.x86_64) 7 (Core)
CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)
CentOS Linux (3.10.0-123.el7.x86_64) 7 (Core)
CentOS Linux (0-rescue-2d3f9371c20d3e90a544ccc814d485e3) 7 (Core)

由于序号从0开始,设置默认启动项为1并重启系统:

1
2
sudo grub2-set-default 1
reboot

重启完成后,重新登录并重新运行uname命令来确认你是否使用了正确的内核:

uname -r
得到如下结果则升级成功:

4.11.0-1.el7.elrepo.x86_64
开启BBR
执行:

1
2
3
echo 'net.core.default_qdisc=fq' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_congestion_control=bbr' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

完成后,分别执行如下命令来检查 BBR 是否开启成功:

1
2
3
4
5
6
sudo sysctl net.ipv4.tcp_available_congestion_control
# 输出应为 net.ipv4.tcp_available_congestion_control = bbr cubic reno
sudo sysctl -n net.ipv4.tcp_congestion_control
# 输出应为 bbr
lsmod | grep bbr
# 输出应类似 tcp_bbr 16384 28

速度测试

需先在 firewalld 中开启 http 服务

1
sudo dd if=/dev/zero of=500mb.zip bs=1024k count=500