首页 > 学院 > 开发设计 > 正文

openshift安装,调试及简单代码

2019-11-08 02:49:24
字体:
来源:转载
供稿:网友

Windows下的安装方法

我的windows环境:Win7 64位

Openshift介绍

OpenShift百度百科 调戏OpenShift:一个免费能干的云平台

安装OpenShift 客户端工具,附图解

按照该教程,安装完毕后,再进行rhc setup设置时,输入openshift账户密码后,一直没有反应,后来找了官网上的教程,进行的安装; 1、意思是先安装Git for Windows 2、安装Ruby 3、安装rhc,安装成功后,截图如下,与教程里稍有不同。 rhc安装成功后截图

Openshift官网安装教程,for windows

新版OpenShift空间申请使用教程-安装WordPRess,MySQL及绑定域名,文件管理

新版OpenShift空间文件目录结构 新版OpenShift空间文件目录结构 OpenShift空间文件系统结构说明如下:

|– .env??#空间环境配置

|– app-root??#应用目录

|?? |– data??#存储数据

|?? |– repo -> runtime/repo?? #代码

这里要提醒一下,当你创建应用时你的代码就会被放在app-root下的repo下面,你的应用本身产生的数据是存储在app-root下的data下面的 这里写图片描述

app-root目录是你的应用运行时代码所在的目录 app-deployments是你git把代码提交上去后git远程库的目录,也就是部署上去的目录

参考教程

1、廖雪峰的Git教程:教程比较详细,初学者可以参考 2、最新Openshift搭建 - 贴吧云签到图文教程:介绍了如何利用openshift搭建了百度贴吧签到系统。 3、Getting Started with Python 2.6, 2.7, and 3.3:官方文档 4、Python Web 应用:WSGI基础 5、python学习:最简单的web应用(WSGI接口):下面是具体介绍 web应用本质上来说就是: 浏览器发送一个HTTP请求; 服务器收到请求,生成一个HTML文档; 服务器把HTML文档作为HTTP响应的Body发送给浏览器; 浏览器收到HTTP响应,从HTTP Body取出HTML文档并显示。 [0]我们要生成一个动态的web应用.如果由自己来写底层代码就太麻烦了.所以python提供了一个统一的接口,让我m只需要处理浏览器的请求,而不用去管各种协议.这个接口就是WGSI. 下面的代码就是利用wsgiref模块创建一个服务器,监听浏览器的请求,并且作出回应.

from wsgiref.simple_server import make_server# 自己编写的application函数:def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/html')]) body = r'<h1>Hello, %s!</h1>'%(environ['PATH_INFO'][1:] or 'web') return [body.encode('utf-8')]# 创建一个服务器,ip地址为空,端口是8000,处理函数是application:httpd = make_server('127.0.0.1', 8000, application)print('Serving HTTP on port 8000...')# 开始监听HTTP请求:httpd.serve_forever()

wsgi接受一个处理函数,这个处理函数接受两个参数:一个是HTTP响应码,一个是一组list表示的HTTP Header,每个Header用一个包含两个str的tuple表示。HTTP请求的所有输入信息都可以通过environ获得,HTTP响应的输出都可以通过start_response()加上函数返回值作为Body。 6、web python – WSGI接口:另外一个写wsgi.py的例子

#! /usr/bin/env python# Our tutorial's WSGI serverfrom wsgiref.simple_server import make_serverdef application(environ, start_response): # Sorting and stringifying the environment key, value pairs response_body = ['%s: %s' % (key, value) for key, value in sorted(environ.items())] response_body = '/n'.join(response_body) status = '200 OK' response_headers = [('Content-Type', 'text/plain'), ('Content-Length', str(len(response_body)))] start_response(status, response_headers) return [response_body]# Instantiate the WSGI server.# It will receive the request, pass it to the application# and send the application's response to the clienthttpd = make_server( 'localhost', # The host name. 8051, # A port number where to wait for the request. application # Our application object name, in this case a function. )# Wait for a single request, serve it and quit.httpd.handle_request()

简单写一个在openshift上的python程序

事先准备好软件:winscp,puttygen

1、在openshift建立好新的应用; 2、按《参考教程-2》例程所示,在puttygen软件上生成密匙,公匙,并连接好。 3、打开本地winscp程序,下图右边Source Code里的代码复制过来,其中从ssh://后面到/~/git/python.git/之间的内容,作为主机名填入winscp,点击’高级’,导入密匙(《参考教程-2》中有详细步骤) 图1

图2 连接到openshift后,winscp右侧显示如下,为新建程序在服务器上的文件夹目录 这里写图片描述

4、进入app-root/runtime/repo文件夹,会发现文件夹下有如下几个文件 这里写图片描述

.openshift:这个文件夹及其中内容不需要操作 requirements.txt:可添加需要的依赖库(默认为空) setup.py:添加一些配置信息(也可以添加依赖库) wsgi.py:python应用默认的入口文件

我们可以通过修改wsgi.py里面的代码,来修改主页内容 5、将wsgi.py里面标签下内容改成hello,保存后,打开openshift上程序,则在主页上就显示出hello字样 以下是官网文档,意思差不多

To make the first change, edit wsgi.py in the base of the local git repository. Go to the file in the terminal and edit with a command line editor like VIM or EMacs. Alternatively, edit the file using any text editor or IDE. The beginning of this file starts a basic WSGI application with some URL routing. Strip out everything between the two < body> tags and change the content to look like this:

<body> <h1>Hello world!</h1></body>

6、将wsgi.py再次重写:

程序编写

1、node.js介绍 2、如何基于OpenShift进行微信公众号开发 3、openshift之Python生成在线API:里面有介绍如何在openshift上安装运行python程序 4、Flask——使用Python和OpenShift进行即时Web开发


上一篇:linux属性

下一篇:对象数组&amp;对象成员

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表