在 Centos7 上搭建 shadowsocks

安装epel源

$ sudo yum -y install epel-release

安装pip包管理

$ sudo yum -y install python-pip

使用pip安装shadowsocks

$ sudo pip install shadowsocks
如果出现 Command "python setup.py egg_info" failed 错误信息,则输入 pip install --upgrade pip 命令后,再执行上面的操作。
如果出现 Could not import setuptools which is required to install from a source distribution 错误信息,则输入 pip install setuptools 命令后,再执行上面的操作。

建立shadowsocks配置文件

$ sudo vi /etc/shadowsocks/shadowsocks.json

单端口配置

{
 "server":"0.0.0.0",
 "server_port":8838,
 "local_address": "127.0.0.1",
 "local_port":1080,
 "password":"123456",
 "timeout":300,
 "method":"aes-256-cfb",
 "fast_open": false
}

多端口配置

{
 "server":"0.0.0.0",
 "local_address": "127.0.0.1",
 "local_port":1080,
 "port_password": {
 "8838": "123456"
 },
 "timeout":300,
 "method":"aes-256-cfb",
 "fast_open": false
}

开启防火墙的端口访问

$ sudo firewall-cmd --zone=public --add-port=8388/tcp --permanent;
$ sudo firewall-cmd --reload;

启动shadowsocks

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

配置shadowsocks服务自启动

编辑 shadowsocks 服务配置文件

$ sudo vi /etc/systemd/system/shadowsocks.service
# shadowsocks.service

[Unit]
Description=Shadowsocks
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/ssserver -c /etc/shadowsocks/shadowsocks.json -d start
ExecReload=/usr/bin/ssserver -c /etc/shadowsocks/shadowsocks.json -d restart
ExecStop=/usr/bin/ssserver -d stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

服务的启动与关闭

$ systemctl start shadowsocks  // 启动
$ systemctl stop shadowsocks // 停止
$ systemctl restart shadowsocks // 重启
$ systemctl enable shadowsocks // 启用开机启动
$ systemctl disable shadowsocks // 禁用开机启动

发表评论