美奇科技 发表于 2016-12-24 09:50:15

jenkins nginx uwsgi web.py

  Jenkins安装起来很容易:
  wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -
  sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'
  sudo apt-get update
  sudo apt-get install jenkins
  默认为8080端口,进去jenkins控制台后,进入‘系统管理’,‘管理插件’,选中‘Github plugin’,点‘直接安装’。
  至于新建Job 以及安全设置可以参考Jenkins的官方文档,很详细。
  Github的job只要在‘源码管理’的Git   Repository URL填上想要编译的项目地址就可以了,焦点移出后会自动检测该Github项目是否可用。
  由于Jenkins的job目录有点儿深:/var/lib/jenkins/jobs/your_project/workspace/src
  python项目又不需要编译,所以可以在Jenkins的编译时运行的shell里把src复制到一个目录浅的地方,比如/srv/your_project/src, 或者做个软链接  ln -s /var/lib/jenkins/jobs/your_project/workspace/src /srv/your_project/src。
  nginx的安装比较简单,apt-get就可以了。
  配置:
  vi /etc/nginx/sites-available/defaut
  在默认的server后面添加新的server:
  server {
  listen 80;
  server_name blog.xuli.cc;
  location / {
  include uwsgi_params;
  uwsgi_pass localhost:9999;
  }
  }
  vi /etc/nginx/nginx.conf 
  由于添加了server,需要把server_names_hash_bucket_size 64; 打开。
  另外,可以考虑把刚才Jenkins要通过8080端口访问的方式改成通过子域名jenkins.mydomain.com访问,需要添加proxy_pass:
  server {
  listen 80;
  server_name jenkins.mydomain.com;
  error_log /var/log/nginx/jenkins.error_log info;
  location / {
  proxy_pass http://localhost:8080;
  }
  }
  安装uwsgi
  由于需要同时编译uwsig为python模块,需要先安装python-dev :
  apt-get install python-dev
  我的VPS的系统为ubuntu 12.04,apt-get安装的的uswgi为1.0,不支持--wsgi-file参数,需要卸掉后获取stable版本:
  http://uwsgi-docs.readthedocs.org/en/latest/Download.html
  tar解压后,在解压后的文件中:
  python uwsgiconfig.py --build
  完事儿以后可以用 ./uwsgi -version查看是否成功。可以将bin目录下的uwsgi复制到/usr/bin目录下更方便。
  web.py的安装也很简单,用easy_install或者pip都可以。
  下面就是webpy的代码了:

import web
import os
from datetime import datetime

web.config.debug = False

urls = ('/', 'index')
render = web.template.render('templates/', globals())
class index:
def GET(self):
# return str(datetime.now()) + "<br/>" + os.path.abspath(os.path.curdir)
return render.testwebpy(datetime.now())
app = web.application(urls, globals(), autoreload=False)

if __name__ == '__main__':
app.run()
application = app.wsgifunc()

  最后一句是一定要有的,可以参考webpy网站教程。
  到这一步,就可以运行uwsgi了:
  进入webpy项目的src目录(/srv/your_project/src) :
  uwsgi -s :9999 --wsgi-file app.py
  在前端运行可以方便调试,调试没问题后,把它放到后台运行:
  nohup uwsgi -s :9999 --wsgi-file app.py &
  如果不在src目录下,会报错:No template named testwebpy
  大概就是这些吧,可能有记忆不准确的地方,等下次有机会再配置一次。
  Reference:
  https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+on+Ubuntu
  http://uwsgi-docs.readthedocs.org/en/latest/Install.html
  http://uwsgi-docs.readthedocs.org/en/latest/WSGIquickstart.html
  http://webpy.org/cookbook/mod_wsgi-nginx
页: [1]
查看完整版本: jenkins nginx uwsgi web.py