This is a creation in Article, where the information may have evolved or changed.
Terry-Mao/gopush-cluster
is a cluster-enabled Comet service (support WebSocket, and TCP protocol).
Characteristics
- Lightweight
- Performance
- Pure Golang Implementation
- Support Message Expiration
- Support for offline message storage
- Supports single and multiple private messaging push
- Support for multiple subscribers of a single key (maximum number of subscribers can be limited)
- Heartbeat Support (app Heartbeat and TCP keepalive)
- Support for secure authentication (unauthorized users cannot subscribe)
- Multi-protocol support (WEBSOCKET,TCP)
- Detailed statistical information
- Topology-capable architecture (support for adding and removing comet nodes, Web nodes, message nodes)
- Support Failover with zookeeper
Installation (version 1.0.5)
First, installation dependent
?
12 |
$ yum -y install java-1.7.0-openjdk $ yum -y install gcc-c++ |
Second, build zookeeper
1. Create a new directory
?
123 |
$ mkdir -p /data/apps $ mkdir -p /data/logs/gopush-cluster $ mkdir -p /data/programfiles |
2. Download zookeeper, recommended download 3.4.5 or later
?
123 |
$ cd /data/programfiles $ wget http: //mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz $ tar -xvf zookeeper-3.4.5.tar.gz -C ./ |
3. Start Zookeeper (Zookeeper cluster configuration is not detailed here, if there are more than one machine, it is recommended to do the cluster)
?
123 |
$ cp /data/programfiles/zookeeper-3.4.5/conf/zoo_sample.cfg /data/programfiles/zookeeper-3.4.5/conf/zoo.cfg $ cd /data/programfiles/zookeeper-3.4.5/bin $ ./zkServer.sh start |
Third, build Redis
?
1234567891011 |
$ cd/data/programfiles $ wget http: //download.redis.io/releases/redis-2.8.17.tar.gz $ TAR-XVF Redis-2.8.17.tar.gz-c./ $ CD redis-2.8.17/src $ make $ make test $ make install $ Mkdir/etc/redis $ cp/data/programfiles/redis-2.8.17/redis.conf/etc/redis/ $ Cp/data/programfiles/redis-2.8.17/src/redis-server/etc/init.d/redis-server Code class= "CPP Plain" >$/etc/init.d/redis-server/etc/redis/redis.conf |
- Install tcl8.5 If the error is as follows (reference 2)
?
12345 |
which: no tclsh8.5 in (/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/geffzhang/bin) You need 'tclsh8.5' in order to run the Redis test Make[1]: *** [test] error 1 make[1]: Leaving directory ‘/data/program files/redis-2.6.4/src’ Make: *** [test] error 2! |
Iv. Install the Git tool (you can skip this step if it is already installed)
Reference: Git
Yum-y Install git
V. Building Golang Environment
1. Download the source code (download the corresponding installation package according to your own system)
?
123 |
$ cd /data/programfiles $ wget -c --no-check-certificate https: //go.googlecode.com/files/go1.3.linux-amd64.tar.gz $ tar -xvf go1.3.linux-amd64.tar.gz -C /usr/local |
2. Configure the GO environment variable (here I add in/etc/profile.d/golang.sh)
?
123456 |
$ vim /etc/profile.d/golang.sh # 将以下环境变量添加到profile最后面 export GOROOT=/usr/local/go export PATH=$PATH:$GOROOT/bin export GOPATH=/data/apps/go $ source /etc/profile |
Vi. Deployment of Gopush-cluster
1. Download Gopush-cluster and dependent packages
./dependencies.sh
2. Install message, comet, Web module (configuration file according to actual machine environment configuration)
?
123456789101112 |
$ CD $GOPATH/src/github.com/terry-mao/gopush-cluster/message Code class= "CPP Plain" >$ go install $ CP message-example.conf $GOPATH/bin/message.conf< /code>$ cp log .xml $GOPATH/bin/message_log.xml $ CD. /comet/ $ go install $ CP comet-example.conf $GOPATH/ bin/comet.conf $ cp log .xml $GOPATH/bin/comet_log.xml $ CD. /web/ $ go install $ CP web-example.conf $GOPATH/bin/ web.conf $ cp log .xml $GOPATH/bin/web_log.xml |
All of these environments are built to complete!
Seven, start Gopush-cluster
?
1234 |
$ cd /$GOPATH/bin $ nohup $GOPATH/bin/message -c $GOPATH/bin/message.conf 2>&1 >> /data/logs/gopush-cluster/panic-message. log & $ nohup $GOPATH/bin/comet -c $GOPATH/bin/comet.conf 2>&1 >> /data/logs/gopush-cluster/panic-comet. log & $ nohup $GOPATH/bin/web -c $GOPATH/bin/web.conf 2>&1 >> /data/logs/gopush-cluster/panic-web. log & |
Eight, testing
1. Push individual private messages (example: message expiration is expire=600 seconds)
?
1 |
$ curl -d "{\"test\":1}" http: //localhost:8091/1/admin/push/private?key=Terry-Mao\&expire=600 |
Successful return:{"ret":0}
2. Bulk Push private messages
?
1 |
$ curl -d "{\"m\":\"{\\\"test\\\":1}\",\"k\":\"t1,t2,t3\"}" http: //localhost:8091/1/admin/push/mprivate?expire=600 |
Successful return:{"data":{"fk":["t1","t2"]},"ret":0}
The field m
is the message body, which k
is the subscription key to bulk push, with each key ,
split.
?
12 |
注:1)新版推送的消息内容必须是json格式,否则获取消息时会报错. 2)批量推送正常情况下是没有`fk`字段的,如果有部分推送失败则返回`fk`,结构为字符串数组. |
3. Get the Offline messaging interface
Open in Browser:
http :// localhost : 8090 / 1 /msg/get?k = Terry - Mao & m = 0
Successful return:
?
12345678 |
{
"data"
:{
"msgs"
:[
{
"msg"
:{
"test"
:1},
"mid"
:13996474938346192,
"gid"
:0}
]
},
"ret"
:0
}
|
4. Get the Node interface
Open in Browser:
http :// localhost : 8090 / 1 /server/get?k = Terry - Mao & P = 2
Successful return:
?
123456 |
{ "data" :{ "server" : "localhost:6969" }, "ret" :0 } |
Ix. attached information
1. Download and install HG
?
12345 |
$ wget http: //mercurial .selenic.com / Release/mercurial-1 .4.1. tar .gz $ tar -xvf mercurial-1.4.1. tar .gz $ cd mercurial-1.4.1 $ make $ make install |
- If the installation prompt cannot find the file ' Python.h ' then you need to install Python-devel
Yum-y Install Python-devel
- If error: couldn ' t find libraries, add environment variable
PYTHONPATH =/usr/local/lib64/python2.6/site-packages
2. Installing tcl8.5
?
12345678 |
$
cd /data/programfiles
$ wget http:
//downloads
.sourceforge.net
/tcl/tcl8
.5.10-src.
tar
.gz
$
tar
-xvf tcl8.5.10-src.
tar
.gz -C ./
$
cd
tcl8.5.10
$
cd
unix
$ .
/configure
$
make
$
make
install
|