Debian11下编译安装Shadowsocks-libev 作者: Hogwarts 发布于: 2022-05-25 更新于: 2022-07-02 分类: 红杏出墙 其实刚开始写博客时是打算以shadowsocks-libev的安装为开端的,当时比较之下感觉go2版本安装简单;而且秋水逸冰的一键安装是那么的方便,再有编译安装shadowsocks-libev的文章很多,懒得再造轮子了。 近期mack a大佬写了一份IP白名单教程,毕世平也推荐了一份IP白名单,勾起了安装shadowsocks-libev的欲望。libev版一直是秋水逸冰推荐的安装版本,奈当时因为认知问题一直安装的是不再维护的python版。为啥呢,因为python版的运行文件可以非常简单的实现多用户多端口的问题。当时想的是每个用户用自己的端口,要是多用户共用一个端口的话,会不会造成网络的拥堵。见笑了! 经测试在Debian11下apt install shadowsocks-libev的版本为3.3.4,对于强迫症患者来说差0.0.1也算差呀。 #一、编译前的准备工作 基本编译器就不再多说了,Libsodium和MbedTLS这两个软件在秋水逸冰的一键脚本中是单独安装的,就照猫画虎了。 ##1.1 安装编译器及依赖 **本文以Debian11为例** apt update && apt upgrade –y apt install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake 如果不编译安装libsodium和MbedTLS,则需 apt install libmbedtls-dev libsodium-dev 编译安装libsodium和MbedTLS的话,继续1.2和1.3。 ##1.2 编译安装libsodium wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz tar -zxvf LATEST.tar.gz cd libsodium-stable ./configure --prefix=/usr make && make install ldconfig cd ##1.3 编译安装MbedTLS - MbedTLS官网稳定版本为2.16.6 `https://tls.mbed.org/download-archive` - 其中分为Apache版和GPL版,经搜索是两个许可的问题,建议Apache版吧。 - 建议安装1.4中的2.28.0版本。 wget https://tls.mbed.org/download/mbedtls-2.16.6-apache.tgz tar -zxvf mbedtls-2.16.6-apache.tgz cd mbedtls-2.16.6 make SHARED=1 CFLAGS="-O2 -fPIC" make DESTDIR=/usr install ldconfig cd pushd和popd这俩命令还没搞清楚,待学习。 ## 1.4 MbedTLS填坑 MbedTLS最新版本已经到了3.1.0 `https://github.com/Mbed-TLS/mbedtls/releases` 尝试安装3.1.0版本,安装成功后,编译shadowsocks-libev时报错 checking whether mbedtls supports Cipher Feedback mode or not... configure: error: MBEDTLS_CIPHER_MODE_CFB required 经搜索,shadowsocks-libev3.3.5最高支持mbedtls的版本为2.28.0。待测试。 Ps:2.28.0完美运行。 wget https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v2.28.0.tar.gz tar -zxvf v2.28.0.tar.gz cd mbedtls-2.28.0 make SHARED=1 CFLAGS="-O2 -fPIC" make DESTDIR=/usr install ldconfig cd #二、编译安装shadowsocks-libev ##方式一 ##2.1 下载源码 git clone https://github.com/shadowsocks/shadowsocks-libev.git ##2.2 编译源码 ###2.2.1 cd /root/shadowsocks-libev ###2.2.2 apt install pkg-config 不执行此命令有可能执行autogen.sh时报错 `https://github.com/shadowsocks/shadowsocks-libev/issues/2818` configure.ac:26: error: possibly undefined macro: AC_MSG_ERROR If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation. configure.ac:146: error: possibly undefined macro: AC_CHECK_HEADERS configure.ac:256: error: possibly undefined macro: AC_SEARCH_LIBS autoreconf: /usr/bin/autoconf failed with exit status: 1 ###2.2.4 ./autogen.sh 有可能会报错 `https://github.com/shadowsocks/shadowsocks-libev/issues/2464` configure.ac:244: error: required file 'libbloom/Makefile.in' not found configure.ac:244: error: required file 'libcork/Makefile.in' not found configure.ac:244: error: required file 'libipset/Makefile.in' not found 执行 git submodule update --init --recursive 不报错执行 ./autogen.sh 如果还报错 error: pathspec '–recursive' did not match any file(s) known to git 执行 git submodule init && git submodule update `https://github.com/shadowsocks/shadowsocks-libev/issues/1095` 再执行 ./autogen.sh ### 2.2.5 ./configure --disable-documentation ### 2.2.6 make && make install ##方式二 20220702PS:经指点,下载作者发布的Release包可省略`./autogen.sh`、`git submodule update --init --recursive` 等步骤。 ##2.1 下载作者发布的包并解压 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 #解压 ##2.2 编译 cd shadowsocks-libev-3.3.5 ./configure --disable-documentation make && make install 参考:`https://shiping.date/69.html` #三、shadowsocks-libev文件配置 ##3.1 配置运行文件 mkdir /etc/shadowsocks-libev/ vim /etc/shadowsocks-libev/config.json { "server":"0.0.0.0", "mode":"tcp_only", "server_port":port, "local_port":1080, "password":"password", "fast_open":false, "nameserver":"8.8.8.8", "timeout":300, "method":"aes-256-gcm" } **注意** **server_port**:需修改为自己的端口。 **password**:需修改为自己的密码。 **mode**:为tcp_only,不能为tcp_and_udp。 **fast_open**:为false,不能为true。 **method**:选aes-256-gcm或chacha20-ietf-poly1305,**不可用aes-128-gcm**。 ##3.2 配置开机运行 vim /etc/systemd/system/shadowsocks-libev.service [Unit] Description=Shadowsocks-libev Default Server Service Documentation=man:shadowsocks-libev After=network-online.target Wants=network-online.target [Service] User=nobody Type=simple ExecStart=/usr/local/bin/ss-server -c /etc/shadowsocks-libev/config.json Restart=always [Install] WantedBy=multi-user.target ##3.3 启动命令 systemctl daemon-reload systemctl start shadowsocks-libev systemctl status shadowsocks-libev systemctl enable shadowsocks-libev 有可能报错 ERROR: bind: Permission denied ERROR: failed to bind address 执行 setcap 'cap_net_bind_service=+ep' /usr/local/bin/ss-server systemctl start shadowsocks-libev ##3.4 运行用户问题 有时systemctl不允许nobody用户运行,或运行后log显示不安全。可忽略或自行新建运行用户。 测试是否允许用户的问题,先以root用户试运行。 /usr/local/bin/ss-server -c /etc/shadowsocks-libev/config.json 正常运行后再以nobody用户运行,并给予权限。 chown -R nobody:nogroup /etc/shadowsocks-libev/config.json 如果nobody搞不定,就以root用户运行,或新建用户吧。 #四、配置IP白名单 - 不保证不被封。 - 特别适用于固定IP或家宽进行测试。 - 不太适合手机移动端。 - 4.1和4.2选择自己熟悉的操作即可。 ##4.1 UFW防火墙 ###4.1.1 ufw防火墙开启并开放必要端口 ufw enable Command may disrupt existing ssh connections. Proceed with operation (y|n)?,请输入y并按回车键。 ###4.1.2 ufw允许ssh端口 ufw allow sshport ###4.1.3 增加IP白名单 限制最后三段 ufw allow from 192.0.0.0/8 to any port xxx 限制最后两段 ufw allow from 192.168.0.0/16 to any port xxx 限制最后一段 ufw allow from 192.168.1.0/24 to any port xxx **说明** 限制段数看自己的情况了。 本例以192开头的IP为例作说明。 本例中xxx代表vps的端口,且ufw为放行状态。 Ps:删除指定端口命令如下: ufw delete allow from 192.168.0.0/16 to any port xxx ###4.1.4 ufw重载 ufw reload ##4.2 配置iptables 毕世平推荐,用iptables实现。 比如对来自于192.168.0.0/16地址的 80/tcp 端口数据进行放行: iptables -t filter -I INPUT -p tcp -m state --state NEW -s 192.168.0.0/16 -m tcp --dport 80 -j ACCEPT ##4.3 参考IP列表 `https://github.com/metowolf/iplist` ##4.4 存在的问题 还未进行充分测试。 #五:参考 [Github-Shadowsocks-libev](https://github.com/shadowsocks/shadowsocks-libev "Github-Shadowsocks-libev") [Shadowsocks-libev 白名单IP 搭建【Beta】](https://www.v2ray-agent.com/Shadowsocks-libev-%E7%99%BD%E5%90%8D%E5%8D%95%E6%90%AD%E5%BB%BA/ "Shadowsocks-libev 白名单IP 搭建【Beta】") 标签: shadowsocks, shadowsocks-libev
下载作者发布的Release包,如:shadowsocks-libev-3.3.5.tar.gz 可以省去 git submodule update --init --recursive 和 autoconf.sh
好的,谢谢告知。待我抽空测试完毕,再修改水文。
一:有点没看明白,第一步都已经用apt安装好libsodium-dev和libmbedtls-dev,后面为啥还要单独编译安装这两个;
二:2.2.4里面好像少了个`-`符号:`git submodule update --init --recursive`
1.不懂,照抄的GitHub。我去修改一下。
2.确实是抄错了,少了一个符号。多谢提醒。