如果你的手上有多个墙外vps可以搭建一个Shadowsocks分享平台。前端面板(moeSS,建议使用ssl加密)和后端(shadowsocks-manyuser),教程如下:
1. Shadowsocks多用户前端moeSS安装
环境:CentOS-6.6-x86_64-minimal.iso
PHP环境配置
安装lnmp环境(必须安装Nginx、MySQL、PHP5.4+),参考《OneinStack》或者《lnmp一键安装包》
加虚拟主机ss.linuxeye.com,需要用到pathinfo,下面是我的配置文件(/usr/local/nginx/conf/vhost/ss.linuxeye.com.conf):
- server {
- listen 443 ssl spdy;
- ssl_certificate 1_ss.linuxeye.com_bundle.crt;
- ssl_certificate_key ss.linuxeye.com.key;
- ssl_ciphers “CHACHA20:GCM:HIGH:!DH:!RC4:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!SRP:!DSS”;
- ssl_session_cache shared:SSL:10m;
- ssl_session_timeout 10m;
- ssl_stapling on;
- ssl_stapling_verify on;
- resolver 8.8.8.8 8.8.4.4 valid=300s;
- resolver_timeout 5s;
- server_name ss.linuxeye.com;
- access_log off;
- index index.html index.htm index.jsp index.php;
- root /home/wwwroot/ss.linuxeye.com;
- if (!-e $request_filename) {
- rewrite ^/(.*)$ /index.php/$1 last;
- break;
- }
- location ~ [^/]\.php(/|$) {
- fastcgi_split_path_info ^(.+\.php)(/.+)$;
- try_files $fastcgi_script_name =404;
- set $path_info $fastcgi_path_info;
- fastcgi_param PATH_INFO $path_info;
- fastcgi_pass unix:/dev/shm/php-cgi.sock;
- fastcgi_index index.php;
- include fastcgi.conf;
- }
- location ~ /\.ht {
- deny all;
- }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
- expires 30d;
- }
- location ~ .*\.(js|css)?$ {
- expires 7d;
- }
- }
- server {
- listen 80;
- server_name ss.linuxeye.com;
- rewrite ^(.*)$ https://$host$1 permanent;
- }
下载代码
- cd ~/oneinstack/src
- git clone https://github.com/monoking/moeSS.git #下载moeSS
- mv moeSS/* /home/wwwroot/ss.linuxeye.com/ #将代码上传到知道虚拟主机(ss.linuxeye.com)网站根目录
- find /home/wwwroot/ss.linuxeye.com –type f –exec chmod 644 {} \; #为了安全,将代码里面文件权限设置为644
- find /home/wwwroot/ss.linuxeye.com –type d –exec chmod 755 {} \; #为了安全,将代码里面目录权限设置为755
- chown -R www.www /home/wwwroot/ss.linuxeye.com/ #修改代码用户和所在组设置为www
导入sql
- cd /home/wwwroot/ss.linuxeye.com/
- mysql -uroot -p
- mysql> create database shadowsocks;
- mysql> use shadowsocks;
- mysql> source shadowsocks.sql;
- //注:#创建moeSS面板和多用户后端shadowsocks-manyuser(shadowsocks-manyuser只需要连接user表,后面授权注意)连接数据库 mysql> grant all privileges on shadowsocks.user to ‘oneinstack_ss’@’%’ identified by ‘oneinstack_pwd’;
- mysql> flush privileges;
开启mysql远程连接端口
- iptables -I INPUT 5 -p tcp -m state –state NEW -m tcp –dport 3306 -j ACCEPT #建议只对指定服务器开放3306端口
- service iptables save
修改moeSS配置文件
- # cd /home/wwwroot/ss.linuxeye.com/application/config
- # cp config-sample.php config.php #直接复制模板,更改
修改如下几个参数:
- SITE_NAME:显示在系统各处的网站名称;
- base_url:网站地址。如果你的系统放在二级目录的话,请写全二级目录的地址,并且不要忘了后置的斜杠和前置的 http:// 或 https://;
- encryption_key:用来加密Cookie信息的,请随意写一串字符串作为加密密钥。务必修改该值,否则Cookie可以被轻易伪造!
- # cp database-simple.php database.php #数据库连接文件
保证hostname, username, password, database 四项设置完全正确,否则可能会导致程序无法连接数据库。
登录管理后台
访问:https://ss.linuxeye.com/admin, 可以登录系统进行配置了。
默认情况下系统自带了用户名和密码为 admin/admin12345 的管理员账户和用户账户。你可以先尝试使用这个账户分别登陆用户面板和管理面板来确认网站是否安装成功。安装完成之后请务必修改默认密码,在管理面板的左下方,你可以找到系统设置->一般设置。其中包含了很多系统的基础设置。你可以选择使用默认值,也可以按照需要修改。
2. Shadowsocks多用户后端shadowsocks-manyuser
先安装需要的环境依赖
如果操作系统是Debian/Ubuntu:
- apt-get -y install python-pip python-m2crypto
CentOS:
- yum -y install m2crypto python-setuptools
- easy_install pip
安装cymysql
- pip install cymysql
安装shadowsocks-manyuser
- cd ~/oneinstack/src
- git clone -b manyuser https://github.com/mengskysama/shadowsocks.git
修改配置
vi ~/shadowsocks/shadowsocks/Config.py #前端数据库连接信息
- #Config
- MYSQL_HOST = ‘ss.linuxeye.com’
- MYSQL_PORT = 3306
- MYSQL_USER = ‘oneinstack_ss’
- MYSQL_PASS = ‘oneinstack_pwd’
- MYSQL_DB = ‘shadowsocks’
关闭iptables
- service iptables stop #shadowsocks多用户需要启用多个端口,添加iptables麻烦,关闭
- chkconfig iptables off
运行shadowsocks-manyuser
- nohup python server.py &