admin 发表于 2016-10-26 22:13:21

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

一、安装依赖组件yum install wget git tar gcc gcc-c++ openssl openssl-devel pcre-devel python-devel libevent automake autoconf libtool make -y升级Python(新手请跳过以免操作不当无法使用)wget http://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar zxvf Python-2.7.6.tgz
cd /root/Python-2.7.6/Modules/zlib
./configure
make && make install
cd /root/Python-2.7.6
./configure
make && make install
cd Modules                                  # 处理 报:ImportError: No module named zlib
vi Setup                                        #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz删除“#”
cd /root/Python-2.7.6         
make && make install                  #再返回MAKE
python -V                                                                     //查看当前python的版本
mv /usr/bin/python /usr/bin/python2.6.6             //这里填刚才显示的版本号
ln -s /usr/local/bin/python2.7 /usr/bin/python   //创建2.7版本的软连接
yum与python的兼容问题还要处理下:
vi /usr/bin/yum
#!/usr/bin/python2.6.6                              //第一行修改为原始的变更后的版本文件名
python                                                            //运行下查看版本信息,Ctrl+Z 停止退出。显示python版本2.7.6就说明成功了,请直接跳过以下这些内容直至第二大部分的安装!
这部分内容是全新部署不用操作不用看的!以下这部分是:已有以下软件才升级Python版本出现很多问题的解决方法:如运行出错:ImportError: No module named binascii ,是由于升级版本不对导致的。
处理:ImportError: No module named binascii
升级安装zlib
wget http://sourceforge.net/projects/libpng/files/zlib/1.2.8/zlib-1.2.8.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make install

升级安装sqlite3
cd /root
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 /root/Python-2.7.6
make && make install
安装setuptools
cd /root
wget https://pypi.python.org/packages ... ls-0.6c11-py2.7.egg --no-check-certificate
sh setuptools-0.6c11-py2.7.egg
如果提示 zipimport.ZipImportError: can’t decompress data; zlib not available ,说明需要安装zlib库:
cd /root/Python-2.7.6/Modules/zlib
./configure
make & make install
重新编译一下python
cd /root/Python-2.7.6
make & make install

安装setuptools
cd /root
sh setuptools-0.6c11-py2.7.egg

错误提示:in resolve pkg_resources.DistributionNotFound: pip==7.1.0 说明需要安装pip7.1.0版本二、安装setuptools、pip、cymysql、swig、M2Crypto、geventcd /root
wget --no-check-certificate https://bootstrap.pypa.io/ez_setup.py
python ez_setup.py --insecure

卸载原来的pip
python -m pip uninstall pip
yum -y remove python-pip python-pip

wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz
tar zxvf pip-7.1.2.tar.gz
cd pip-7.1.2
python setup.py install
pip install cymysql
cd /root
wget http://jaist.dl.sourceforge.net/project/swig/swig/swig-3.0.0/swig-3.0.0.tar.gz
tar zxvf swig-3.0.0.tar.gz
cd swig-3.0.0
./configure
make && make install
cd /root
wget https://pypi.python.org/packages/source/M/M2Crypto/M2Crypto-0.22.3.tar.gz --no-check-certificate
tar zxvf M2Crypto-0.22.3.tar.gz
cd M2Crypto-0.22.3
python setup.py build
python setup.py install
cd /root
yum install -y libevent
pip install greenlet
pip install gevent
三、安装及配置Shadowsockscd /root
git clone -b manyuser https://github.com/mengskysama/shadowsocks.git
vi /root/shadowsocks/shadowsocks/Config.py
vi /root/shadowsocks/shadowsocks/config.json编辑 config.json 只更改加密算法为:aes-256-cfb编辑 Config.py文件的数据库配置信息。重点是节点的配置文件中需要注意的是:#Config
MYSQL_HOST = ''                     #MySQL服务器域名
MYSQL_PORT = 3306             #MySQL服务器端口
MYSQL_USER = ''                     #MySQL用户名
MYSQL_PASS = ''                      #MySQL用户密码
MYSQL_DB = ''                        #MySQL数据库名
MANAGE_PASS = ''             #这个随便填没关系的
MANAGE_BIND_IP = '127.0.0.1' #当前节点IP地址
MANAGE_PORT = 3306这里再说一下,没安装vim的可以用yum install vim 进行安装。vim 编辑器下按 i 进入编辑模式就可以编辑了,编辑好了之后,按Esc输入:(冒号)再输入wq(保存退出)即可完成文本编辑。以下SS-panel配置部分节点服务器不用做连接到主数据库即可。
四、创建数据库并开启远程连接(1)创建数据库并开启远程连接mysql -u root -p提示输入MySQL密码,进入后创建数据库:create database shadowsocks;
grant all privileges on shadowsocks.* to 'root'@'%' identified by 'password' ;
flush privileges;这里的grant all reivileges 是赋予账户所有的权限,可以只赋予select和update权限即可。shadowsocks.*是shadowsocks数据库下的所有表,root是用户名%指任意主机连接地址。password就是设置的账户密码,flush privileges;是重新加载权限。这样就能远程连接了。下面是另一种方法可以更改权限,我们再来查看下确定是否已经拥有远程连接的权限了:use mysql;
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端口:iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT查看规则是否生效:iptables -L -n   
或者   
service iptables status
service iptables save
或者   
/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值,可以自行更改。命令行操作为:cd /home/wwwroot/default
git clone https://github.com/orvice/ss-panel.git
mv -f ss-panel/* .
cat /home/wwwroot/default/sql/*.sql > shadowsocks.sql
mysql -u root -p
use shadowsocks;
source /home/wwwroot/default/shadowsocks.sql;
exit
六、运行测试并设置开机自动后台运行(1)运行测试cd /root/shadowsocks/shadowsocks
pythonserver.py看输出信息来确定是否正常运行连接到数据库和监听端口。按ctrl+c 可以中断,根据反馈的信息去找问题所在去解决。(2)后台运行下面我们来介绍几种用法,选其一即可:<1>nohupcd /root/shadowsocks/shadowsocks
nohup pythonserver.py && 是后台运行意思。nohup 命令> log.file 2>&1 & 可将日志文件重定向到log.file中。运行后如果不重定向则会在目录下生成nohup.out日志文件可用cat nohup.out查看。用这个命令需要注意的是要使用exit退出才能关闭终端会话否则程序也会一起关闭。如果需要查看可以使用jobs -l命令,关闭可以使用kill PID号即可关闭所指定的任务。<2>screenscreen -dmS Shadowsocks python server.pyscreen -dmS 用来创建一个处于断开模式的会话,Shadowsocks为session name。screen -r Shadowsocks可以恢复指定的会话,忘记了可以用screen -list来查看。(3)配置开机自动启动并在后台运行vi /etc/rc.local编辑添加以下内容:cd /root/shadowsocks/shadowsocks
python server.py &screen实现的方法就添加以下内容:cd /root/shadowsocks/shadowsocks
screen -dmS Shadowsocks python server.py(4)supervisor值守进程方法:cd /root
pip install --upgrade pip
pip install supervisor
echo_supervisord_conf > /etc/supervisord.conf
vi /etc/supervisord.conf
                                 //在底部编辑去注释
files = /etc/supervisord.conf.d/*.conf       //存退
mkdir /etc/supervisord.conf.d
cd /etc/supervisord.conf.d
vi shadowsocks.conf

command=python /root/shadowsocks/shadowsocks/server.py -c /root/shadowsocks/shadowsocks/config.json
autostart=true
autorestart=true
stderr_logfile = /root/shadowsocks.err.log
stdout_logfile = /root/shadowsocks.out.log运行supervisorsupervisord -c /etc/supervisord.confsupervisor运行后就交由supervisorctl来管理了使修改的配置立即生效:supervisorctl update设置开机启动supervisorvi /etc/rc.local         //添加以下内容supervisord -c /etc/supervisord.confsupervisor控制台命令supervisorctl                                             打开命令行
supervisorctl status                                 获得所有程序状态
supervisorctl start all                              运行所有进程
supervisorctl stop all                                 停止所有进程
supervisorctl restart all                            重启所有进程
supervisorctl shutdown                            关闭所有程序
supervisorctl start shadowsocks             运行目标进程
supervisorctl stop shadowsocks            停止所有进程
supervisorctl restart shadowsocks          重启目标程序
supervisorctl tail -f shadowsocks stderr 查看此进程的日志文件Web管理supervisorsupervisor自带Web Server 可以通过页面来管理进程,前提是需要开启配置文件中的 项。vi /etc/supervisord.conf

port = 127.0.0.1:9001
;username = admin
;password = yourpassword即可在浏览器中输入地址和端口号进行网页化的管理。

admin 发表于 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)
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
# 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 usein 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/libpng/files/zlib/1.2.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
页: [1]
查看完整版本: CentOS:Shadowsocks Manyuser、SS-panel完整详细配置多节点