标签 synology 下的文章

作者: reistlin
来源: http://www.reistlin.com/blog/434
更新时间: 2023.02
版权声明: 原创文章.转载请保留作者信息和原文完整.谢绝任何方式的摘要

linux.gif

一,Ubuntu 16.04.7 配置(VMware x86 64bit)

1,下载安装 Ubuntu 16.04,内核版本 4.4(非常重要!需要与群晖 Synology DSM 6.2.4 版本一致

uname -a
Linux ubuntu 4.4.0-186-generic #216-Ubuntu SMP Wed Jul 1 05:34:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/os-release
 
NAME="Ubuntu"
VERSION="16.04.7 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.7 LTS"
VERSION_ID="16.04"

2,安装 ubuntu 编译环境

apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake libmbedtls-dev libsodium-dev pkg-config

3,交叉编译安装 libsodium-1.0.16,安装路径: /usr

下载 Synology DSM 6.2.4 Tool Chains 环境
选择 DS220+ 对应的 Intel x86 Linux 4.4.59 (GeminiLake) 目录
选择 geminilake-gcc493_glibc220_linaro_x86_64-GPL.txz 下载

wget https://sourceforge.net/projects/dsgpl/files/Tool%20Chain/DSM%206.2.4%20Tool%20Chains/Intel%20x86%20Linux%204.4.59%20%28GeminiLake%29/geminilake-gcc493_glibc220_linaro_x86_64-GPL.txz/download
tar Jxvf geminilake-gcc493_glibc220_linaro_x86_64-GPL.txz
cd x86_64-pc-linux-gnu

配置环境变量,启用 DSM 6.2.4 Tool Chains 交叉编译 libsodium-1.0.16

export PATH="/root/x86_64-pc-linux-gnu/bin:$PATH"
export CC=/root/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-gcc
export LD=/root/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ld
export RANLIB=/root/x86_64-pc-linux-gnu/bin/x86_64-pc-linux-gnu-ranlib
export CFLAGS="-I/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/include"
export LDFLAGS="-L/root/x86_64-pc-linux-gnu/x86_64-pc-linux-gnu/lib"

交叉编译安装 libsodium-1.0.16,安装路径: /usr

wget https://download.libsodium.org/libsodium/releases/old/libsodium-1.0.16.tar.gz
tar zxvf libsodium-1.0.16.tar.gz
cd libsodium-1.0.16
./configure --prefix=/usr
make
make install
ldconfig

4,编译安装 mbedtls-2.6.1,安装路径: /usr

wget https://codeload.github.com/Mbed-TLS/mbedtls/tar.gz/refs/tags/mbedtls-2.6.1
tar zxvf mbedtls-mbedtls-2.6.1.tar.gz
cd mbedtls-mbedtls-2.6.1
make SHARED=1 CFLAGS="-O2 -fPIC"
make DESTDIR=/usr install
ldconfig

5,编译安装 shadowsocks-libev,安装路径: /root/shadowsocks

wget https://github.com/shadowsocks/shadowsocks-libev/releases/download/v3.3.5/shadowsocks-libev-3.3.5.tar.gz
tar zxvf shadowsocks-libev-3.3.5.tar.gz 
cd shadowsocks-libev-3.3.5
autoreconf --install --force
./configure --prefix=/root/shadowsocks --with-sodium-include=/usr/include --with-sodium-lib=/usr/lib --with-mbedtls-include=/usr/include --with-mbedtls-lib=/usr/lib
make
make install

注意!./configure 需要指定 libsodium-1.0.16 和 mbedtls-2.6.1 的 include 和 lib 路径,否则 make 时会报错

ss_local-aead.o: In function `aead_cipher_decrypt'''':
/root/pkgs/shadowsocks-libev-3.3.5/src/aead.c:239: undefined reference to `crypto_aead_xchacha20poly1305_ietf_decrypt''''
ss_local-aead.o: In function `aead_cipher_encrypt'''':
/root/pkgs/shadowsocks-libev-3.3.5/src/aead.c:192: undefined reference to `crypto_aead_xchacha20poly1305_ietf_encrypt''''
collect2: error: ld returned 1 exit status

6,复制 ubuntu 系统 so 文件到 /root/shadowsocks/lib/ 目录,用于后续群晖 DSM 6.2.4 系统正常运行依赖。总计 4 个文件:

libev.so.4.0.0
libpcre.so.3.13.2
libsodium.so.23.1.0
libmbedcrypto.so.0

cd /root/shadowsocks/lib/
cp -a /usr/lib/x86_64-linux-gnu/libev.so.4.0.0 .
cp -a /lib/x86_64-linux-gnu/libpcre.so.3.13.2 .
cp -a /usr/lib/libsodium.so.23.1.0 .
cp -a /usr/lib/libmbedcrypto.so.0 .

7,新建 shell 脚本,用于后续 so 文件 symbolic link 到群晖 DSM 6.2.4 系统 /usr/lib/ 目录

vim /root/shadowsocks/lib/libshadowsocks-libev.sh
 
#!/bin/sh
 
ln -s /root/shadowsocks/lib/libev.so.4.0.0 /usr/lib/libev.so.4
ln -s /root/shadowsocks/lib/libpcre.so.3.13.2 /usr/lib/libpcre.so.3
ln -s /root/shadowsocks/lib/libsodium.so.23.1.0 /usr/lib/libsodium.so.23
ln -s /root/shadowsocks/lib/libmbedcrypto.so.0 /usr/lib/libmbedcrypto.so.0

chmod 755 /root/shadowsocks/lib/libshadowsocks-libev.sh

8,完成所有配置,压缩打包 /root/shadowsocks 目录为 shadowsocks.tar.gz,下载。

cd /root
tar zcvf shadowsocks.tar.gz shadowsocks

二,群晖 DS220+ 配置(Synology DS220+ Intel Celeron J4025 Geminilake)

1,将 shadowsocks.tar.gz 上传至群晖 DS220+

2,切换群晖 root 用户

sudo -i

3,进入 root 目录,解压缩 shadowsocks.tar.gz
运行 shadowsocks/lib 目录下的 libshadowsocks-libev.sh
将 so 文件 symbolic link 到 /usr/lib/

cd /root
tar zxvf shadowsocks.tar.gz
cd shadowsocks/lib
./libshadowsocks-libev.sh

4,正式启动,运行 ss-local,-c 参数指定 jsoin 配置文件,-f 参数指定 pid 文件
默认加密方法:chacha20-ietf-poly1305

cd /root/shadowsocks/bin/
./ss-local -c /root/shadowsocks/etc/ss.json -f /root/shadowsocks/etc/ss.pid