美文网首页消息中间件
【ActiveMQ】安装

【ActiveMQ】安装

作者: 佐蓝Gogoing | 来源:发表于2019-06-23 14:18 被阅读0次

    1. 下载安装

    下载:官网下载

    将压缩文件放到 Centos 中
    解压:tar -zxvf apache-activemq-5.15.9-bin.tar.gz -C /var
    改名:mv /var/apache-activemq-5.15.9/ /var/activemq/

    切换目录:cd /var/activemq/

    启动:./bin/activemq start

    [root@localhost activemq]# ./bin/activemq start
    INFO: Loading '/var/activemq//bin/env'
    INFO: Using java '/usr/java/jdk1.8.0_211/bin/java'
    INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
    INFO: pidfile created : '/var/activemq//data/activemq.pid' (pid '4823')
    

    停止./bin/activemq stop

    [root@localhost activemq]# ./bin/activemq stop
    INFO: Loading '/var/activemq//bin/env'
    INFO: Using java '/usr/java/jdk1.8.0_211/bin/java'
    INFO: Waiting at least 30 seconds for regular process termination of pid '4823' : 
    Java Runtime: Oracle Corporation 1.8.0_211 /usr/java/jdk1.8.0_211/jre
      Heap sizes: current=63360k  free=62303k  max=1013632k
        JVM args: -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config=/var/activemq//conf/login.config -Dactivemq.classpath=/var/activemq//conf:/var/activemq//../lib/: -Dactivemq.home=/var/activemq/ -Dactivemq.base=/var/activemq/ -Dactivemq.conf=/var/activemq//conf -Dactivemq.data=/var/activemq//data
    Extensions classpath:
      [/var/activemq/lib,/var/activemq/lib/camel,/var/activemq/lib/optional,/var/activemq/lib/web,/var/activemq/lib/extra]
    ACTIVEMQ_HOME: /var/activemq
    ACTIVEMQ_BASE: /var/activemq
    ACTIVEMQ_CONF: /var/activemq/conf
    ACTIVEMQ_DATA: /var/activemq/data
    Connecting to pid: 4823
    Stopping broker: localhost
    . TERMINATED
    

    2. 创建服务

    2.1 创建一个 systemd 服务文件
    vi /usr/lib/systemd/system/activemq.service
    

    放入内容

    [Unit]
    Description=ActiveMQ service
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/var/activemq/bin/activemq start
    ExecStop=/var/activemq/bin/activemq stop
    User=root
    Group=root
    Restart=always
    RestartSec=9
    StandardOutput=syslog
    StandardError=syslog
    SyslogIdentifier=activemq
    
    [Install]
    WantedBy=multi-user.target
    

    加载服务:systemctl daemon-reload

    2.2 修改 ActiveMQ 配置

    找到 Java 目录:whereis java

    [root@localhost activemq]# whereis java
    java: /usr/java/jdk1.8.0_211/bin/java
    

    设置 activemq 配置文件 /var/activemq/bin/env 中的 JAVA_HOME

    # 注意 JAVA_HOME 前面的 # 要去掉
    JAVA_HOME="/usr/java/jdk1.8.0_211"
    JAVACMD="auto"
    
    2.3 通过 systemctl 管理 ActiveMQ 启停

    启动 activemq 服务: systemctl start activemq
    查看服务状态: systemctl status activemq

    [root@localhost bin]# systemctl status activemq
    ● activemq.service - ActiveMQ service
       Loaded: loaded (/usr/lib/systemd/system/activemq.service; enabled; vendor preset: disabled)
       Active: active (running) since Sun 2019-06-23 14:07:25 CST; 1min 59s ago
      Process: 4989 ExecStart=/var/activemq/bin/activemq start (code=exited, status=0/SUCCESS)
     Main PID: 5039 (java)
       CGroup: /system.slice/activemq.service
               └─5039 /usr/java/jdk1.8.0_211/bin/java -Xms64M -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.security.auth.login.config...
    
    Jun 23 14:07:25 localhost.localdomain systemd[1]: Starting ActiveMQ service...
    Jun 23 14:07:25 localhost.localdomain activemq[4989]: INFO: Loading '/var/activemq//bin/env'
    Jun 23 14:07:25 localhost.localdomain activemq[4989]: INFO: Using java '/usr/java/jdk1.8.0_211/bin/java'
    Jun 23 14:07:25 localhost.localdomain activemq[4989]: INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties t...details
    Jun 23 14:07:25 localhost.localdomain activemq[4989]: INFO: pidfile created : '/var/activemq//data/activemq.pid' (pid '5039')
    Jun 23 14:07:25 localhost.localdomain systemd[1]: Started ActiveMQ service.
    Hint: Some lines were ellipsized, use -l to show in full.
    

    创建软链接:ln -s /usr/lib/systemd/system/activemq.service /etc/systemd/system/multi-user.target.wants/activemq.service

    开启开机自启:systemctl enable activemq
    检测是否开启成功(enable): systemctl list-unit-files |grep activemq

    [root@localhost bin]# systemctl list-unit-files |grep activemq
    activemq.service                              enabled 
    

    3. 防火墙配置

    Web管理端口默认为8161(admin/admin),通讯端口默认为61616

    添加并重启防火墙

    firewall-cmd --zone=public --add-port=8161/tcp --permanent
    firewall-cmd --zone=public --add-port=61616/tcp --permanent
    systemctl restart firewalld.service
    

    或者直接关闭防火墙: systemctl stop firewalld.service

    4. web管理系统配置

    4.1 端口和登陆

    配置文件:/home/activemq/apache-activemq-5.15.9/conf/jetty.xml
    端口修改

    <bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" 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>
    

    关闭登陆

    <bean id="securityConstraint" class="org.eclipse.jetty.util.security.Constraint">
      <property name="name" value="BASIC" />
      <property name="roles" value="user,admin" />
      <!-- 改为false即可关闭登陆 -->
      <property name="authenticate" value="true" />
    </bean>
    
    4.2 登陆账号

    配置文件:/home/activemq/apache-activemq-5.15.9/conf/jetty-realm.properties
    账号修改

    # 在此即可维护账号密码,格式:
    # 用户名:密码,角色
    # Defines users that can access the web (console, demo, etc.)
    # username: password [,rolename ...]
    admin: admin, admin
    user: 123, user
    

    截个图

    相关文章

      网友评论

        本文标题:【ActiveMQ】安装

        本文链接:https://www.haomeiwen.com/subject/ptbiqctx.html