zl程序教程

您现在的位置是:首页 >  其他

当前栏目

分布式架构实战--ActiveMQ的安装与使用(单节点)

2023-09-27 14:20:44 时间

 

2、  下载Linux版的ActiveMQ(当前最新版apache-activemq-5.11.1-bin.tar.gz)

$ wget http://apache.fayea.com/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz

 

3、  解压安装

$ tar -zxvf apache-activemq-5.11.1-bin.tar.gz

$ mv apache-activemq-5.11.1 activemq-01

如果启动脚本activemq没有可执行权限,此时则需要授权(此步可选)

$ cd /home/wusc/activemq-01/bin/

$ chmod 755 ./activemq

 

4、  防火墙中打开对应的端口

ActiveMQ需要用到两个端口

一个是消息通讯的端口(默认为61616)

一个是管理控制台端口(默认为8161)可在conf/jetty.xml中修改,如下:

bean id="jettyPort" init-method="start"

  !-- the default port number for the web console --

  property name="host" value="0.0.0.0"/

  property name="port" value="8161"/

/bean

 

# vi /etc/sysconfig/iptables

添加:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 61616 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8161 -j ACCEPT

重启防火墙:

# service iptables restart

 

5、  启动

$ cd /home/wusc/activemq-01/bin

$ ./activemq start

 

6、  打开管理界面:http://192.168.4.101:8161


m8Fc5Psarwhn2GJTj6Ae2atR3JKzyyj7.png


3mh7nHzCK4MCTaQh2B5y7mrrwp4dCKjy.png


默认用户名和密码为:admin/admin

 

登录后进入

fZ7djQYF28xn46FHScwYMAsRCzFHmpRh.png


7、  安全配置(消息安全)

ActiveMQ如果不加入安全机制的话,任何人只要知道消息服务的具体地址(包括ip,端口,消息地址[队列或者主题地址],),都可以肆无忌惮的发送、接收消息。关于ActiveMQ安装配置http://activemq.apache.org/security.html

 

ActiveMQ的消息安全配置策略有多种,我们以简单授权配置为例:

在conf/activemq.xml文件中在broker标签最后加入以下内容即可:

$ vi /home/wusc/activemq-01/conf/activemq.xml

plugins

     simpleAuthenticationPlugin

     users

         authenticationUser username="wusc" password="wusc.123" groups="users,admins"/

     /users

     /simpleAuthenticationPlugin

/plugins

定义了一个wusc用户,密码为wusc.123,角色为users,admins

 

设置admin的用户名和密码:

$ vi /home/wusc/activemq-01/conf/jetty.xml

bean id="securityConstraint"

    property name="name" value="BASIC" /

    property name="roles" value="admin" /

    property name="authenticate" value="true" /

/bean

确保authenticate的值为true(默认)

 

控制台的登录用户名密码保存在conf/jetty-realm.properties文件中,内容如下:

$ vi /home/wusc/activemq-01/conf/jetty-realm.properties

# Defines users that can access the web (console, demo, etc.)

# username: password [,rolename ...]

admin: wusc.123, admin

 

注意:用户名和密码的格式是

用户名 : 密码 ,角色名

 

重启:

$ /home/wusc/activemq-01/bin/activemq restart

 

设置开机启动:

# vi /etc/rc.local

加入以下内容

## ActiveMQ

su - wusc -c /home/wusc/activemq-01/bin/activemq start

 

8、  MQ消息生产者也与消息消费者的Demo样例讲解与演示


参考内容 http://www.roncoo.com/course/view/85d6008fe77c4199b0cdd2885eaeee53


22-微服务技术栈(高级):分布式缓存Redis主从集群 单机Redis可以解决应用缓存的问题,但是随着系统流量的增加,读操作开始指数级倍增时,及时单节点Redis基于内存的读写操作再快也会有性能瓶颈,此时我们可以借助主从架构(主负责写、从负责读)来优化上述场景,实现高并发读优化。