Openshift中diy模式安装山寨verycd:simplecd

redhat提供的openshift空间还是不错的,灵活性蛮高,可以用来折腾一些东西。这次要折腾的是simplecd(山寨verycd)的安装。

注意:当前使用的代码是较早版本,功能简陋,而且无法实现抓取了,会一直返回verycd的html代码,如果有强烈需求的,可以自己根据代码修改。

准备工作

需要安装ngnix,python,web.py,flup,spawn-fcgi

以下操作也都在SSH中。

1.安装python,web.py

#进入"tmp"目录
cd $OPENSHIFT_TMP_DIR
#下载Python 2.7.2
wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2
tar jxf Python-2.7.2.tar.bz2
cd Python-2.7.2
./configure --prefix=$OPENSHIFT_DATA_DIR
make install

setuptools: cd $OPENSHIFT_TMP_DIR wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz tar zxf setuptools-0.6c11.tar.gz cd setuptools-0.6c11 $OPENSHIFT_DATA_DIR/bin/python setup.py install pip:

cd $OPENSHIFT_TMP_DIR
wget http://pypi.python.org/packages/source/p/pip/pip-1.1.tar.gz
tar zxf pip-1.1.tar.gz
cd pip-1.1
$OPENSHIFT_DATA_DIR/bin/python setup.py install

web.py(0.33): cd $OPENSHIFT_TMP_DIR wget http://webpy.org/static/web.py-0.33.tar.gz tar xvzf web.py-0.33.tar.gz cd web.py-0.33 $OPENSHIFT_DATA_DIR/bin/python setup.py install

2.flup,spawn-fcgi

安装 Flup:

http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
tar xvzf flup-1.0.2.tar.gz
cd flup-1.0.2
$OPENSHIFT_DATA_DIR/bin/python setup.py install

安装 Spawn-fcgi:

wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar zxvf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3 
./configure --prefix=$OPENSHIFT_DATA_DIR
make && make install # install

3.安装ngnix

下载pcre备用:

cd $OPENSHIFT_TMP_DIR
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.bz2
tar -xjvf pcre-8.33.tar.bz2

下载ngnix:

cd $OPENSHIFT_TMP_DIR
wget http://nginx.org/download/nginx-1.5.2.tar.gz
tar -zxvf nginx-1.5.2.tar.gz
cd nginx-1.5.2
./configure  --with-pcre=$OPENSHIFT_TMP_DIR/pcre-8.33 --prefix=$OPENSHIFT_DATA_DIR/nginx 
make && make install

配置ngnix:

echo $OPENSHIFT_DIY_IP
echo $OPENSHIFT_DIY_PORT

得到主机的IP和端口,修改配置文件.

我的配置文件如下:

#user www-data;
worker_processes  2;

error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

pid        /dev/shm/nginx.pid;

events {
    use epoll;
    worker_connections  2048;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;

    log_format main      '$remote_addr - $remote_user [$time_local]  '
      '"$request" $status $bytes_sent '
      '"$http_referer" "$http_user_agent" '
      '"$gzip_ratio"';

    log_format download  '$remote_addr - $remote_user [$time_local]  '
      '"$request" $status $bytes_sent '
      '"$http_referer" "$http_user_agent" '
      '"$http_range" "$sent_http_content_range"';

    client_header_timeout  3m;
    client_body_timeout    3m;
    send_timeout           3m;

    client_header_buffer_size    1k;
    large_client_header_buffers  4 4k;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_http_version 1.1;
    gzip_comp_level 3;
    gzip_types text/css text/xml text/plain application/x-javascript application/xml application/pdf application/x-perl application/x-tcl application/msword application/rtf application/vnd.ms-excel application/vnd.ms-powerpoint application/vnd.wap.xhtml+xml image/x-ms-bmp;
    gzip_disable "MSIE [1-6] .";
    gzip_vary on;

    output_buffers   1 32k;
    postpone_output  1460;

    sendfile         on;
    tcp_nopush       on;
    tcp_nodelay      on;

    keepalive_timeout  75 20;

    #目录替换成自己空间的,这里是已经下载好程序源码之后的
   fastcgi_cache_path /var/lib/openshift/5265233de0b8cd58dc00003d/app-root/repo/simplecd/cache  levels=1:2  keys_zone=webpy:50m;

#listen 替换成你的
server {
        listen 127.12.225.1:8080;
        server_name  idayer.com;

        access_log  logs/access.log  main;
        error_log  logs/error.log;

        #root也替换成你的应用目录
        root   /var/lib/openshift/5265233de0b8cd58dc00003d/app-root/repo/simplecd;
        index  index.html index.htm;

        location / {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
            fastcgi_param PATH_INFO $fastcgi_script_name;
            fastcgi_pass 127.12.225.1:15123;
            fastcgi_cache webpy;
            fastcgi_cache_key $server_addr$request_uri;
            fastcgi_cache_valid any 1m;
            fastcgi_hide_header Set-Cookie;
        }
        location /static/ {
            if (-f $request_filename) {
                rewrite ^/static/(.*)$ /static/$1 break;
            }
        }
}
}

