Centos部署shadowsocks

Administrator 16 2023-07-26
  • Shadowsocks协议问题不支持跨国链接 例大陆>香港是无法连接的。

Centos部署shadowsocks

1.安装pip3

yum install -y python3-pip

2.安装shadowsocks3.0.0

pip3 install https://github.com/shadowsocks/shadowsocks/archive/master.zip

3.查看shadowsocks版本

ssserver –version

4.创建配置文件

vi /etc/shadowsocks.json
{
    "server" :"你的IP地址",
    #对外供连接地址
    "server_port" :19400,
    #服务shadowsocks服务端口
    "local_port" :1080,
    #本地端口
    "password" : "your password",
    #密码
    "timeout" :600,
    #连接时间
    "method" : "aes-256-gcm"
    #加密类型
}

5.启动方法
5.1、交互式启动,测试使用,勿生产环境使用

ssserver -c /etc/shadowsocks.json  

5.2、配置后台运行、配置为系统服务

  • vi /etc/systemd/system/shadowsocks-server.service
  • 输入以下内容:
[Unit]
Description=Shadowsocks Server
After=network.target

[Service]
ExecStart=/usr/bin/ssserver -c /etc/shadowsocks.json
Restart=on-abort

[Install]
WantedBy=multi-user.target
  • 启动、设置开机自启
systemctl daemon-reload
  • 重载
systemctl start shadowsocks-server
systemctl enable shadowsocks-server
  • 操作
前端启动:ssserver -c /etc/shadowsocks.json
后端启动:ssserver -c /etc/shadowsocks.json -d start
停止:ssserver -c /etc/shadowsocks.json -d stop
重启(修改配置需要重启才生效):ssserver -c /etc/shadowsocks.json -d restart
#服务安装路径 可使用命令查找 
#命令 whereis ssserver  
#默认在/usr/bin/ssserver

debian12部署shadowsocks

方法1. 从snap安装。
如果OS支持snap,那么先安装snap core,再安装shadowsocks-libev即可,非常简单;不过后续开机自启等配置步骤是不太一样的,本文暂未描述,暂请自行研究。

sudo apt-get updatesudo 
apt-get install shadowsocks-libev 

方法2. 使用脚本自动编译deb安装,适用于Debian (>=8) / Ubuntu 14.04 (Trusty) / 16.04 (Xenial) / 16.10 / Higher
(会自动编译安装所有依赖包,并同时安装simpleobfs plugin)

mkdir ./build-area
cd build-area
wget https://github.com/shadowsocks/shadowsocks-libev/raw/master/scripts/build_deb.sh
chmod +x build_deb.sh
./build_deb.sh all 

方法3. 手动编译安装(Ubuntu 16.04 / Debian 8及以上),在你需要从最新master源码编译时候可以使用这种方式。
先通过git下载源码:

git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init --recursive 

安装必须的包:

sudo apt-get install --no-install-recommends autoconf automake \    debhelper pkg-config asciidoc xmlto libpcre3-dev apg pwgen rng-tools \    libev-dev libc-ares-dev dh-autoreconf libsodium-dev libmbedtls-dev 

Debian 8的用户,注意需要从Debian Backports安装libsodium(最低版本v1.0.8)。
注意:新版本需要debhelper版本大于等于10,不满足的请使用Backports安装新版debhelper:

# 仅举例 Ubuntu 16.04 LTS
# 先添加backports(添加过的跳过)
echo 'deb http://archive.ubuntu.com/ubuntu xenial-backports main' > /etc/apt/sources.list.d/xenial-backports.list
# 安装
sudo apt update
sudo apt install debhelper/xenial-backports
# backports中的软件较新,可以顺道更新一下
sudo apt upgrade

然后生成deb包并安装,一步步执行(留意是否出错 如果出错需要检查系统或者之前的步骤):

./autogen.sh && dpkg-buildpackage -b -us -uc
cd ..
sudo dpkg -i shadowsocks-libev*.deb

其他Unix-like的系统,特别是Debian-based的Linux发行版如: Ubuntu, Debian or Linux Mint
先从最近的源码编译安装libmbedtls和libsodium

export LIBSODIUM_VER=1.0.11
export MBEDTLS_VER=2.4.0
wget https://download.libsodium.org/libsodium/releases/libsodium-$LIBSODIUM_VER.tar.gz
tar xvf libsodium-$LIBSODIUM_VER.tar.gz
pushd libsodium-$LIBSODIUM_VER
./configure --prefix=/usr && make
sudo make install
popd
wget https://tls.mbed.org/download/mbedtls-$MBEDTLS_VER-gpl.tgz
tar xvf mbedtls-$MBEDTLS_VER-gpl.tgz
pushd mbedtls-$MBEDTLS_VER
make SHARED=1 CFLAGS=-fPIC
sudo make DESTDIR=/usr install
popd

安装依赖包:

# Debian / Ubuntu
sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake
# CentOS / Fedora / RHEL
sudo yum install gettext gcc autoconf libtool automake make asciidoc xmlto c-ares-devel libev-devel
# Arch
sudo pacman -S gettext gcc autoconf libtool automake make asciidoc xmlto libev c-ares

编译:

./autogen.sh && ./configure && make
sudo make install

二、配置与启动

1、配置文件为:/etc/shadowsocks-libev/config.json,格式说明:

{
	"server":"example.com or X.X.X.X",
	"mode":"tcp_and_udp",
	"server_port":443,
	"password":"password",
	"method":"aes-128-gcm",
	"fast_open":true,
	"timeout":60
}

其中:
server:主机域名或者IP地址,尽量填IP
server_port:服务器监听端口
password:密码
method:加密方式 所有支持的加密方式请参照官方文档。这里本人推荐只使用支持AEAD的加密方式,包括以下五种: aes-128-gcm/aes-192-gcm/aes-256-gcm/chacha20-ietf-poly1305/xchacha20-ietf-poly1305
timeout:连接超时时间,单位秒。要适中。
注意引号。

2、控制启动、停止、重启:
由于目前大部分新的linux发行版都已经支持systemd,因此,可以统一使用如下命令

# Start
sudo systemctl start shadowsocks-libev.service
# Stop
sudo systemctl stop shadowsocks-libev.service
# Restart
sudo systemctl restart shadowsocks-libev.service