风岭社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3686|回复: 1

CentOS:Shadowsocks Manyuser、SS-panel完整详细配置多节点

[复制链接]
发表于 2016-10-26 22:13:21 | 显示全部楼层 |阅读模式
一、安装依赖组件
  1. yum install wget git tar gcc gcc-c++ openssl openssl-devel pcre-devel python-devel libevent automake autoconf libtool make -y
复制代码

升级Python(新手请跳过以免操作不当无法使用)
  1. wget [url]http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz[/url]
  2. tar zxvf Python-2.7.6.tgz
  3. cd /root/Python-2.7.6/Modules/zlib
  4. ./configure
  5. make && make install
  6. cd /root/Python-2.7.6
  7. ./configure
  8. make && make install
  9. cd Modules                                  # 处理 报:ImportError: No module named zlib
  10. vi Setup                                        #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz  删除“#”
  11. cd /root/Python-2.7.6           
  12. make && make install                    #再返回MAKE
  13. python -V                                                                       //查看当前python的版本
  14. mv /usr/bin/python /usr/bin/python2.6.6             //这里填刚才显示的版本号
  15. ln -s /usr/local/bin/python2.7 /usr/bin/python     //创建2.7版本的软连接
  16. yum与python的兼容问题还要处理下:
  17. vi /usr/bin/yum
  18. #!/usr/bin/python2.6.6                                //第一行修改为原始的变更后的版本文件名
  19. python                                                              //运行下查看版本信息,Ctrl+Z 停止退出。
复制代码
显示python版本2.7.6就说明成功了,请直接跳过以下这些内容直至第二大部分的安装!

这部分内容是全新部署不用操作不用看的!
以下这部分是:已有以下软件才升级Python版本出现很多问题的解决方法:
  1. 如运行出错:ImportError: No module named binascii ,是由于升级版本不对导致的。
  2. 处理:ImportError: No module named binascii
  3. 升级安装zlib
  4. wget [url]http://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz[/url]
  5. tar -zxvf zlib-1.2.8.tar.gz
  6. cd zlib-1.2.8
  7. ./configure
  8. make install

  9. 升级安装sqlite3
  10. cd /root
  11. wget [url]http://www.sqlite.org/2014/sqlite-autoconf-3080500.tar.gz[/url]
  12. tar -zxvf sqlite-autoconf-3080500.tar.gz
  13. cd sqlite-autoconf-3080500
  14. ./configure
  15. make && make install

  16. cd /root/Python-2.7.6
  17. make && make install
  18. 安装setuptools
  19. cd /root
  20. wget [url]https://pypi.python.org/packages[/url] ... ls-0.6c11-py2.7.egg --no-check-certificate
  21. sh setuptools-0.6c11-py2.7.egg
  22. 如果提示 zipimport.ZipImportError: can’t decompress data; zlib not available ,说明需要安装zlib库:
  23. cd /root/Python-2.7.6/Modules/zlib
  24. ./configure
  25. make & make install
  26. 重新编译一下python
  27. cd /root/Python-2.7.6
  28. make & make install

  29. 安装setuptools
  30. cd /root
  31. sh setuptools-0.6c11-py2.7.egg
复制代码


错误提示:in resolve pkg_resources.DistributionNotFound: pip==7.1.0 说明需要安装pip7.1.0版本

二、安装setuptools、pip、cymysql、swig、M2Crypto、gevent
  1. cd /root
  2. wget --no-check-certificate [url]https://bootstrap.pypa.io/ez_setup.py[/url]
  3. python ez_setup.py --insecure

  4. 卸载原来的pip
  5. python -m pip uninstall pip
  6. yum -y remove python-pip python-pip

  7. wget --no-check-certificate [url]https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz[/url]
  8. tar zxvf pip-7.1.2.tar.gz
  9. cd pip-7.1.2
  10. python setup.py install
  11. pip install cymysql
  12. cd /root
  13. wget [url]http://jaist.dl.sourceforge.net/project/swig/swig/swig-3.0.0/swig-3.0.0.tar.gz[/url]
  14. tar zxvf swig-3.0.0.tar.gz
  15. cd swig-3.0.0
  16. ./configure
  17. make && make install
  18. cd /root
  19. wget [url]https://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-0.22.3.tar.gz[/url] --no-check-certificate
  20. tar zxvf M2Crypto-0.22.3.tar.gz
  21. cd M2Crypto-0.22.3
  22. python setup.py build
  23. python setup.py install
  24. cd /root
  25. yum install -y libevent
  26. pip install greenlet
  27. pip install gevent
