Meteor is an open source HTTP server, designed to offer developers a simple means of integrating streaming data into web applications without the need for page refreshes. Meteor是一个开源的HTTP服务器,旨在为开发人员提供简单非刷新页面的方式把程序的数据流集成到web应用程序中。Meteor不是框架,不是meteor.com。搜了下,这个还真是小众,至少中文资料非常少。说到Meteor,不得不说live Blogging。因为想在wordpress上弄一个微博,才有live blogging,然后才有meteor(认识过程)。 Live Blogging(中文名称:WordPress微博)是一个WordPress插件,允许您在WordPress网站中创建即时消息博文(类似Twitter的微博客)。该插件使用Comet技术来降低服务器负载,提升更新发布速度,提供了较好的整体用户体验。该插件发布后引起了WPer的广泛兴趣,目前正在准备一些重大的改进。该插件在2009年Weblog Tools Collection(网络博客工具集锦) 插件竞赛中获得亚军。可以通过作者提供的屏幕录像来了解该插件目前的主要功能。 Live Blogging我就不详细介绍了,链接地址为中文翻译者的博客,比较详细的介绍了这个wordpress插件。不过高级用法还有待自己摸索研究。
Live Blogging提供Meteor的平滑模式。于是我也在我的服务器安装了这个Meteor,安装过程在这里分享出来,特别是centos系统的童鞋。
网上有给出用curl安装的,在centos6以后能成功,在centos5,glibc2.5安装不成功。
一、下载解压
Meteor必须要安装perl 5,确保您的机器上安装了。
首先,建立文件夹/usr/local/meteor
mkdir /usr/local/meteor cd /usr/local/meteor
去网站下载Meteor压缩包,并进行解压:
wget http://meteorserver.org/download/latest.tgz tar zxvf latest.tgz
解压后会在meteor文件夹中看到如下内容
Meteor/- Meteor's perl modules
- Channel.pm - A Meteor channel
- Config.pm - Meteor configuration handling
- Connection.pm - Common super-class for controller and subscriber
- Controller.pm - A Meteor controller
- Document.pm - Caching and serving mechansim for static documents
- Message.pm - Meteor message object
- Socket.pm - Meteor Socket additions
- Subscriber.pm - A Meteor subscriber
- Syslog.pm - Convenience interface to Sys::Syslog
public_html/- document root for static page serving
- poll.html - JavaScript IFRAME source for polling connections
- stream.html - JavaScript IFRAME source for streaming connections
- meteor.js - JavaScript class required for Meteor web browser client
meteord - The Meteor executable
meteor.conf.dist - Sample configuration file
daemoncontroller.dist - Meteor deamon init script shell script 二、配置
复制启动脚本meteord
cp daemoncontroller.dist /etc/init.d/meteord cp meteord.conf.dist /etc/meteord.conf
然后对这个文件进行修改
vim /etc/init.d/meteord
会看到如下内容
#!/bin/sh
# description: Runs meteord
# chkconfig: 2345 99 00
# Source function library.
. /etc/init.d/functions
case "$1" in
'start')
echo -n "Starting Meteord: "
echo 65535 > /proc/sys/fs/file-max
ulimit -n 65535
cd /usr/local/meteor
sudo -u meteor ./meteord >/var/log/meteord 2>&1 &
echo
;;
'stop')
echo -n "Stopping Meteord: "
killall meteord && success || failure
;;
'reload')
echo -n "Reloading Meteord configuration: "
killall -s SIGHUP meteord && success || failure
;;
*)
echo "Usage: $0 { start | stop | reload }"
;;
esac
exit 0修改后的文件,取消了用meteor角色来启动服务,不知道有没有什么坏处。
#!/bin/sh
# description: Runs meteord
# chkconfig: 2345 99 00
# Source function library.
#. /etc/init.d/functions
case "$1" in
'start')
echo -n "Starting Meteord: "
echo 65535 > /proc/sys/fs/file-max
ulimit -n 65535
#cd /usr/local/meteor
#su meteor
cd /usr/local/meteor/
./meteord >/var/log/meteord 2>&1 &
echo
;;
'stop')
echo -n "Stopping Meteord: "
killall meteord && success || failure
;;
'reload')
echo -n "Reloading Meteord configuration: "
killall -s SIGHUP meteord && success || failure
;;
*)
echo "Usage: $0 { start | stop | reload }"
;;
esac
exit 0这里很奇怪,必须要先cd /usr/local/meteor/ 进入文件夹,然后才启动,不然就各种错误,对perl不了解,所以不清楚是怎么回事。
然后将服务打开,启动服务器。
/sbin/chkconfig meteord on /etc/init.d/meteord start
三、测试服务连接
到这里,meteorServer这个时候已经安装好并已经启动起来了。在windows下打开cmd
telnet yourIP 4670
测试订阅服务,然后输入
GET /push/1/iframe/test HTTP/1.1
会得到如下结果
Trying yourIP...
Connected to yourIP.
Escape character is '^]'.
GET /push/1/iframe/test HTTP/1.1 <Enter>
<Enter>
HTTP/1.1 200 OK
Server: meteord
Content-Type: text/html; charset=utf-8
Pragma: no-cache
Cache-Control: no-cache, no-store, must-revalidate
Expires: Thu, 1 Jan 1970 00:00:00 GMT
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Cache-Control" content="no-store">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="Thu, 1 Jan 1970 00:00:00 GMT">
<script type="text/javascript">
window.onError = null;
var domainparts = document.domain.split(".");
document.domain = domainparts[domainparts.length-2]+"."+domainparts[domainparts.length-1];
parent.Meteor.register(this);
</script>
</head>
<body onload="try { parent.Meteor.reset(this) } catch (e) {}">
<script>ch("test", 0);</script>
<script>p(-1,"");</script>
<script>p(-1,"");</script>说明订阅服务是正常的。然后测试控制服务
telnet yourIP 4671 Trying yourIP... Connected to yourIP. Escape character is '^]'. ADDMESSAGE test hello world <enter> OK 0 <script>p(2,"test","hello world");</script>
到此,MeteorServer算是安装了大半了。
四、通过Nginx发布应用文件
我们下载的时候发布有一个public_html的文件夹,这个文件夹必须发布出去,这样前台的应用才能使用Meteor的脚本来实现功能。当然了push请求还是要转发给MeteorServer的。由于我用的是nginx,直接在配置文件nginx.conf中修改就行了。
server {
listen 80;
server_name meteor.ueder.info;
root /usr/local/meteor/public_html;
location / {
index index.html index.htm index.php;
}
location ~*^/push {
proxy_pass http://127.0.0.1:4670;
}
location ~.*\.(js|css)?$
{
expires 1d;
}
}然后nginx –s reload就生效了。至此,完成了在centos下meteorServer的安装。
安装不难,但是很折腾人。晚上回家搞一晚上,服务器启动起来了,快睡觉了,reboot,发现又没有启动成功,查看日志,尽是些perl出错的东西,把我给引到歧路上去了。希望我写的东西对您有用。
参考资料: