潍坊建站程序,网络广告营销方案策划,北京建站哪家好,娃哈哈网站建设策划书文章目录 配置wrapper相关配置wrapper是干什么用的MQ的运行内存修改【需修改】修改内容题外话 wrapper.log配置【需修改】引起的问题优化方式 activemq.xml相关配置官网介绍配置管理后台的认证授权【建议修改】配置broker【根据自己需求更改】配置允许jmx监控关闭消息通知持久化… 文章目录 配置wrapper相关配置wrapper是干什么用的MQ的运行内存修改【需修改】修改内容题外话 wrapper.log配置【需修改】引起的问题优化方式 activemq.xml相关配置官网介绍配置管理后台的认证授权【建议修改】配置broker【根据自己需求更改】配置允许jmx监控关闭消息通知持久化发布订阅模式topic管理删除过期的消息删除已经不活跃额订阅者 队列模式queue管理配置参数 认证授权明文配置方式activemq.xml中的配置代码中的配置 加密配置方式 统一配置时间死信队列抛弃策略死信队列是什么呢配置方式 持久化配置kahaDB配置 存储空间设置 kahaDB日志【测试时才用测试环境和生产环境不能配置】 示例配置activemq.xml 原文件activemq.xml 配置
wrapper相关配置
wrapper是干什么用的
ActiveMQ官网上是这么写的(戳此跳转到官网页面) ActiveMQ uses the Java Service Wrapper to run the broker. To configure how the Java Service Wrapper starts up, you can edit the wrapper.conf located in the bin/win32, bin/linux, or bin/macosx depending on which system you are running it. For more information on the different properties of the Java Service Wrapper, refer to this page wrapper是个将java打包成windows或者unix的服务的一个工具。它同时还为应用程序提供日记功能灵活的配置可靠的运行性能按需求重新启动简化应用程序的安装等。
MQ的运行内存修改【需修改】
修改内容
当你下载MQ并解压之后你会发现文件夹如下所示下图中上面为macox、linux版下图为windows版 修改内存可通过修改wrapper.conf文件中的如下命令。 注意此处是通过什么方式启动就修改哪个文件夹的wrapper.conf啊比如你是win64启动方式就改win64文件夹下的.conf并且你运行的时候也是用win64文件夹下的activemq.bat哈 # Initial Java Heap Size (in MB)
# 等同于xms
wrapper.java.initmemory1024# Maximum Java Heap Size (in MB)
# 等同于xmx
wrapper.java.maxmemory1024题外话
在研究的过程中发现了一个很有意思的东西在此赘述下。
在bin文件夹下的activemqunix可执行文件的源代码中发现了一个备注
# System variables for this script, like ACTIVEMQ_OPTS and ACTIVEMQ_OPTS_MEMORY,
# can be configured in env script located in this directory.并且在activemqunix可执行文件中也能看到代码为
if [ -z $ACTIVEMQ_OPTS ] ; thenACTIVEMQ_OPTS$ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.filelogging.properties -Djava.security.auth.login.config$ACTIVEMQ_CONF/login.config
fi然后编辑env文件windows版没有该文件其中有一段代码如下
if [ -z $ACTIVEMQ_OPTS_MEMORY ] ; thenACTIVEMQ_OPTS_MEMORY-Xms64M -Xmx1G
fi
if [ -z $ACTIVEMQ_OPTS ] ; thenACTIVEMQ_OPTS$ACTIVEMQ_OPTS_MEMORY -Djava.util.logging.config.filelogging.properties -Djava.security.auth.login.config$ACTIVEMQ_CONF/login.config
fiif [ -z $ACTIVEMQ_OUT ]; thenACTIVEMQ_OUT/dev/null
fi也就是说在此处也可以进行配置经过测试发现如果会用bin目录下的activemq进行启动当然此处window没法用这个启动就会使用到这个内存修改参数。 如果此文件修改了使用的bin/xxx/下的activemq最终wrapper会覆盖掉这个文件夹下的参数 如果此文件修改了使用的bin下的activemq最终使用的是env下的参数
下图为使用单独文件夹下的activemq启动如图所示 下图为使用bin目录下的activemq启动如图所示 两者启动的形成的命令行如下在macos上其余系统未尝试
java -Xms64M -Xmx1G -Djava.util.logging.config.filelogging.properties -Djava.security.auth.login.config/apache-activemq-5.16.6/conf/login.config -Dcom.sun.management.jmxremote -Djava.awt.headlesstrue -Djava.io.tmpdir/apache-activemq-5.16.6//tmp -Dactivemq.classpath/apache-activemq-5.16.6//conf:/apache-activemq-5.16.6//../lib/: -Dactivemq.home/apache-activemq-5.16.6/ -Dactivemq.base/apache-activemq-5.16.6/ -Dactivemq.conf/apache-activemq-5.16.6//conf -Dactivemq.data/apache-activemq-5.16.6//data -jar //apache-activemq-5.16.6//bin/activemq.jar start/apache-activemq-5.16.6/bin/macosx/wrapper /apache-activemq-5.16.6/bin/macosx/wrapper.conf wrapper.syslog.identActiveMQ wrapper.pidfile/apache-activemq-5.16.6/bin/macosx/./ActiveMQ.pid wrapper.daemonizeTRUE/usr/bin/java -Dactivemq.home../.. -Dactivemq.base../.. -Djavax.net.ssl.keyStorePasswordpassword -Djavax.net.ssl.trustStorePasswordpassword -Djavax.net.ssl.keyStore../../conf/broker.ks -Djavax.net.ssl.trustStore../../conf/broker.ts -Dcom.sun.management.jmxremote -Dorg.apache.activemq.UseDedicatedTaskRunnerfalse -Djava.util.logging.config.filelogging.properties -Dactivemq.conf../../conf -Dactivemq.data../../data -Djava.security.auth.login.config../../conf/login.config -Xms1024m -Xmx1024m -Djava.library.path../../bin/macosx/ -classpath ../../bin/wrapper.jar:../../bin/activemq.jar -Dwrapper.keyZpwQ3RjSWlo75KaJ -Dwrapper.port32000 -Dwrapper.jvm.port.min31000 -Dwrapper.jvm.port.max31999 -Dwrapper.pid87518 -Dwrapper.version3.2.3 -Dwrapper.native_librarywrapper -Dwrapper.serviceTRUE -Dwrapper.cpu.timeout10 -Dwrapper.jvmid1 org.tanukisoftware.wrapper.WrapperSimpleApp org.apache.activemq.console.Main start从启动命令能大概看出来使用wrapper的方式启动能覆盖到直接用unix执行命令启动
wrapper.log配置【需修改】
引起的问题
ActiveMQ服务器data目录下wrapper.log文件默认产生的日志是不覆盖的文件的大小逐渐增大。累加后会出现文件越来越大。所以建议此处进行优化。找到以下代码进行修改。如下面因为所示一个是最大的文件大小和最多的文件数量。
优化方式
# Maximum size that the log file will be allowed to grow to before
# the log is rolled. Size is specified in bytes. The default value
# of 0, disables log rolling. May abbreviate with the k (kb) or
# m (mb) suffix. For example: 10m 10 megabytes.
wrapper.logfile.maxsize20m# Maximum number of rolled log files which will be allowed before old
# files are deleted. The default value of 0 implies no limit.
wrapper.logfile.maxfiles100activemq.xml相关配置
官网介绍
默认的activemq.xml的原文件详见最后的源文件其相关内容的配置详见“极其复杂的官网配置页面”
配置管理后台的认证授权【建议修改】
activemq在登录管理后台的时候是会需要账号密码的。如果需要修改管理后台的登录账号密码可以修改conf/jetty-realm.properties/jetty-realm.properties文件文件内容如下
# Defines users that can access the web (console, demo, etc.)
# username: password [,rolename ...]
admin: admin, admin
user: user, user修改形式为 “用户名: 密码, 角色”此处角色是怎么配置的比较复杂可以见conf/jetty-realm.properties/jetty.xml
配置broker【根据自己需求更改】
broker就相当于一个Activemq实例
配置允许jmx监控
!-- 允许使用jmx监控 --broker xmlnshttp://activemq.apache.org/schema/core brokerNamelocalhost dataDirectory${activemq.data} useJmxtrue.../broker关闭消息通知
消息通知指的是broker上的操作记录的跟踪和通知可通过配置关闭
broker xmlnshttp://activemq.apache.org/schema/core brokerNamelocalhost dataDirectory${activemq.data} advisorySupportfalse.../broker持久化发布订阅模式topic管理
按照官网的解释系统中不应该有离线的持久化订阅者这样会浪费众多资源。详见官网
所以建议配置以下参数
删除过期的消息
在对应的entry上增加expireMessagesPeriod配置比如
!-- 每5分钟检查一下所有的过期消息不配置的话默认是30秒 --
policyEntry topic expireMessagesPeriod300000/删除已经不活跃额订阅者
在broker的数据上增加以下参数
参数默认中文描述英文描述offlineDurableSubscriberTimeout-1删除多久不活跃的订阅者单位毫秒如果配置为-1则不删除Amount of time (in milliseconds) after which we remove inactive durable subs. Default -1, means don’t remove themofflineDurableSubscriberTaskSchedule300000检查的频率单位毫秒How often we check (in milliseconds)
示例
!-- 每小时检查离线1天的订阅者 --
broker namelocalhost offlineDurableSubscriberTimeout86400000 offlineDurableSubscriberTaskSchedule3600000
.....
/broker队列模式queue管理
详见官网
配置参数
参数名称描述配置数据schedulePeriodForDestinationPurge检查非活跃状态的queue间隔3600000gcInactiveDestinations声明该队列是否要被扫描到默认是falseinactiveTimeoutBeforeGC声明该队列闲置多少秒被删除默认60秒
其中上面的闲置代表“无入队记录及无有效订阅”
示例
!-- 每10秒检查一次 --
broker xmlnshttp://activemq.apache.org/schema/core schedulePeriodForDestinationPurge10000destinationPolicypolicyMappolicyEntries!-- 所有队列都被扫毛闲置30秒就被删除--policyEntry queue gcInactiveDestinationstrue inactiveTimoutBeforeGC30000//policyEntries/policyMap/destinationPolicy/broker认证授权
一个ActiveMQ不能无认证授权的暴漏在外网中如果这样会出现信息泄露的风险。所以需要对ActiveMQ的broker进行认证授权配置这样系统在连接MQ的时候就必须配置账号密码提高mq的安全。
明文配置方式
activemq.xml中的配置
在中找到标签在标签前增加以下插件配置
pluginssimpleAuthenticationPluginusersauthenticationUser username账号 password密码 groups组别//users/simpleAuthenticationPlugin
/plugins此处账号密码可以写死也可以通过加载配置文件引入常用的配置方式是使用activemq.xml里面默认引入的配置文件“credentials.properties”然后使用里面的配置的用户名和密码
比如
pluginssimpleAuthenticationPluginusersauthenticationUser username${activemq.username} password${activemq.password} groupsusers,admins/authenticationUser usernameguest password${guest.password} groupsguests//users/simpleAuthenticationPlugin
/plugins其中“credentials.properties”引入方式是通过activemq.xml里面是默认使用的
!-- Allows us to use system properties as variables in this configuration file --
bean classorg.springframework.beans.factory.config.PropertyPlaceholderConfigurerproperty namelocationsvaluefile:${activemq.conf}/credentials.properties/value/property
/bean里面的内容是:
# Defines credentials that will be used by components (like web console) to access the brokeractivemq.usernamesystem
activemq.passwordmanager
guest.passwordpassword代码中的配置
此处是以springboot为例代码中需要配置
spring:activemq:broker-url: tcp://127.0.0.1:61616user: systempassword: manager加密配置方式
具体内容详见官网页面未仔细研究大概就是使用credentials_enc.properties的内容密码形如“ENC(Cf3Jf3tMUrSOoaKU50od5CuBa8rxjoL)”如需要可以查看官网
统一配置时间
在broker中使用TimeStampPlugin插件此为一个时间戳插件官网解释为TimeStampPlugin插件
参数默认描述英文描述futureOnlyfalseWhen the plugin will never set a message’s time stamp and expiration time to a value lower than the original values. When the plugin always update a message’s time stamp and expiration time.truefalsettlCeiling0表示过期时间上限程序写的过期时间不能超过此时间超过则以此时间为准When not zero, this value (in ms) limit the expiration time.zeroExpirationOverride0表示过期时间给未分配过期时间的消息分配过期时间When not zero this value (in ms) will override the expiration time for messages that do not have an expiration already set.
也就是统一设置过期时间的上线和默认过期时间
plugins!-- 设置全局过期时间 --!-- 86,400,000 ms 1 day --timeStampingBrokerPlugin ttlCeiling1800000 zeroExpirationOverride1800000 /
/plugins死信队列抛弃策略
死信队列是什么呢
消息过期后会进入死信队列如不想抛弃死信队列默认进入ACTIVEMQ.DLQ队列且不会自动清除对于过期的消息进入死信队列还有一些可选的策略:放入各自的死信通道、保存在一个共享的队列默认且可以设置是否将过期消息放入队列的开关以及死信队列消息过期时间。
配置方式
使用discardingDLQBrokerPlugin插件官网解释为DiscardingDLQBrokerPlugin插件按照自己的需求配置一下内容即可
plugins!-- 丢弃所有死信--discardingDLQBrokerPlugindropAlltrue dropTemporaryTopicstrue dropTemporaryQueuestrue /!-- 丢弃指定死信--discardingDLQBrokerPlugindropOnlyMY.EXAMPLE.TOPIC.29 MY.EXAMPLE.QUEUE.87 reportInterval1000 /!--使用丢弃正则匹配到死信--discardingDLQBrokerPlugindropOnlyMY.EXAMPLE.TOPIC.[0-9]{3} MY.EXAMPLE.QUEUE.[0-9]{3} reportInterval3000/
/plugins持久化配置
activemq默认的持久化方式为kahaDB当然如果有特殊需求还可以配置jdbc作为持久化源。
kahaDB配置
所有参数详见官网
默认的kahaDB的配置只有存储路径
persistenceAdapterkahaDB directory${activemq.data}/kahadb/
/persistenceAdapter可以增加以下配置
persistenceAdapter!-- journalMaxFileLength产生的日志文件最大容量 --kahaDB directory${activemq.data}/kahadb journalMaxFileLength32mb/kahaDB
/persistenceAdapter存储空间设置
注意此处标签有两层不是我多写了哈
systemUsagesystemUsagememoryUsage!-- 表示ActiveMQ使用的内存 --memoryUsage percentOfJvmHeap70 //memoryUsagestoreUsage!-- 表示持久化存储文件的大小 --storeUsage limit100 gb//storeUsagetempUsage!-- 非持久化消息的临时内存大小 --tempUsage limit50 gb//tempUsage/systemUsage
/systemUsagekahaDB日志【测试时才用测试环境和生产环境不能配置】
在log4j.properties中增加以下参数便可以输出kahadb的相关日志
### 测试kahadb,增加日志
log4j.appender.kahadborg.apache.log4j.RollingFileAppender
log4j.appender.kahadb.file${activemq.base}/data/kahadb.log
log4j.appender.kahadb.maxFileSize1024KB
log4j.appender.kahadb.maxBackupIndex5
log4j.appender.kahadb.appendtrue
log4j.appender.kahadb.layoutorg.apache.log4j.PatternLayout
log4j.appender.kahadb.layout.ConversionPattern%d [%-15.15t] %-5p %-30.30c{1} - %m%n
log4j.logger.org.apache.activemq.store.kahadb.MessageDatabaseTRACE, kahadb示例配置
activemq.xml
beansxmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsdbean classorg.springframework.beans.factory.config.PropertyPlaceholderConfigurerproperty namelocationsvaluefile:${activemq.conf}/credentials.properties/value/property/beanbean idlogQuery classio.fabric8.insight.log.log4j.Log4jLogQuerylazy-initfalse scopesingletoninit-methodstart destroy-methodstop/beanbroker xmlnshttp://activemq.apache.org/schema/core brokerNamelocalhost dataDirectory${activemq.data} startfalse restartAllowedfalseschedulePeriodForDestinationPurge3600000useJmxtrue advisorySupportfalse offlineDurableSubscriberTimeout12000 offlineDurableSubscriberTaskSchedule6000 deleteAllMessagesOnStartuptruedestinationPolicypolicyMappolicyEntriespolicyEntry topic expireMessagesPeriod60000pendingMessageLimitStrategyconstantPendingMessageLimitStrategy limit1000//pendingMessageLimitStrategy/policyEntrypolicyEntry queue gcInactiveDestinationstrue inactiveTimoutBeforeGC21600000 strictOrderDispatchtrue expireMessagesPeriod60000/policyEntry/policyEntries/policyMap/destinationPolicymanagementContextmanagementContext createConnectorfalse//managementContextpersistenceAdapterkahaDB directory${activemq.data}/kahadb lockKeepAlivePeriod2000 ignoreMissingJournalfilestrue enableAckCompaction true journalMaxFileLength32mblockershared-file-locker lockAcquireSleepInterval10000 //locker/kahaDB/persistenceAdapterpluginstimeStampingBrokerPlugin ttlCeiling1800000 zeroExpirationOverride1800000 /discardingDLQBrokerPlugin dropAlltrue dropTemporaryTopicstrue dropTemporaryQueuestrue //pluginssystemUsagesystemUsagememoryUsagememoryUsage percentOfJvmHeap70 //memoryUsagestoreUsagestoreUsage limit100 gb//storeUsagetempUsagetempUsage limit50 gb//tempUsage/systemUsage/systemUsagetransportConnectorstransportConnector nameopenwire uritcp://0.0.0.0:61616?maximumConnections1000amp;wireFormat.maxFrameSize104857600/transportConnector nameamqp uriamqp://0.0.0.0:5672?maximumConnections1000amp;wireFormat.maxFrameSize104857600/transportConnector namestomp uristomp://0.0.0.0:61613?maximumConnections1000amp;wireFormat.maxFrameSize104857600/transportConnector namemqtt urimqtt://0.0.0.0:1883?maximumConnections1000amp;wireFormat.maxFrameSize104857600/transportConnector namews uriws://0.0.0.0:61614?maximumConnections1000amp;wireFormat.maxFrameSize104857600//transportConnectorsshutdownHooksbean xmlnshttp://www.springframework.org/schema/beans classorg.apache.activemq.hooks.SpringContextHook //shutdownHooks/brokerimport resourcejetty.xml//beans原文件
activemq.xml
!--Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the License); you may not use this file except in compliance withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an AS IS BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
--
!-- START SNIPPET: example --
beansxmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd!-- Allows us to use system properties as variables in this configuration file --bean classorg.springframework.beans.factory.config.PropertyPlaceholderConfigurerproperty namelocationsvaluefile:${activemq.conf}/credentials.properties/value/property/bean!-- Allows accessing the server log --bean idlogQuery classio.fabric8.insight.log.log4j.Log4jLogQuerylazy-initfalse scopesingletoninit-methodstart destroy-methodstop/bean!--The broker element is used to configure the ActiveMQ broker.--broker xmlnshttp://activemq.apache.org/schema/core brokerNamelocalhost dataDirectory${activemq.data}destinationPolicypolicyMappolicyEntriespolicyEntry topic !-- The constantPendingMessageLimitStrategy is used to preventslow topic consumers to block producers and affect other consumersby limiting the number of messages that are retainedFor more information, see:http://activemq.apache.org/slow-consumer-handling.html--pendingMessageLimitStrategyconstantPendingMessageLimitStrategy limit1000//pendingMessageLimitStrategy/policyEntry/policyEntries/policyMap/destinationPolicy!--The managementContext is used to configure how ActiveMQ is exposed inJMX. By default, ActiveMQ uses the MBean server that is started bythe JVM. For more information, see:http://activemq.apache.org/jmx.html--managementContextmanagementContext createConnectorfalse//managementContext!--Configure message persistence for the broker. The default persistencemechanism is the KahaDB store (identified by the kahaDB tag).For more information, see:http://activemq.apache.org/persistence.html--persistenceAdapterkahaDB directory${activemq.data}/kahadb//persistenceAdapter!--The systemUsage controls the maximum amount of space the broker willuse before disabling caching and/or slowing down producers. For more information, see:http://activemq.apache.org/producer-flow-control.html--systemUsagesystemUsagememoryUsagememoryUsage percentOfJvmHeap70 //memoryUsagestoreUsagestoreUsage limit100 gb//storeUsagetempUsagetempUsage limit50 gb//tempUsage/systemUsage/systemUsage!--The transport connectors expose ActiveMQ over a given protocol toclients and other brokers. For more information, see:http://activemq.apache.org/configuring-transports.html--transportConnectors!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB --transportConnector nameopenwire uritcp://0.0.0.0:61616?maximumConnections1000amp;wireFormat.maxFrameSize104857600/transportConnector nameamqp uriamqp://0.0.0.0:5672?maximumConnections1000amp;wireFormat.maxFrameSize104857600/transportConnector namestomp uristomp://0.0.0.0:61613?maximumConnections1000amp;wireFormat.maxFrameSize104857600/transportConnector namemqtt urimqtt://0.0.0.0:1883?maximumConnections1000amp;wireFormat.maxFrameSize104857600/transportConnector namews uriws://0.0.0.0:61614?maximumConnections1000amp;wireFormat.maxFrameSize104857600//transportConnectors!-- destroy the spring context on shutdown to stop jetty --shutdownHooksbean xmlnshttp://www.springframework.org/schema/beans classorg.apache.activemq.hooks.SpringContextHook //shutdownHooks/broker!--Enable web consoles, REST and Ajax APIs and demosThe web consoles requires by default login, you can disable this in the jetty.xml fileTake a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details--import resourcejetty.xml//beans
!-- END SNIPPET: example -- 天行健君子以自强不息地势坤君子以厚德载物