CentOS 7 编译安装 shadowsocks-libev
本文参考教程: https://www.lazycoffee.com/articles/view?id=5a83210e1b611c0e53fcbd07 (重要,请阅读)
我修改之后的脚本如下,原文中的 LIBSODIUM_VER
版本 1.0.13
文件 404 了,所以换了 1.0.17 版本。去这个网页查看当前存在哪些文件: https://download.libsodium.org/libsodium/releases/
创建 /home/你的用户名/temp/install-shadowsocks-libev.sh
,并赋予可执行权限 $ sudo chmod +x /home/你的用户名/temp/install-shadowsocks-libev.sh
#!/bin/bash
# install dependencies
yum update -y
yum install -y pcre pcre-devel git gettext gcc autoconf libtool automake make asciidoc xmlto c-ares-devel libev-devel
export LIBSODIUM_VER=1.0.17
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
#./configure && make && make check
make install
popd
ldconfig
export MBEDTLS_VER=2.6.0
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
make DESTDIR=/usr install
popd
ldconfig
# clean directory
rm -rf /tmp/shadowsocks-libev
# compile and install
cd /tmp
git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init --recursive
./autogen.sh
./configure
make
make install
cd ..
rm -rf /tmp/shadowsocks-libev
临时提权至 root 执行脚本
$ sudo su
# bash /home/你的用户名/temp/install-shadowsocks-libev.sh
耐心等待一段时间。如网络没啥大问题则不会出错。
创建配置文件 /etc/shadowsocks-libev/config.json
,假设内容如下
{
"server":["0.0.0.0"],
"mode":"tcp_and_udp",
"server_port":8899,
"local_port":1080,
"password":"xxxyyy",
"timeout":86400,
"method":"chacha20-ietf-poly1305"
}
创建 /etc/default/shadowsocks-libev
,作为 ss-server 运行时的 变量/配置 定义文件
# Defaults for shadowsocks initscript
# sourced by /etc/init.d/shadowsocks-libev
# installed at /etc/default/shadowsocks-libev by the maintainer scripts
#
# This is a POSIX shell fragment
#
# Note: `START', `GROUP' and `MAXFD' options are not recognized by systemd.
# Please change those settings in the corresponding systemd unit file.
# Enable during startup?
START=yes
# Configuration file
CONFFILE="/etc/shadowsocks-libev/config.json"
# Extra command line arguments
DAEMON_ARGS="-u"
# User and group to run the server as
USER=nobody
GROUP=nobody
# Number of maximum file descriptors
MAXFD=32768
要基于 systemd
管理服务,创建文件 /lib/systemd/system/shadowsocks-libev.service
# This file is part of shadowsocks-libev.
#
# Shadowsocks-libev is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This file is default for Debian packaging. See also
# /etc/default/shadowsocks-libev for environment variables.
[Unit]
Description=Shadowsocks-libev Default Server Service
Documentation=man:shadowsocks-libev(8)
After=network.target
[Service]
Type=simple
EnvironmentFile=/etc/default/shadowsocks-libev
User=nobody
Group=nobody
LimitNOFILE=32768
ExecStart=/usr/local/bin/ss-server -c $CONFFILE $DAEMON_ARGS
[Install]
WantedBy=multi-user.target
防火墙放行 8899 tcp/udp
$ sudo firewall-cmd --zone=public --add-port=8899/tcp --permanent && sudo firewall-cmd --zone=public --add-port=8899/udp --permanent && sudo firewall-cmd --reload
使用 systemd
设置开机自启和启动服务
$ sudo systemctl enable shadowsocks-libev
$ sudo systemctl start shadowsocks-libev
使用 $ sudo systemctl status shadowsocks-libev
查看运行状态。