> CentOS > CentOS服务器 >

CentOS6.4安装Python web开发+生产环境

1.概述
centos6.4安装Python, setuptool, pip, virtualenv, mysql, django, libevent, memcache, nginx, git, beyond compare, jdk, eclipse, pydev

2.参考命令
centos6.4自带Python2.6, 反正2.x区别不大,也就将就着用了.
1.安装setuptool
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
wget --no-check-certificate  https://bootstrap.pypa.io/ez_setup.py 
python ez_setup.py 
当然也可以去下载setuptool源码,解压后编译安装

2.安装pip
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
wget --no-check-certificate http://pypi.python.org/packages/source/p/pip/pip-1.0.2.tar.gz 
tar zxf pip-1.0.2.tar.gz 
cd pip-1.0.2 
python setup.py install 
3.安装virtualenv
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
pip install virtualenv 


4.创建一个虚拟环境,并激活
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
virtualenv pydj14 
source pydj14/bin/activate 
5.安装mysql
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
wget http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-5.5.17-1.linux2.6.x86_64.tar 
tar -xf MySQL-5.5.17-1.linux2.6.x86_64.tar 
yum erase mysql-libs 
rpm -ivh MySQL-server-5.5.17-1.linux2.6.x86_64.rpm 
rpm -ivh MySQL-devel-5.5.17-1.linux2.6.x86_64.rpm  (安装devel才会有mysql_config文件,否则MySQL-python报错找不到此文件) 
rpm -ivh MySQL-client-5.5.17-1.linux2.6.x86_64.rpm 可选 
chown -R mysql:mysql /var/lib/mysql 
/etc/init.d/mysql start          启动 
mysqladmin -uroot password 'ppp' 
/usr/bin/mysqladmin -u root -p shutdown      关闭  

开机启动可选:
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
/sbin/chkconfig --add mysql 
数据库目录 /var/lib/mysql/
配置文件 /usr/share/mysql
相关命令 /usr/bin      (mysqladmin mysqldump等命令)
启动脚本 /etc/rc.d/init.d/
6.安装django开发环境
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
pip install south 
pip install --download MySQL-python  解压后修改setup_posix.py 将mysql_config路径改为/usr/bin/mysql_config 
pip install python-memcached 
pip install django==1.4.5 
pip install uwsgi 
7.安装libevent
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
yum install gcc 
yum install gcc-c++ libstdc++-devel 
yum install zlib-devel 
wget http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz 
tar zxvf libevent-1.4.14b-stable.tar.gz   
cd libevent-1.4.14b-stable   
./configure --prefix=/usr/local/libevent/   
make && make install  
下面二选一  
ln -s /usr/local/libevent/lib/libevent-1.4.so.2 /lib/libevent-1.4.so.2        32位系统 
ln -s /usr/local/libevent/lib/libevent-1.4.so.2 /lib64/libevent-1.4.so.2      64位系统 
8.安装memcache
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
wget http://www.danga.com/memcached/dist/memcached-1.2.5.tar.gz 
tar zxvf memcached-1.2.5.tar.gz 
cd memcached-1.2.5 
./configure --prefix=/usr/local/memcached/ --with-libevent=/usr/local/libevent/   
make && make install 
/usr/local/memcached/bin/memcached -d -m 64 -u root -l 127.0.0.1 -p 11211 -c 128 -P /tmp/memcached.pid 
9.安装nginx
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm 
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm 
yum install nginx 
修改防火墙 
vi /etc/sysconfig/iptables 
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT 
service iptables restart 
配置目录:/etc/nginx/
PID目录:/var/run/nginx.pid
错误日志:/var/log/nginx/error.log
访问日志:/var/log/nginx/access.log
默认站点目录:/usr/share/nginx/html
启动nginx:nginx
重启nginx:killall -HUP nginx
测试nginx配置:nginx -t

10.安装git
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
yum -y install zlib-devel openssl-devel perl cpio expat-devel gettext-devel 
yum install autoconf 
yum install git 
11.安装BeyondCompare
http://www.scootersoftware.com/download.php下载rpm包安装

12.git 配置bc3
[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
[color] 
        ui = true 
[core] 
        editor = vim 
 
[diff] 
        tool = bc3 
[difftool "bc3"] 
        cmd = bcompare $LOCAL $REMOTE 
[difftool] 
        prompt = false 
13.Python web开发环境
下载jdk1.7rpm包, rpm命令安装
下载eclipse 解压,mv至/usr/local目录下,配置桌面启动图标如下代码

注意jdk版本与eclipse版本, eclipse4.3及以前可以使用jdk1.6(推荐jdk1.6安装3.3--3.7的eclipse), eclipse4.4起必须jdk1.7及以上.
注意jdk与eclipse位数一致,最好与操作系统一致,都用64位,32位。从上面安装命令可以看出,本文章是centos6.4 64位

桌面添加eclipse启动图标(centos6.4添加后桌面不会立即出现该图标,仅仅放在桌面备选项中,手动点击左上角,应用,找到eclipse,右键,添加至桌面)

[plain] view plaincopy在CODE上查看代码片派生到我的代码片 
vim /usr/share/applications/eclipse.desktop 
 
输入如下 
[Desktop Entry] 
Encoding=UTF-8 
Name=Eclipse 
Comment=Eclipse IDE 
Exec=/usr/local/eclipse/eclipse 
Icon=/usr/local/eclipse/icon.xpm 
Terminal=false 
Type=Application 
Categories=GNOME;Application;Development; 
StartupNotify=true 
安装pydev
下载源码包解压至eclipse dropins目录,或者在线安装(3.7以下版本eclipse在线安装很可能失败),略去
仅需要注意pydev2.X jdk1.6或以上,但1.8有点小问题。pydev3必须jdk1.7以上。

具体mysql配置,nginx配置, memcache配置就各自百度谷歌吧. (责任编辑:IT)