IT运维管理体系和规范,it运维管理系统介绍
753
2023-02-15
消息队列服务rabbitmq安装配置
一. 安装erlangRabbitmq基于erlang语言开发,因此需要安装erlang虚拟机1.通过yum安装
2.通过源码包安装
二. 安装rabbitmq1. 通过yum安装
三. 配置/usr/local/rabbitmq/sbin目录下rabbitmq-env 环境配置rabbitmq-defaults 默认参数设置rabbitmqctl 管理工具rabbitmq-plugins 插件管理工具rabbitmq-server rabbitmq服务
# vim rabbitmq-defaults
1 2 3 4 5 6 7 8 9 10 | SYS_PREFIX=${RABBITMQ_HOME} ERL_DIR=/usr/local/erlang/bin///设置erl命令路径 CLEAN_BOOT_FILE=start_clean SASL_BOOT_FILE=start_sasl CONFIG_FILE=${SYS_PREFIX}/etc/rabbitmq/rabbitmq//设置rabbitmq运行参数 LOG_BASE=${SYS_PREFIX}/var/log/rabbitmq MNESIA_BASE=${SYS_PREFIX}/var/lib/rabbitmq/mnesia ENABLED_PLUGINS_FILE=${SYS_PREFIX}/etc/rabbitmq/enabled_plugins//允许插件列表配置文件 PLUGINS_DIR="${RABBITMQ_HOME}/plugins" CONF_ENV_FILE=${SYS_PREFIX}/etc/rabbitmq/rabbitmq-env.conf |
主要配置文件1. enabled_plugins:设置允许的插件列表,格式如下:
1 2 3 4 5 | [rabbitmq_jsonrpc_channel, rabbitmq_jsonrpc_channel_examples, rabbitmq_management, rabbitmq_management_visualiser, rabbitmq_tracing]. |
2. rabbitmq.config:设置rabbitmq运行参数。结构为hash数组格式。如
1 2 3 4 5 6 7 8 9 | [ {mnesia,[{dump_log_write_threshold,1000}]}, {rabbit,[{vm_memory_high_watermark,0.4}]} {rabbitmq_management, [{listener,[{port,55673}, {ip,"0.0.0.0"} ]} ]} ]. |
1 2 3 4 5 6 | RABBITMQ_NODENAME=FZTEC-240088节点名称 RABBITMQ_NODE_IP_ADDRESS=127.0.0.1监听IP RABBITMQ_NODE_PORT=5672监听端口 RABBITMQ_LOG_BASE=/data/rabbitmq/log日志目录 RABBITMQ_PLUGINS_DIR=/data/rabbitmq/plugins插件目录 RABBITMQ_MNESIA_BASE=/data/rabbitmq/mnesia后端存储目录 |
4. 启动
1 | # /usr/local/rabbitmq/sbin/rabbitmq-server -detached |
四. rabbitmq插件管理启用rabbitmq web管理插件
1 | # ./rabbitmq-plugins enable rabbitmq_management |
列出所有插件
1 | # ./rabbitmq-plugins list |
六. php操作实例1. 创建队列
2. 获取队列信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <?php //连接RabbitMQ $conn_args=array('host'=>'10.31.247.202','port'=>'5672','login'=>'guest','password'=>'guest','vhost'=>'/'); $conn=newAMQPConnection($conn_args); $conn->connect(); //设置queue名称,使用exchange,绑定routingkey $channel=newAMQPChannel($conn); $q=newAMQPQueue($channel); $q->setName('_queue'); $q->setFlags(AMQP_DURABLE|AMQP_AUTODELETE); $q->declare(); $q->bind('_exchange','_routingkey'); //消息获取 $messages=$q->get(AMQP_AUTOACK); if($messages){ var_dump(json_decode($messages->getBody(),true)); } $conn->disconnect(); ?> |
执行后输出信息如下:array(2) {[0]=>string(12) "Hello World!"[1]=>string(6) "DIRECT"}
七. 查看队列信息1. 查看exchange信息
1 2 3 4 5 6 7 8 9 10 11 12 | # /usr/local/rabbitmq/sbin/rabbitmqctl list_exchanges name type durable auto_delete arguments Listing exchanges... direct truefalse[] amq.direct direct truefalse[] amq.fanout fanout truefalse[] amq.headers headers truefalse[] amq.match headers truefalse[] amq.rabbitmq.log topic truefalse[] amq.rabbitmq.trace topic truefalse[] amq.topic topic truefalse[] _exchange direct truefalse[] ...done. |
2. 查看队列信息
1 2 3 4 | # /usr/local/rabbitmq/sbin/rabbitmqctl list_queues name durable auto_delete messages consumers memory Listing queues... _queue truetrue107244 ...done. |
3. 查看绑定信息
1 2 3 4 5 | # /usr/local/rabbitmq/sbin/rabbitmqctl list_bindings Listing bindings... exchange _queue queue _queue[] _exchange exchange _queue queue _routingkey[] ...done. |
八. 日志轮转
1 | # /usr/local/rabbitmq/sbin/rabbitmqctl rotate_logs .1 |
发表评论
暂时没有评论,来抢沙发吧~