1 操作系统
Centos 6.5 64bit 或以上版本
2 软件环境
提示:(1)用什么软件;(2)运行环境(3)开发包。
- Python:Python-2.7.6.tgz
- Scrapy:Scrapy-1.0.3.tar.gz
- Selenium:selenium (2.48.0)
- Phantomjs:phantomjs-1.9.8-linux-x86_64.tar.bz2
- MySQL-python:MySQL-python-1.2.5.zip
- MySQL:MySQL-5.6.27-1.linux_glibc2.5.x86_64.rpm-bundle.tar
3 安装步骤
1. 安装依赖库
yum install zlib-devel bzip2-devel ncurses-devel sqlite-devel readline-devel tk-devel mysql-devel gcc libxslt-devel libxml2-devel libffi-devel openssl-devel python-devel
# yum install zlib-devel
# yum install bzip2-devel
# yum install openssl-devel
# yum install ncurses-devel
# yum install sqlite-devel
# yum install readline-devel
# yum install tk-devel
# yum install mysql-devel
# yum install gcc
# yum install make (centos可能已自带,不用安装)
安装Scrapy必装:
# yum install libxslt-devel
# yum install libxml2-devel
# yum install libffi-devel
2. 升级Python
(下载地址:https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz)
Centos6.5系统自带python2.6.6,需要升级到Python2.7
安装库文件:yum install zlib-devel openssl-devel sqlite-devel
下载:wget https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
解压:tar zxvf Python-2.7.6.tgz
安装:
cd Python-2.7.6
./configure --prefix=/usr/local/python
make
make install
创建软链接:ln -sf /usr/local/python/bin/python2.7 /usr/bin/python
修正yum:修改文件/usr/bin/yum的第一行(#!/usr/bin/python改为#!/usr/bin/python2.6)
3. 安装setuptools和pip
使用pip安装python模块时出现报错,建议先更新setuptools和pip来排除。
下载地址:https://pypi.python.org/packages/source/s/setuptools/setuptools-18.4.tar.gz
解压后安装:python setup.py install(或pip install --upgrade setuptools)
下载地址:https://pypi.python.org/packages/source/p/pip/pip-7.1.2.tar.gz
解压后安装:python setup.py install(或pip install --upgrade pip)
4. 安装scrapy+selenium+phantomjs
下载地址:https://pypi.python.org/packages/source/S/Scrapy/Scrapy-1.0.3.tar.gz
解压后安装:python setup.py install
(也可使用pip install scrapy
命令安装)
注意:使用pip install scrapy
安装时可能由于网络异常或下载安装其他依赖库时报错,可以单独下载依赖库进行安装。
selenium+phantomjs按需安装,如果使用了phantomjs类浏览器来解析js则安装:
下载地址:https://pypi.python.org/packages/source/s/selenium/selenium-2.48.0.tar.gz
解压后安装:python setup.py install
(也可使用pip install selenium
命令安装)
下载地址:
https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-i686.tar.bz2
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-1.9.8-linux-i686.tar.bz2
tar jxvf phantomjs-1.9.8-linux-i686.tar.bz2
mv phantomjs-1.9.8-linux-i686 /usr/local/src/phantomjs
ln -sf /usr/local/src/phantomjs/bin/phantomjs /usr/local/bin/phantomjs
chmod a+x phantomjs
5. 安装MySQL-python
Python使用MySQL数据库,需要安装该模块。
下载地址:
https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip
解压后安装:python setup.py install
pip install mysql-python
6. 安装MySQL
下载地址:
http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.27-1.linux_glibc2.5.x86_64.rpm-bundle.tar
解压后安装使用rpm命令安装
rpm MySQL-server-5.6.27-1.linux_glibc2.5.x86_64.rpm
rpm MySQL-client-5.6.27-1.linux_glibc2.5.x86_64.rpm
rpm MySQL-devel-5.6.27-1.linux_glibc2.5.x86_64.rpm
rpm MySQL-shared-5.6.27-1.linux_glibc2.5.x86_64.rpm
4 部署注意点
1、不要忘记修改环境变量
2、安装MySQL后需要修改默认字符集为utf8