复制代码

三、安装及配置Shadowsocks
  1. cd /root
  2. git clone -b manyuser [url]https://github.com/mengskysama/shadowsocks.git[/url]
  3. vi /root/shadowsocks/shadowsocks/Config.py
  4. vi /root/shadowsocks/shadowsocks/config.json
复制代码
编辑 config.json 只更改加密算法为:aes-256-cfb
编辑 Config.py  文件的数据库配置信息。
重点是节点的配置文件中需要注意的是:
  1. #Config
  2. MYSQL_HOST = ''                     #MySQL服务器域名
  3. MYSQL_PORT = 3306             #MySQL服务器端口
  4. MYSQL_USER = ''                     #MySQL用户名
  5. MYSQL_PASS = ''                      #MySQL用户密码
  6. MYSQL_DB = ''                          #MySQL数据库名
  7. MANAGE_PASS = ''             #这个随便填没关系的
  8. MANAGE_BIND_IP = '127.0.0.1' #当前节点IP地址
  9. MANAGE_PORT = 3306
复制代码
这里再说一下,没安装vim的可以用yum install vim 进行安装。
vim 编辑器下按 i 进入编辑模式就可以编辑了,编辑好了之后,
按Esc输入:(冒号)再输入wq(保存退出)即可完成文本编辑。
以下SS-panel配置部分节点服务器不用做连接到主数据库即可。

四、创建数据库并开启远程连接(1)创建数据库并开启远程连接
  1. mysql -u root -p
复制代码
提示输入MySQL密码,进入后创建数据库:
  1. create database shadowsocks;
  2. grant all privileges on shadowsocks.* to 'root'@'%' identified by 'password' ;
  3. flush privileges;
复制代码
这里的grant all reivileges 是赋予账户所有的权限,可以只赋予select和update权限即可。
shadowsocks.*是shadowsocks数据库下的所有表,root是用户名%指任意主机连接地址。
password就是设置的账户密码,flush privileges;是重新加载权限。这样就能远程连接了。
下面是另一种方法可以更改权限,我们再来查看下确定是否已经拥有远程连接的权限了:
  1. use mysql;
  2. select host,user from user;
复制代码
查看结果是不是root或你指定的那个用户登录的host字段是否显示为%,如不是就执行:
update user set host = '%' where user = 'root'; 执行完后再select host,user from user;
查看下root对应的host是否更改成了%,更改成功就表示该用户可以任意IP地址登录了。
flush privileges;    记得要执行一下这个命令才能让刚才更改的权限信息重新载入生效。
exit;  或输入 quit  退出MySQL控制台。当然也可以在phpmyadmin里面进行权限更改。
我们还需要确定防火墙是否开放了数据库所需要的3306端口来保障我们的通信正常的。
(2)打开远程连接数据库的端口
添加规则,打开3306端口:
  1. iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
复制代码
查看规则是否生效:
  1. iptables -L -n     
  2. 或者   
  3. service iptables status
  4. service iptables save
  5. 或者   
  6. /etc/init.d/iptables save
复制代码
这样重启也可以生效了。

