ps: Since there are two copies of the source code on github and code cloud, the latest code is mainly on github.
git clone https://github.com/mpusher/mpush.git
mpush-test
module, all test codes are under this modulesrc/test/resource/application.conf
file. Please refer to point 6 of service deployment for the modification method.com.mpush.test.sever.ServerTestMain.java
to start the long link servicecom.mpush.test.client.ConnClientTestMain.java
to simulate a clientcom.mpush.test.push.PushClientTestMain
to simulate sending messages to users Install jdk 1.8
or above and set %JAVA_HOME%
Install zookeeper
(the installation and configuration steps are omitted)
Install Redis
(installation and configuration steps omitted)
Download the latest official package of mpush server https://github.com/mpusher/mpush/releases
Unzip the downloaded tar package tar -zvxf mpush-release-0.0.2.tar.gz
to the mpush directory. The structure is as follows
drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:30 bin —> startup script drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:52 conf —> configuration file drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:29 lib —> Core class library-rw-rw-r-- 1 shinemo shinemo 11357 May 31 11:07 LICENSE drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:32 logs —> log directory-rw-rw-r-- 1 shinemo shinemo 21 May 31 11:07 README.md drwxrwxr-x 2 shinemo shinemo 4096 Aug 20 09:52 tmp
Modify the vi mpush.conf
file in the conf directory. The configuration items in mpush.conf
will overwrite the reference.conf
file in the same directory.
#主要修改以下配置
mp . net . connect - server - port = 3000 //长链接服务对外端口, 公网端口
mp . zk . server - address = "127.0.0.1:2181" //zk 机器的地址
mp . redis ={ //redis 相关配置
nodes :[ "127.0.0.1:6379" ] //格式是ip:port
cluster - model : single //single, cluster
}
//还有用于安全加密的RSA mp.security.private-key 和 mp.security.public-key 等...
If you want to modify other configurations, please refer to the reference.conf file.
Add execution permissions to the script in the bin directory chmod u+x *.sh
Execute ./mp.sh start
to start the service and view the help ./mp.sh
currently supports commands:
Usage: ./mp.sh {start|start-foreground|stop|restart|status|upgrade|print-cmd}
set-env.sh
is used to add and modify jvm startup parameters, such as heap memory, open remote debugging port, open jmx, etc.
cd logs
directory, cat mpush.out
to check whether the service started successfully
Integrated deployment, such as integrating into existing web projects and deploying to tomcat, you can add the following dependencies
< dependency >
< groupId >com.github.mpusher</ groupId >
< artifactId >mpush-boot</ artifactId >
< version >0.0.2</ version >
</ dependency >
Startup entry com.mpush.bootstrap.ServerLauncher.java
##################################################################################################################
#
# NOTICE :
#
# 系统配置文件,所有列出的项是系统所支持全部配置项
# 如果要覆盖某项的值可以添加到mpush . conf中。
#
# 配置文件格式采用HOCON格式。解析库由https : //github.com/typesafehub/config提供。
# 具体可参照说明文档,比如含有特殊字符的字符串必须用双引号包起来。
#
##################################################################################################################
mp {
#基础配置
home = $ { user . dir } //程序工作目录
#日志配置
log - level = warn
log - dir = $ { mp . home }/ logs
log - conf - path = $ { mp . home }/ conf / logback . xml
#核心配置
core {
max - packet - size = 10 k //系统允许传输的最大包的大小
compress - threshold = 10 k //数据包启用压缩的临界值,超过该值后对数据进行压缩
min - heartbeat = 3 m //最小心跳间隔
max - heartbeat = 3 m //最大心跳间隔
max - hb - timeout - times = 2 //允许的心跳连续超时的最大次数
session - expired - time = 1d //用于快速重连的session 过期时间默认1天
epoll - provider = netty //nio:jdk自带,netty:由netty实现
}
#安全配置
security {
# rsa 私钥、公钥key长度为1024 ;可以使用脚本bin / rsa . sh生成, @ see com . mpush . tools . crypto . RSAUtils # main
private - key = "MIIBNgIBADANBgkqhkiG9w0BAQEFAASCASAwggEcAgEAAoGBAKCE8JYKhsbydMPbiO7BJVq1pbuJWJHFxOR7L8Hv3ZVkSG4eNC8DdwAmDHYu/wadfw0ihKFm2gKDcLHp5yz5UQ8PZ8FyDYvgkrvGV0ak4nc40QDJWws621dm01e/INlGKOIStAAsxOityCLv0zm5Vf3+My/YaBvZcB5mGUsPbx8fAgEAAoGAAy0+WanRqwRHXUzt89OsupPXuNNqBlCEqgTqGAt4Nimq6Ur9u2R1KXKXUotxjp71Ubw6JbuUWvJg+5Rmd9RjT0HOUEQF3rvzEepKtaraPhV5ejEIrB+nJWNfGye4yzLdfEXJBGUQzrG+wNe13izfRNXI4dN/6Q5npzqaqv0E1CkCAQACAQACAQACAQACAQA="
public - key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCghPCWCobG8nTD24juwSVataW7iViRxcTkey/B792VZEhuHjQvA3cAJgx2Lv8GnX8NIoShZtoCg3Cx6ecs+VEPD2fBcg2L4JK7xldGpOJ3ONEAyVsLOttXZtNXvyDZRijiErQALMTorcgi79M5uVX9/jMv2Ggb2XAeZhlLD28fHwIDAQAB"
aes - key - length = 16 //AES key 长度
}
#网络配置
net {
local - ip = "" //本地ip, 默认取第一个网卡的本地IP
public - ip = "" //外网ip, 默认取第一个网卡的外网IP
connect - server - bind - ip = "" //connSrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0)
connect - server - register - ip = $ { mp . net . public - ip } //公网ip, 注册到zk中的ip, 默认是public-ip
connect - server - port = 3000 //长链接服务对外端口, 公网端口
connect - server - register - attr { //注册到zk里的额外属性,比如配置权重,可在alloc里排序
weight : 1
}
gateway - server - bind - ip = "" //gatewaySrv 绑定的本地ip (默认anyLocalAddress 0.0.0.0 or ::0)
gateway - server - register - ip = $ { mp . net . local - ip } //本地ip, 注册到zk中的ip, 默认是local-ip
gateway - server - port = 3001 //网关服务端口, 内部端口
gateway - server - net = tcp //网关服务使用的网络类型tcp/udp/sctp/udt
gateway - client - port = 4000 //UDP 客户端端口
gateway - server - multicast = "239.239.239.88" //239.0.0.0~239.255.255.255为本地管理组播地址,仅在特定的本地范围内有效
gateway - client - multicast = "239.239.239.99" //239.0.0.0~239.255.255.255为本地管理组播地址,仅在特定的本地范围内有效
gateway - client - num = 1 //网关客户端连接数
admin - server - port = 3002 //控制台服务端口, 内部端口
ws - server - port = 0 //websocket对外端口, 公网端口, 0表示禁用websocket
ws - path = "/" //websocket path
public - host - mapping { //本机局域网IP和公网IP的映射关系, 该配置后续会被废弃
//"10.0.10.156":"111.1.32.137"
//"10.0.10.166":"111.1.33.138"
}
snd_buf { //tcp/udp 发送缓冲区大小
connect - server = 32 k
gateway - server = 0
gateway - client = 0 //0表示使用操作系统默认值
}
rcv_buf { //tcp/udp 接收缓冲区大小
connect - server = 32 k
gateway - server = 0
gateway - client = 0 //0表示使用操作系统默认值
}
write - buffer - water - mark { //netty 写保护
connect - server - low = 32 k
connect - server - high = 64 k
gateway - server - low = 10 m
gateway - server - high = 20 m
}
traffic - shaping { //流量整形配置
gateway - client {
enabled : false
check - interval : 100 ms
write - global - limit : 30 k
read - global - limit : 0
write - channel - limit : 3 k
read - channel - limit : 0
}
gateway - server {
enabled : false
check - interval : 100 ms
write - global - limit : 0
read - global - limit : 30 k
write - channel - limit : 0
read - channel - limit : 3 k
}
connect - server {
enabled : false
check - interval : 100 ms
write - global - limit : 0
read - global - limit : 100 k
write - channel - limit : 3 k
read - channel - limit : 3 k
}
}
}
# Zookeeper配置
zk {
server - address = "127.0.0.1:2181" //多台机器使用","分隔如:"10.0.10.44:2181,10.0.10.49:2181" @see org.apache.zookeeper.ZooKeeper#ZooKeeper()
namespace = mpush
digest = mpush //zkCli.sh acl 命令 addauth digest mpush
watch - path =/
retry {
# initial amount of time to wait between retries
baseSleepTimeMs = 3 s
# max number of times to retry
maxRetries = 3
# max time in ms to sleep on each retry
maxSleepMs = 5 s
}
connectionTimeoutMs = 5 s
sessionTimeoutMs = 5 s
}
# Redis集群配置
redis {
cluster - model = single //single,cluster,sentinel
sentinel - master :""
nodes :[] s //["127.0.0.1:6379"]格式ip:port
password ="" //your password
config {
maxTotal : 8 ,
maxIdle : 4 ,
minIdle : 1 ,
lifo : true ,
fairness : false ,
maxWaitMillis : 5000 ,
minEvictableIdleTimeMillis : 300000 ,
softMinEvictableIdleTimeMillis : 1800000 ,
numTestsPerEvictionRun : 3 ,
testOnCreate : false ,
testOnBorrow : false ,
testOnReturn : false ,
testWhileIdle : false ,
timeBetweenEvictionRunsMillis : 60000 ,
blockWhenExhausted : true ,
jmxEnabled : false ,
jmxNamePrefix : pool ,
jmxNameBase : pool
}
}
# HTTP代理配置
http {
proxy - enabled = false //启用Http代理
max - conn - per - host = 5 //每个域名的最大链接数, 建议web服务nginx超时时间设长一点, 以便保持长链接
default - read - timeout = 10 s //请求超时时间
max - content - length = 5 m //response body 最大大小
dns - mapping { //域名映射外网地址转内部IP, 域名部分不包含端口号
//"mpush.com":["127.0.0.1:8080", "127.0.0.1:8081"]
}
}
#线程池配置
thread {
pool {
conn - work : 0 //接入服务线程池大小,0表示线程数根据cpu核数动态调整(2*cpu)
gateway - server - work : 0 //网关服务线程池大小,0表示线程数根据cpu核数动态调整(2*cpu)
http - work : 0 //http proxy netty client work pool size,0表示线程数根据cpu核数动态调整(2*cpu)
ack - timer : 1 //处理ACK消息超时
push - task : 0 //消息推送中心,推送任务线程池大小, 如果为0表示使用Gateway Server的work线程池,tcp下推荐0
gateway - client - work : 0 //网关客户端线程池大小,0表示线程数根据cpu核数动态调整(2*cpu),该线程池在客户端运行
push - client : 2 //消息推送回调处理,该线程池在客户端运行
event - bus { //用户处理内部事件分发
min : 1
max : 16
queue - size : 10000 //大量的online,offline
}
mq { //用户上下线消息, 踢人等
min : 1
max : 4
queue - size : 10000
}
}
}
#推送消息流控
push {
flow - control { //qps = limit/(duration)
global :{ //针对非广播推送的流控,全局有效
limit : 5000 //qps = 5000
max : 0 //UN limit
duration : 1 s //1s
}
broadcast :{ //针对广播消息的流控,单次任务有效
limit : 3000 //qps = 3000
max : 100000 //10w
duration : 1 s //1s
}
}
}
#系统监控配置
monitor {
dump - dir = $ { mp . home }/ tmp
dump - stack = false //是否定时dump堆栈
dump - period = 1 m //多久监控一次
print - log = true //是否打印监控日志
profile - enabled = false //开启性能监控
profile - slowly - duration = 10 ms //耗时超过10ms打印日志
}
# SPI扩展配置
spi {
thread - pool - factory : "com.mpush.tools.thread.pool.DefaultThreadPoolFactory"
dns - mapping - manager : "com.mpush.common.net.HttpProxyDnsMappingManager"
}
}