Webpy+Nginx+Flup+Spawn-fcgi构建webpy开发环境

Webpy+Nginx+Flup+Spawn-fcgi构建webpy开发环境
------------------------------------------------------
SYS_OS:CentOS 6.3x64

一:为了统一环境 这里统一采用Python 2.7+
wget http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tgz
wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz/download
wget http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.68.tar.gz
wget http://www.dbasky.net/tool/python/setuptools-0.6c9.tar.gz

yum install gcc* pcre-devel mysql-devel make --skip-broken -y
tar zvfx Python-2.7.5.tgz
cd Python-2.7.5
./configure
make && make install
cd ..

userdel -r mysql
groupdel mysql
groupadd mysql -g 800
useradd -g mysql -u 801 -M -s /sbin/nologin mysql
cat /etc/passwd|grep mysql

tar zxvf mysql-5.1.68.tar.gz
cd mysql-5.1.68
./configure --prefix=/usr/local/mysql-5.1.68 \
--with-unix-socket-path=/usr/local/mysql-5.1.68/tmp/mysql.sock \
--localstatedir=/data/mysqldata \
--enable-assembler \
--enable-thread-safe-client \
--with-mysqld-user=mysql \
--without-debug \
--with-pthread \
--enable-assembler \
--with-extra-charsets=all \
--with-readline \
--with-ssl \
--with-embedded-server \
--enable-local-infile \
--with-plugins=partition,innobase \
--with-mysqld-ldflags=-all-static \
--with-client-ldflags=-all-static
make
make install

/bin/cp support-files/my-medium.cnf /etc/my.cnf
mkdir -p /data/mysqldata
/usr/local/mysql-5.1.68/bin/mysql_install_db --user=mysql
chgrp -R mysql /usr/local/mysql-5.1.68
/usr/local/mysql-5.1.68/bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /usr/local/mysql-5.1.68/bin/mysql-server
chmod 755 /usr/local/mysql-5.1.68/bin/mysql-server
echo "/usr/local/mysql-5.1.68/bin/mysql-server start" >> /etc/rc.local
/usr/local/mysql-5.1.68/bin/mysqladmin -uroot password admin
echo "alias mysql-login='/usr/local/mysql-5.1.68/bin/mysql -uroot -p'" >> /root/.bashrc
source /root/.bashrc
cd ..
echo "export PATH=/usr/local/mysql-5.1.68/bin:\$PATH" >> /etc/profile
source /etc/profile
echo "/usr/local/mysql-5.1.68/lib/mysql" > /etc/ld.so.conf.d/mysql.conf
ldconfig

tar zvfx setuptools-0.6c9.tar.gz
cd setuptools-0.6c9
python setup.py install
cd ..

tar zvfx MySQL-python-1.2.3.tar.gz
cd MySQL-python-1.2.3
python setup.py install
cd ..

二:安装Nginx
wget http://nginx.org/download/nginx-1.4.2.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz

tar zxvf pcre-8.33.tar.gz
cd pcre-8.33/
./configure
make && make install
cd ../

tar zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --prefix=/usr/local/nginx-1.4.2 \
--with-http_stub_status_module \
--with-http_ssl_module
make
make install
cd ../

vi /usr/local/nginx-1.4.2/conf/nginx.conf
#-----------------------------------------------------------------
user www develop;
worker_processes 8;
error_log logs/error.log;
pid logs/nginx.pid;

worker_rlimit_nofile 60000;
events {
use epoll;
worker_connections 10000;
}

http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
keepalive_timeout 10;
client_header_buffer_size 32k;
large_client_header_buffers 4 128k;
client_max_body_size 10m;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_types text/javascript text/plain application/x-javascript text/css application/xml;
include vhosts/*.conf;
fastcgi_intercept_errors on;
}
#-----------------------------------------------------------------

vi example.conf
#-----------------------------------------------------------------
server {

listen 80;
server_name example.com;
root /data/web/example;
autoindex off;
access_log off;

location / {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; # [1]
fastcgi_param PATH_INFO $fastcgi_script_name; # [2]
fastcgi_pass 127.0.0.1:9000;
}

location /static/ {
if (-f $request_filename) {
rewrite ^/static/(.*)$ /static/$1 break;
}
}
}
#-----------------------------------------------------------------

/usr/local/nginx-1.4.2/sbin/nginx
echo "/usr/local/nginx-1.4.2/sbin/nginx" >> /etc/rc.local

三:安装webpy
wget http://webpy.org/static/web.py-0.36.tar.gz
wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz

tar zvfx flup-1.0.2.tar.gz
cd flup-1.0.2
python setup.py install
cd ..

tar zvfx spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure
make && make install
cd ..

tar zvfx web.py-0.36.tar.gz
cd web.py-0.36
python setup.py install
cd ..

vi index.py
#-------------------------------------------------------------------------
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import web

urls = ("/.*", "hello")
app = web.application(urls, globals())

class hello:
def GET(self):
return 'Hello, world!'

if __name__ == "__main__":
web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)
app.run()
#-------------------------------------------------------------------------

chmod a+x index.py

启动:spawn-fcgi -d /data/web/example -f /data/web/example/index.py -a 127.0.0.1 -p 9000
关闭:kill `pgrep -f "python /data/web/example/index.py"`
-f 指定调用FastCGI的进程的执行程序位置
-a 绑定到地址 addr
-p 绑定到端口 port
-F 指定产生的FastCGI的进程数(很多人以为是-C,其实那是PHP专用的,这里要用-F)
-P 指定产生的进程的PID文件路径
-u 和-g FastCGI使用什么身份运行
-n Debug调试模式
启动端口检查:
netstat -lntup|grep 9000
http:/localhost/ 访问测试

管理脚本 可以参考如下:
https://github.com/sdjl/zarkpy/blob/master/tool/launch.sh

posted @ 2015-06-18 11:17  study-notes  阅读(307)  评论(0编辑  收藏  举报