Docker搭建Shadowsocks代理服务
by
Vicent
- 十一月 21, 2018
Docker搭建Shadowsocks
环境
- CentOS7 x64
- Xshell
还没有服务器的看文章最后购买
一、安装Docker
xxxxxxxxxx
[xdl@vultr ~]$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
[xdl@vultr ~]$ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
[xdl@vultr ~]$ sudo yum install docker-ce
二、Docker管理
xxxxxxxxxx
[xdl@vultr ~]$ sudo usermod -aG docker xdl # 当前用户加入Docker组
[xdl@vultr ~]$ sudo systemctl start docker # 启动Docker服务
[xdl@vultr ~]$ sudo systemctl enable docker # 开机自启
退出重新登录服务器
三、下载Shadowsocks镜像
xxxxxxxxxx
[xdl@vultr ~]$ docker pull shadowsocks/shadowsocks-libev
Using default tag: latest
latest: Pulling from shadowsocks/shadowsocks-libev
4fe2ade4980c: Pull complete
cb21e2328681: Pull complete
c2fb2a6d5d48: Pull complete
Digest: sha256:b4884b7c63f640ba899f1c8898d098938b6e3d6e1b1cab81b93051c440abfa12
Status: Downloaded newer image for shadowsocks/shadowsocks-libev:latest
四、启动Shadowsocks服务
xxxxxxxxxx
[xdl@vultr ~]$ docker run --name ss-libev -e PASSWORD=<password> -p<server-port>:8388 -p<server-port>:8388/udp -d --restart always shadowsocks/shadowsocks-libev
上述命令启动了一个叫ss-libev
的容器,使用自定义的密码,自定义端口,随Docker服务自启。如果要启动多个只需要修改--name
后面的参数,使用一个不同的名字即可。到这里搭建就完成了。如果觉得麻烦,需要增加更多的自定义项,可以使用docker-compose管理。
五、使用docker-compose管理[可选]
5.1安装docker-compose
xxxxxxxxxx
[xdl@vultr ~]$ sudo curl -L https://github.com/docker/compose/releases/download/1.23.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
[xdl@vultr ~]$ sudo chmod +x /usr/local/bin/docker-compose
5.2下载配置文件
xxxxxxxxxx
[xdl@vultr ~]$ mkdir ~/shadowsocks
[xdl@vultr ~]$ cd shadowsocks/
[xdl@vultr shadowsocks]$ curl -sSLO https://github.com/shadowsocks/shadowsocks-libev/raw/master/docker/alpine/docker-compose.yml
5.3修改配置文件
xxxxxxxxxx
[xdl@vultr shadowsocks]$ vim docker-compose.yml
shadowsocks:
image: shadowsocks/shadowsocks-libev
ports:
- "8388:8388/tcp"
- "8388:8388/udp"
environment:
- SERVER_ADDR=0.0.0.0
- SERVER_ADDR_IPV6=::0
- METHOD=aes-256-gcm
- DNS_ADDRS=1.1.1.1,1.0.0.1
- PASSWORD=9MLSpPmNt
restart: always
5.4启动Docker服务
xxxxxxxxxx
[xdl@vultr shadowsocks]$ docker-compose up -d
Creating shadowsocks_shadowsocks_1_d727ae1c9995 ... done
5.5查看日志
xxxxxxxxxx
[xdl@vultr shadowsocks]$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED
85193c8f47d2 shadowsocks/shadowsocks-libev "/bin/sh -c 'exec ss…" 18 seconds ago8406ea22
[xdl@vultr shadowsocks]$ docker container logs 85193c8f47d2
2018-11-21 07:21:08 INFO: using tcp fast open
2018-11-21 07:21:08 INFO: UDP relay enabled
2018-11-21 07:21:08 INFO: initializing ciphers... aes-256-gcm
2018-11-21 07:21:08 INFO: using nameserver: 1.1.1.1,1.0.0.1
2018-11-21 07:21:08 INFO: tcp server listening at 0.0.0.0:8388
2018-11-21 07:21:08 INFO: tcp server listening at [::0]:8388
2018-11-21 07:21:08 INFO: udp server listening at 0.0.0.0:8388
2018-11-21 07:21:08 INFO: udp server listening at [::0]:8388
搭建完成!
推荐服务器
1、Vultr: 注册得10$
2、DigtalOcean: 注册得50$
更多客户端等的使用方法请参考