Code Monkey home page Code Monkey logo

ksproxy's Introduction

ksproxy简介

为了避免用户程序连接ksc接口时较复杂的认证过程,ksproxy将认证过程封装,对用外提供不需要认证的简单HTTP接口,只需将认证使用的ks_access_key_id、ks_secret_access_key配置在ksproxy的配置文件中即可。

请求的URL格式: http://serve_ip:serve_port/service_name/method?params 如:http://127.0.0.1:9000/offline/GetPresetDetail?preset=test service_name, method, GET或POST, 及GET/POST的参数和响应格式请参考相应服务的API手册

运行平台

本程序在Ubuntu 14.04 (Python 2.7.9)、CentOS 6.5 (Python 2.6.6)、Windows 7 x86_64 (Python 2.7.12)上测试通过。以下为Linux平台的安装方法,Windows平台的安装步骤请参考 https://github.com/ksvc/ksproxy/blob/master/README_Windows.md

安装kscore

mkdir /data/koptest/
cd /data/koptest
git clone https://github.com/KscSDK/ksc-sdk-python.git
cd /data/koptest/ksc-sdk-python
python setup.py install

安装过程中,会将kscore和相关的依赖包安装到系统的python库路径中,如

/usr/local/lib/python2.7/site-packages

如果不想对系统造成修改,或没有root权限,推荐使用VirtualEnv。本文最后有VirtualEnv用法的简要介绍。

下载ksproxy代码

cd /data/koptest
git clone https://github.com/ksvc/ksproxy.git
cd /data/ksproxy

修改配置文件

ksproxy.json,一般需修改region、ks_access_key_id、ks_secret_access_key等配置。

启动proxy程序

注意:如果有防火墙,请关闭或将程序绑定端口添加到防火墙例外。

python ./ksproxy.py

VirtualEnv

VirtualEnv可以创建独立的Python运行环境。在Ubuntu 14.04可通过如下命令安装VirtualEnv软件:

sudo aptitude install python-pip
sudo pip install virtualenv

CentOS 6.5可通过如下命令安装:

sudo yum install python-setuptools python-devel
sudo easy_install virtualenv

创建一个独立的运行环境:

cd /data
virtualenv --no-site-packages koptest

激活该运行环境:

cd /data/koptest
source ./bin/activate

激活后终端的命令提示符前会有个(koptest)的前缀:

(koptest) sunny@tiger:~$

之后pip等命令安装的包都是安装到创建的运行环境中,不会对系统产生影响。

使用supervisor使程序以daemon方式运行

安装和启动监控

CentOS
sudo yum install supervisor
sudo service supervisord start

Debian / Ubuntu
sudo aptitude install supervisor
sudo service supervisor start

添加监控,修改/etc/supervisord.conf

[program:ksproxy]
command=/home/work/ksproxy/bin/python /home/work/ksproxy/ksproxy/ksproxy.py # 执行的命令,注意使用的是virtualenv
directory=/home/work/ksproxy/ksproxy  # 执行命令的路径
user=work # 执行命令的用户
autostart=true # 随着supervisord的启动而启动
autorestart=true  # 出错后自动重启

更新配置

supervisorctl update

ksproxy's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.