五、前端SS-Panel的配置
上传SS-panel的文件到网站目录中,lnmp是在:/home/wwwroot/default/ 目录下。
进入phpmyadmin,将SS-panelsql下所有sql文件全都导入shadowsocks数据库中。
编辑SS-panel的数据库配置文件lib/config.php (config-sample.php改为config.php)
其中user表中id=1的用户是管理员,端口号也是起始端口号之后的端口由此而递增。
默认帐号:first@blood.com        默认密码:1993    密码为MD5值,可以自行更改。
命令行操作为:
  1. cd /home/wwwroot/default
  2. git clone [url]https://github.com/orvice/ss-panel.git[/url]
  3. mv -f ss-panel/* .
  4. cat /home/wwwroot/default/sql/*.sql > shadowsocks.sql
  5. mysql -u root -p
  6. use shadowsocks;
  7. source /home/wwwroot/default/shadowsocks.sql;
  8. exit
复制代码

六、运行测试并设置开机自动后台运行(1)运行测试
  1. cd /root/shadowsocks/shadowsocks
  2. python  server.py
复制代码
看输出信息来确定是否正常运行连接到数据库和监听端口。
按ctrl+c 可以中断,根据反馈的信息去找问题所在去解决。
(2)后台运行
下面我们来介绍几种用法,选其一即可:
<1>nohup
  1. cd /root/shadowsocks/shadowsocks
  2. nohup python  server.py &
复制代码
& 是后台运行意思。nohup 命令> log.file 2>&1 & 可将日志文件重定向到log.file中。
运行后如果不重定向则会在目录下生成nohup.out日志文件可用cat nohup.out查看。
用这个命令需要注意的是要使用exit退出才能关闭终端会话否则程序也会一起关闭。
如果需要查看可以使用jobs -l命令,关闭可以使用kill PID号即可关闭所指定的任务。
<2>screen
  1. screen -dmS Shadowsocks python server.py
复制代码
screen -dmS 用来创建一个处于断开模式的会话,Shadowsocks为session name。
screen -r Shadowsocks  可以恢复指定的会话,忘记了可以用screen -list来查看。
(3)配置开机自动启动并在后台运行
  1. vi /etc/rc.local
复制代码
编辑添加以下内容:
  1. cd /root/shadowsocks/shadowsocks
  2. python server.py &
复制代码
screen实现的方法就添加以下内容:
  1. cd /root/shadowsocks/shadowsocks
  2. screen -dmS Shadowsocks python server.py
复制代码
(4)supervisor值守进程方法:
  1. cd /root
  2. pip install --upgrade pip
  3. pip install supervisor
  4. echo_supervisord_conf > /etc/supervisord.conf
  5. vi /etc/supervisord.conf
  6. [include]                                 //在底部编辑去注释
  7. files = /etc/supervisord.conf.d/*.conf       //存退
  8. mkdir /etc/supervisord.conf.d
  9. cd /etc/supervisord.conf.d
  10. vi shadowsocks.conf
  11. [program:shadowsocks]
  12. command=python /root/shadowsocks/shadowsocks/server.py -c /root/shadowsocks/shadowsocks/config.json
  13. autostart=true
  14. autorestart=true
  15. stderr_logfile = /root/shadowsocks.err.log
  16. stdout_logfile = /root/shadowsocks.out.log
复制代码
运行supervisor
  1. supervisord -c /etc/supervisord.conf
复制代码
supervisor运行后就交由supervisorctl来管理了
使修改的配置立即生效:supervisorctl update
设置开机启动supervisor
  1. vi /etc/rc.local  
复制代码
         //添加以下内容
  1. supervisord -c /etc/supervisord.conf
复制代码
supervisor控制台命令
  1. supervisorctl                                               打开命令行
  2. supervisorctl status                                   获得所有程序状态
  3. supervisorctl start all                                运行所有进程
  4. supervisorctl stop all                                 停止所有进程
  5. supervisorctl restart all                            重启所有进程
  6. supervisorctl shutdown                            关闭所有程序
  7. supervisorctl start shadowsocks             运行目标进程
  8. supervisorctl stop shadowsocks              停止所有进程
  9. supervisorctl restart shadowsocks          重启目标程序
  10. supervisorctl tail -f shadowsocks stderr 查看此进程的日志文件
复制代码
Web管理supervisor
supervisor自带Web Server 可以通过页面来管理进程,
前提是需要开启配置文件中的 [inet_http_server] 项。
  1. vi /etc/supervisord.conf
  2. [inet_http_server]
  3. port = 127.0.0.1:9001
  4. ;username = admin
  5. ;password = yourpassword
复制代码
即可在浏览器中输入地址和端口号进行网页化的管理。

回复

使用道具 举报

 楼主| 发表于 2016-11-13 21:20:41 | 显示全部楼层
执行#Python与#python -V,看到版本号是2.4.3,很老了,而且之前写的都是跑在python3.X上面的,3.X和2.X有很多不同,
有兴趣的朋友可以参考下这篇文章:
http://www.jb51.net/article/34011.htm

更新python千万不要把老版本的删除!新老版本是可以共存的,很多基本的命令、
软件包都要依赖预装的老版本python的,比如yum。

一、升级到2.7.3
1. 升级安装
首先下载源tar包
可利用linux自带下载工具wget下载,如下所示:
# wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.gz

下载完成后到下载目录下,解压
# tar -zxvf Python-2.7.3.tar.gz

进入解压缩后的文件夹
cd Python-2.7.3

在编译前先在/usr/local建一个文件夹python2.7.3(作为python的安装路径,以免覆盖老的版本)
# mkdir /usr/local/python2.7.3

在解压缩后的目录下编译安装
# ./configure --prefix=/usr/local/python2.7.3
# make
# make install

此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
# mv /usr/bin/python /usr/bin/python_old

再建立新版本python的链接
# ln -s /usr/local/python2.7.3/bin/python2.7 /usr/bin/python

这个时候输入
# python

就会显示出python的新版本信息
view sourceprint?
Python 2.7.3 (default, Sep 29 2013, 11:05:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

2.运行程序时出现错误:
File "~/PythonInstall/lib/python2.7/multiprocessing/process.py", line 129, in start
    from .forking import Popen
  File "~/PythonInstall/lib/python2.7/multiprocessing/forking.py", line 58, in
    from pickle import Pickler
  File "~/PythonInstall/lib/python2.7/pickle.py", line 1266, in
    import binascii as _binascii
ImportError: No module named binascii
是因为升级python版本不正常导致的。

回到源文件目录:
# cd .../Python-2.7.3
[Python-2.7.3]# make -s
building dbm using gdbm
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c: In function '_pysqlite_set_result':
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: 'sqlite3_int64' undeclared

(first use in this function)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: (Each undeclared identifier is

reported only once
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: for each function it appears in.)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: expected ')' before

'PyInt_AsLong'
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c: In function '_pysqlite_build_py_params':
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:583: error: 'sqlite3_int64' undeclared
(first use in this function)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:583: error: expected ';' before 'val_int'
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:596: error: 'val_int' undeclared (first use  in this function)
/usr/bin/ld: /usr/local/lib/libz.a(adler32.o): relocation R_X86_64_32 against `a local symbol' can not be used when

making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
/usr/bin/ld: /usr/local/lib/libz.a(crc32.o): relocation R_X86_64_32 against `a local symbol' can not be used when

making a shared object; recompile with -fPIC
/usr/local/lib/libz.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

Python build finished, but the necessary bits to build these modules were not found:
_tkinter           bsddb185           dl              
imageop            sunaudiodev                        
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

Failed to build these modules:
_sqlite3           binascii           zlib

升级安装zlib
# wget http://sourceforge.net/projects/ ... 8/zlib-1.2.8.tar.gz
# tar -zxvf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure
# make install

# cd ../Python-2.7.3
# make -s
building dbm using gdbm
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c: In function '_pysqlite_set_result':
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: 'sqlite3_int64' undeclared

(first use in this function)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: (Each undeclared identifier is reported only once
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: for each function it appears in.)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:552: error: expected ')' before

'PyInt_AsLong'
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c: In function '_pysqlite_build_py_params':
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:583: error: 'sqlite3_int64' undeclared

(first use in this function)
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:583: error: expected ';' before 'val_int'
/opt/PJT_python/python-2.7.3/Python-2.7.3/Modules/_sqlite/connection.c:596: error: 'val_int' undeclared (first use in this function)

Python build finished, but the necessary bits to build these modules were not found:
_tkinter           bsddb185           dl              
imageop            sunaudiodev                        
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

Failed to build these modules:
_sqlite3

升级安装sqlite3
# cd ..
# wget http://www.sqlite.org/2014/sqlite-autoconf-3080500.tar.gz
# tar -zxvf sqlite-autoconf-3080500.tar.gz
# cd sqlite-autoconf-3080500
# ./configure
# make
# make install

# cd ..
# cd python-2.7.3
# make -s
building dbm using gdbm

Python build finished, but the necessary bits to build these modules were not found:
_tkinter           bsddb185           dl              
imageop            sunaudiodev                        
To find the necessary bits, look in setup.py in detect_modules() for the module's name.

# make clean
# make all
# make install
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|Comsenz Inc.

GMT+8, 2024-3-28 17:45 , Processed in 0.035195 second(s), 6 queries , File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表