appfog tunnel管理数据库

appfog的大名我想不用说了,如果你不知道呢,可以问谷哥或度娘。其在2012年获得值得关注的十个云计算服务第一名。appfog为我们提供了云应用快速部署服务。利用其提供的平台,我们可以很方便的在上面搭建属于自己的应用。如wordpress 、phpbb、织梦等(其可布应用不止止只有PHP啊,只不过我其他网页语言应用比较陌生)。不过在使用免费的appfog服务时,其对我们设置了很多限制。比如上传文件大小不超过2M,内存使用不超过2G。除此之外,比如维护和管理数据库也是件麻烦事。不过一旦了解了其工作原理,维护数据库也不是件难事。本文主要介绍如何通过官方提供的tunnel进行连接管理。

1、安装管理环境

先从appfog官网下载ruby环境,安装完成后,打开Start Command Prompt with Ruby,安装af环境。

gem update --system
gem install af
af login

注:以上是在windows环境下,如果是在linux/mac环境下,一般其自带都有ruby环境,可以直接通过以上命令安装af 环境。并登录管理。这里至于怎么安装应用就略过了,现以mysql为例直接说如何管理数据库 。

2、安装devkit

在windows下进行管理时,还需要安装devkit环境。在linux/mac 下可以直接略过该步骤。没有该软件,无法进行tunnel连接数据库,其提示如下:

C:Documents and SettingsAdministrator>af tunnel 361way
To use `af tunnel', you must first install Caldecott:
        gem install caldecott
Note that you'll need a C compiler. If you're on OS X, Xcode
will provide one. If you're on Windows, try DevKit.
This manual step will be removed in the future.
Error: Caldecott is not installed.
http://cloud.github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

上面的错误提示已经说的很明白了,从那里下载devkit应用,并安装caldecott 。不过上面的提示还有点太过简单了。devkit下载好以后实际上是一个7z压缩文件。执行exe时其会提示让解压到何处。如解压到c:/devkit。(注意:目录不能有空格)在安装目录下运行ruby dk.rb,然后按照提示分别运行ruby dk.rb init 和 ruby dk.rb install来增强ruby 。

完成了devkit的安装,就可以通过gem install caldecott命令安装tunnel管理所需的包了。大致如下:

C:webkit>gem install caldecott
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Fetching: em-http-request-0.3.0.gem (100%)
Building native extensions.  This could take a while...
Fetching: em-websocket-0.3.8.gem (100%)
Fetching: rack-1.5.2.gem (100%)
Fetching: rack-protection-1.3.2.gem (100%)
Fetching: tilt-1.3.3.gem (100%)
Fetching: sinatra-1.3.5.gem (100%)
Fetching: async_sinatra-0.5.0.gem (100%)
Fetching: json-1.6.8.gem (100%)
Building native extensions.  This could take a while...
Fetching: caldecott-0.0.5.gem (100%)
Successfully installed escape_utils-0.3.2
Successfully installed em-http-request-0.3.0
Successfully installed em-websocket-0.3.8
Successfully installed rack-1.5.2
Successfully installed rack-protection-1.3.2
Successfully installed tilt-1.3.3
Successfully installed sinatra-1.3.5
Successfully installed async_sinatra-0.5.0
Successfully installed json-1.6.8
Successfully installed caldecott-0.0.5
10 gems installed

3、进行tunnel连接

C:webkit>af services
//查看目前的mysql服务名
============== System Services ==============
+------------+---------+-------------------------------+
| Service    | Version | Description                   |
+------------+---------+-------------------------------+
| mongodb    | 1.8     | MongoDB NoSQL store           |
| mysql      | 5.1     | MySQL database service        |
| postgresql | 9.1     | PostgreSQL database service   |
| rabbitmq   | 2.4     | RabbitMQ message queue        |
| redis      | 2.2     | Redis key-value store service |
+------------+---------+-------------------------------+
=========== Provisioned Services ============
+--------------------+---------+--------+
| Name               | Service | In     |
+--------------------+---------+--------+
| 361waytest-mysql-11892 | mysql   | ap-aws |
+--------------------+---------+--------+
//进行tunnel连接
C:webkit>af tunnel 361waytest-mysql-11892
Deploying tunnel application 'caldecott-ap-aws'.
Uploading Application:
  Checking for available resources: OK
  Packing application: OK
  Uploading (1K): OK
Push Status: OK
Binding Service [361way-mysql-11892]: OK
Staging Application 'caldecott-ap-aws': OK
Starting Application 'caldecott-ap-aws': OK
Getting tunnel connection info: OK
//显示用户名,密码
Service connection info:
  username : xxxxxxxxxxxxx
  password : xxxxxxxxxxxxx
  name     : xxxxxxxxxxxxxxxxxxxxxxxxxxxx
  infra    : ap-aws
Starting tunnel to 361way-mysql-11892 on port 10000.
1: none
2: mysql
3: mysqldump
Which client would you like to start?: 1
Open another shell to run command-line clients or
use a UI tool to connect using the displayed information.
Press Ctrl-C to exit...

连接步骤如上所示。至此已建立了远程主机和本机的连接,往下就可以通过navicat等mysql管理工具进行连接管理了。记得把主机连接信息输入为localhost,端口为10000 。

后记:除了以上的方法外,也可以通过phpmyadmin或者通过php等环境变量参数获取管理等方式。具体可以参看官方页面 。但个人还是比较喜欢tunnel这种方式。




本站的发展离不开您的资助,金额随意,欢迎来赏!

You can donate through PayPal.
My paypal id: itybku@139.com
Paypal page: https://www.paypal.me/361way

  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.