shadowsocks 安装(Ubuntu , CentsOS 和 其他Linux 编译安装)

0x00 版本选择

ss的 Linux 服务器版本有很多,例如go,python等,其中shadowsocks-libev是c写的。
其他版本安装比较简单,而且教程很多。这里主要是讲 libev 的编译安装。
 

0x01 项目网址和说明

具体说明请看github,网址:
 
 

0x02 CentOS

编译环境准备&安装依赖包

yum update -y
yum install vim git -y
官方提供的依赖库下载
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y

获取源码

git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init --recursive
开始编译shadowsocks-libev
./autogen.sh && ./configure --prefix=/usr && make
make install
 准备必须的文件
mkdir -p /etc/shadowsocks-libev

cp ./rpm/SOURCES/etc/init.d/shadowsocks-libev /etc/init.d/shadowsocks-libev

cp ./debian/config.json /etc/shadowsocks-libev/config.json

chmod +x /etc/init.d/shadowsocks-libev
 
修改配置文件:同时启用ipv4和ipv6
vim /etc/shadowsocks-libev/config.json
在里面填下这些内容,server_port可以改为自己的端口,密码,加密方式也一样,密码最好改一下
{
    "server":["[::0]","0.0.0.0"],
    "server_port":8990,
    "local_port":1081,
    "password":"password",
    "timeout":60,
    "method":"aes-256-cfb"
}
开启服务
service shadowsocks-libev restart

此时,如果我们还不能通过外网访问服务器,因为防火墙并没有开启相应的端口,编辑防火墙开放的端口服务:

vim /etc/firewalld/zones/public.xml
添加如下行:
<port protocol="tcp" port="服务器端口"/>
<port protocol="udp" port="服务器端口"/>
保存后:
firewall-cmd --complete-reload
服务更新(ss经常更新)
git pull
./configure
make
make install

备注:CentOS防火墙的其他命令

启动:# systemctl start firewalld
查看状态:# systemctl status firewalld 或者 firewall-cmd --state
停止(开机会重新启动):# systemctl stop firewalld
禁用(禁止firewall开机启动):# systemctl disable firewalld
 
CentOS 7 开机启动
新建启动脚本文件
vim /etc/systemd/system/shadowsocks.service
加入下面的内容
[Unit]
Description=Shadowsocks
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/ss-server -c /etc/shadowsocks-libev/config.json
[Install]
WantedBy=multi-user.target
 
CentOS 6 开机启动
mkdir -p /etc/shadowsocks-libev
cp ./rpm/SOURCES/etc/init.d/shadowsocks-libev /etc/init.d/shadowsocks-libev
cp ./debian/config.json /etc/shadowsocks-libev/config.json
chmod +x /etc/init.d/shadowsocks-libev

 

 

安装libsodium,如果需要的话(

export LIBSODIUM_VER=1.0.16
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
make install
popd
ldconfig
 
 
 

0x03 Debian (Ubuntu)

 
apt-get 直接安装版(github写的,没试验过)
sudo apt update
sudo apt install shadowsocks-libev
Ubuntu 14.04 and 16.04,请加入PPA
sudo add-apt-repository ppa:max-c-lv/shadowsocks-libev
sudo apt-get update
sudo apt install shadowsocks-libev
 
编译安装版本
## Debian / Ubuntu
sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libudns-dev automake libmbedtls-dev libsodium-dev

sudo apt-get install libpcre3 libpcre3-dev  zlib1g  openssl libssl-dev

cd /tmp
# 下载源码
git clone https://github.com/shadowsocks/shadowsocks-libev.git
# 开始编译
cd shadowsocks-libev
./autogen.sh
./configure --prefix=/usr && make
make install
# 准备必须的文件
mkdir -p /etc/shadowsocks-libev
cp ./debian/shadowsocks-libev.init /etc/init.d/shadowsocks-libev
cp ./debian/shadowsocks-libev.default /etc/default/shadowsocks-libev
cp ./debian/shadowsocks-libev.service /lib/systemd/system/
cp ./debian/config.json /etc/shadowsocks-libev/config.json
chmod +x /etc/init.d/shadowsocks-libev
# 编辑配置文件
vim /etc/shadowsocks-libev/config.json
# 启动服务
service shadowsocks-libev start
#开机启动
echo 'service shadowsocks-libev start' >>/etc/rc.local

0x04 Linux 通用版本

# Installation of basic build dependencies## Debian / Ubuntu
sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libudns-dev automake libmbedtls-dev libsodium-dev
## CentOS / Fedora / RHEL
sudo yum install gettext gcc autoconf libtool automake make asciidoc xmlto udns-devel libev-devel
## Arch
sudo pacman -S gettext gcc autoconf libtool automake make asciidoc xmlto udns libev

# Installation of Libsodiumexport LIBSODIUM_VER=1.0.12
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
sudo ldconfig

# Installation of MbedTLSexport MBEDTLS_VER=2.4.2
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
sudo ldconfig

# Start building
./autogen.sh && ./configure && make
sudo make install

##开机启动请参考上面
 
参考:
https://dreamcreator108.com/dreams/centos-build-ss-libev/
 

6 thoughts on “shadowsocks 安装(Ubuntu , CentsOS 和 其他Linux 编译安装)

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据