之后先把自带的testrubyserver服务停掉

killall ruby

编辑启动文件

vi ~/app-root/repo/.openshift/action_hooks/start

修改为(注意下面的配置是最终配置完成的)

#!/bin/bash
# The logic to start up your application should be put in this
# script. The application will work only if it binds to
# $OPENSHIFT_INTERNAL_IP:8080
# nohup $OPENSHIFT_REPO_DIR/diy/testrubyserver.rb $OPENSHIFT_INTERNAL_IP $OPENSHIFT_REPO_DIR/diy > $OPENSHIFT_DIY_LOG_DIR/server.log 2>&1 &
#设置自己安装的python到执行环境中
export PATH=$OPENSHIFT_DATA_DIR/bin:$PATH
#用spawn-fcgi开fcgi
nohup $OPENSHIFT_DATA_DIR/bin/spawn-fcgi -u www-data -g www-data -d  /var/lib/openshift/5265233de0b8cd58dc00003d/app-root/repo/simplecd/ -f  /var/lib/openshift/5265233de0b8cd58dc00003d/app-root/repo/simplecd/code.py -a 127.12.225.1 -p 15123 -F 2 > $OPENSHIFT_DIY_LOG_DIR/server.log 2>&1 &

$OPENSHIFT_DIY_LOG_DIR/server.log 2>&1 &
nohup $OPENSHIFT_DATA_DIR/nginx/sbin/nginx > $OPENSHIFT_DIY_LOG_DIR/server.log 2>&1 &

保存退出

编辑停止命令文件

vi ~/app-root/repo/.openshift/action_hooks/stop

修改为

#!/bin/bash
source $OPENSHIFT_CARTRIDGE_SDK_BASH

# The logic to stop your application should be put in this script.
# The logic to stop your application should be put in this script.
kill `ps -ef | grep testrubyserver.rb | grep -v grep | awk '{ print $2 }'` > /dev/null 2>&1
ps -ef | grep nginx | while read line
do
  kill -9 `echo $line | awk '{ print $2 }'`
done
exit 0

保存之后退出,rhc app start|stop|restart 你的应用,顺利的话,现在服务器空间应该是配置完成了,如果出现错误,注意查看配置文件和日志。

安装simplecd

下载源码

#进入到repo目录
cd /app-root/repo/
hg clone https://simplecd.googlecode.com/hg simplecd
cd simplecd
hg update dev-sqlite

关于配置在上面start文件和ngnix中已经集成了。

simplecd的安装只能进行到这,目前的代码无法抓取verycd,不过可以下载作者提供的数据库来演示。

数据库(截止2009.12.18)

eMule链接:

ed2k://|file|verycd.sqlite3.db.lzma|233121378|0fd38cff1353e996576f9f3e9b8c65dd|

解压: lzma -d verycd.sqlite3.db.lzma

然后放入simplecd目录即可

在openshift免费空间的大小是1G,而且上面的数据库的大小将近1G,所以无法成功解压。我就删减了数据库的条目,生成几十M的数据文件来演示。

有需要的话可以下载我的:http://pan.baidu.com/s/1y076H

数据库文件放到simplecd目录下,然后就可以访问网站了。

查看我的:simplecd.idayer.com

0 条评论