Quick Operation Guide
# 1. Deployment Architecture
# Overall Architecture
┌─────────────────────────────────────────────────────────────┐
│ 客户端层 │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────┐ │
│ │ 生产者应用 │ │ 消费者应用 │ │ 管控台/Web管理 │ │
│ └─────────────┘ └─────────────┘ └─────────────────────┘ │
└────────────────────────┬────────────────────────────────────┘
│ AMQP/MQTT/STOMP
┌────────────────────────▼────────────────────────────────────┐
│ 消息引擎层 │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ ADMQ for RabbitMQ 节点 │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌──────────────┐ │ │
│ │ │ 连接层 │ │ 交换机 │ │ 队列 │ │ │
│ │ │ Connection │ │ Exchange │ │ Queue │ │ │
│ │ └─────────────┘ └─────────────┘ └──────────────┘ │ │
│ │ │ │
│ │ ┌─────────────┐ ┌─────────────┐ ┌──────────────┐ │ │
│ │ │ 路由层 │ │ 镜像队列 │ │ 持久化存储 │ │ │
│ │ │ Router │ │Mirror Queue │ │ Mnesia/ETS │ │ │
│ │ └─────────────┘ └─────────────┘ └──────────────┘ │ │
│ └───────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
┌────────────────────────▼────────────────────────────────────┐
│ 集群通信层 │
│ ┌───────────────────────────────────────────────────────┐ │
│ │ Erlang Distribution 网络 │ │
│ │ (节点间元数据同步与心跳检测) │ │
│ └───────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Deployment Mode
| Deployment Mode | Nodes | Use Case | High Availability |
|---|---|---|---|
| Standalone | 1 node | Development/Testing | None |
| Standard Cluster | 2+ nodes | Production Environment | Metadata HA |
| Mirror Queue Cluster | 3+ nodes | Production Environment | Metadata + Data HA |
# 2. Quick Installation
# 2.1 Environment Preparation
| Component | Minimum Requirement | Recommended Configuration |
|---|---|---|
| CPU | 4 cores | 8 cores or more |
| Memory | 8 GB | 16 GB or more |
| Disk | 100 GB SSD | 500 GB or more SSD |
| OS | CentOS 7+, Ubuntu 18.04+, Kylin, UOS | - |
Port Requirements:
| Port | Purpose |
|---|---|
| 5672 | AMQP protocol |
| 15672 | Web management interface |
| 25672 | Cluster inter-node communication |
# 2.2 Standalone Installation
# Create directory
mkdir -p /apusic && cd /apusic
# Extract installation package
tar zxvf ADMQ-V2.0.6.xxx.tar.gz
cd admq-rabbitmq
# Place license.xml license file in the root directory
# Modify hostname (only letters, digits, and hyphens allowed)
hostname node1
# Start service
bin/admq-daemon start rabbitmq server
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 2.3 Cluster Installation (3 Nodes)
Execute on all nodes:
mkdir -p /apusic && cd /apusic
tar zxvf ADMQ-V2.0.6.xxx.tar.gz
cd admq-rabbitmq
# Place license.xml
# Modify hostname
hostname node171 # node172, node173
# Configure /etc/hosts
172.20.140.171 node171
172.20.140.172 node172
172.20.140.173 node173
# Start service
bin/admq-daemon start rabbitmq server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Execute cluster creation on Node 1:
bin/admq rabbitmq cluster add -s 172.20.140.172:58181 -u monitor -p apusic_123
bin/admq rabbitmq cluster add -s 172.20.140.173:58181 -u monitor -p apusic_123
1
2
2
Enable mirror queue (optional):
bin/admq rabbitmq admin ctl set_policy ha-all "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}'
1
# 3. Core Concepts
# Message Model
Producer -> Exchange -> [Binding/Routing Key] -> Queue -> Consumer
1
# Exchange Types
| Type | Routing Method | Use Case |
|---|---|---|
| Direct | Exact Routing Key match | Point-to-point messaging |
| Fanout | Broadcast to all queues | Broadcast notifications |
| Topic | Pattern matching * # | Log categorization, event routing |
| Headers | Match based on message headers | Complex conditional routing |
# Queue Types
| Type | Characteristics | Use Case |
|---|---|---|
| Classic Queue | Traditional queue, supports mirroring | General business scenarios |
| Quorum Queue | Raft-based, automatic multi-replica | High availability scenarios |
| Stream Queue | Append-only log, supports multiple reads | High throughput, logging scenarios |
# 4. Common Command Reference
# Service Management
# Start/Stop/Restart
bin/admq-daemon start rabbitmq server
bin/admq-daemon stop rabbitmq server
bin/admq-daemon restart rabbitmq server
# Application start/stop
bin/admq rabbitmq admin ctl start_app
bin/admq rabbitmq admin ctl stop_app
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Status Inspection
# Node status
bin/admq rabbitmq admin ctl status
# Cluster status
bin/admq rabbitmq admin ctl cluster_status
# Health check
bin/admq rabbitmq admin diagnostics health_check
# Memory usage
bin/admq rabbitmq admin diagnostics memory_breakdown
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# User Management
# Create user
bin/admq rabbitmq admin ctl add_user username password
bin/admq rabbitmq admin ctl set_user_tags username administrator
bin/admq rabbitmq admin ctl set_permissions -p /vhost username ".*" ".*" ".*"
# Change password
bin/admq rabbitmq admin ctl change_password username newpassword
# Delete user
bin/admq rabbitmq admin ctl delete_user username
# List users
bin/admq rabbitmq admin ctl list_users
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# Queue Management
# List queues
bin/admq rabbitmq admin ctl list_queues
bin/admq rabbitmq admin ctl list_queues name messages consumers
# List exchanges
bin/admq rabbitmq admin ctl list_exchanges name type
# List connections
bin/admq rabbitmq admin ctl list_connections peer_host state
# List channels
bin/admq rabbitmq admin ctl list_channels connection consumer_count
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# Cluster Management
# View cluster status
bin/admq rabbitmq admin ctl cluster_status
# View queue details (including mirror)
bin/admq rabbitmq admin ctl list_queues name pid slave_pids synchronised_slave_pids
# Remove failed node
bin/admq rabbitmq admin ctl forget_cluster_node rabbit@node2
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Policy Management
# List policies
bin/admq rabbitmq admin ctl list_policies
# Set mirror policy
bin/admq rabbitmq admin ctl set_policy ha-all "^" '{"ha-mode":"all"}' --priority 0 --apply-to queues
# Clear policy
bin/admq rabbitmq admin ctl clear_policy ha-all
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# Backup and Restore
# Export configuration
bin/admq rabbitmq admin ctl export_definitions /backup/definitions.json
# Import configuration
bin/admq rabbitmq admin ctl import_definitions /backup/definitions.json
# Backup Mnesia
bin/admq rabbitmq admin ctl eval 'rabbit_mnesia:backup("/backup/mnesia.backup").'
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 5. Daily Operations
# Log Locations
| Log Type | Path |
|---|---|
| Service log | ./log/rabbitmq/rabbit@hostname.log |
| Startup log | ./log/rabbitmq/rabbit@hostname-sasl.log |
| Console log | ./logs/ |
# Daily Checklist
| Check Item | Command | Normal Standard |
|---|---|---|
| Node status | bin/admq rabbitmq admin ctl status | Running normally |
| Cluster status | bin/admq rabbitmq admin ctl cluster_status | All nodes online |
| Queue backlog | bin/admq rabbitmq admin ctl list_queues messages | No abnormal backlog |
| Memory usage | bin/admq rabbitmq admin ctl status | Below watermark |
| Disk space | df -h | Above disk_free_limit |
# Health Check Script
#!/bin/bash
# Node health check
bin/admq rabbitmq admin diagnostics health_check
# Memory check
bin/admq rabbitmq admin diagnostics memory_breakdown
# Alert queue check (messages > 10000)
bin/admq rabbitmq admin ctl list_queues name messages consumers | awk '$2 > 10000 {print "WARNING: Queue "$1" has "$2" messages"}'
# Connection count check
CONN_COUNT=$(bin/admq rabbitmq admin ctl list_connections | wc -l)
if [ $CONN_COUNT -gt 1000 ]; then
echo "WARNING: Connection count $CONN_COUNT exceeds threshold"
fi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 6. Configuration Optimization
# rabbitmq.conf Core Configuration
# Network
listeners.tcp.default = 5672
listeners.ssl.default = 5671
# Memory (recommended 0.6-0.7)
vm_memory_high_watermark.relative = 0.6
vm_memory_high_watermark_paging_ratio = 0.5
# Disk (recommended absolute value 1GB)
disk_free_limit.relative = 1.5
disk_free_limit.absolute = 1GB
# Connections
channel_max = 2047
heartbeat = 30
# Queues
queue_master_locator = min-masters
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# System Optimization
# File descriptors
ulimit -n 65535
# Kernel parameters (/etc/sysctl.conf)
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_reuse = 1
net.core.somaxconn = 65535
vm.swappiness = 10
# Disk scheduler
echo deadline > /sys/block/sda/queue/scheduler
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 7. Troubleshooting
# Service Won't Start
| Symptom | Possible Cause | Solution |
|---|---|---|
| Port occupied | 5672/15672 occupied | Stop the occupying process or change the port |
| Cookie mismatch | Cluster node Cookie mismatch | Synchronize .erlang.cookie |
| Insufficient memory | System memory insufficient | Increase memory or lower watermark |
| Insufficient disk | Below disk_free_limit | Clean up disk or adjust limit |
# Message Consumption Anomalies
| Symptom | Possible Cause | Solution |
|---|---|---|
| Message backlog | Consumer too slow or offline | Add more consumers or optimize logic |
| Message loss | Persistence not enabled | Enable delivery_mode=2 |
| Duplicate consumption | Acknowledgement timeout | Optimize processing logic, acknowledge promptly |
# Cluster Anomalies
| Symptom | Possible Cause | Solution |
|---|---|---|
| Node offline | Network failure | Check network, restart service |
| Split-brain | Network partition | Use forget_cluster_node to clean up |
| Queue unavailable | Node offline | Use mirror queue or Quorum Queue |
# Diagnostic Commands
# View detailed information
bin/admq rabbitmq admin ctl status
bin/admq rabbitmq admin ctl cluster_status
bin/admq rabbitmq admin ctl list_connections peer_host peer_port state
bin/admq rabbitmq admin ctl list_queues name messages consumers memory
# View memory/processes
bin/admq rabbitmq admin diagnostics memory_breakdown
bin/admq rabbitmq admin diagnostics processes
bin/admq rabbitmq admin diagnostics connections
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 8. Security Hardening
# Change Default User
# Delete default guest user
bin/admq rabbitmq admin ctl delete_user guest
# Create new administrator
bin/admq rabbitmq admin ctl add_user admin strongpassword
bin/admq rabbitmq admin ctl set_user_tags admin administrator
bin/admq rabbitmq admin ctl set_permissions -p / admin ".*" ".*" ".*"
1
2
3
4
5
6
7
2
3
4
5
6
7
# Firewall Configuration
firewall-cmd --permanent --add-port=5672/tcp
firewall-cmd --permanent --add-port=15672/tcp
firewall-cmd --permanent --add-port=25672/tcp
firewall-cmd --reload
1
2
3
4
2
3
4
# SSL Configuration
listeners.ssl.default = 5671
ssl_options.cacertfile = /path/to/ca_certificate.pem
ssl_options.certfile = /path/to/server_certificate.pem
ssl_options.keyfile = /path/to/server_key.pem
ssl_options.verify = verify_peer
ssl_options.fail_if_no_peer_cert = false
1
2
3
4
5
6
2
3
4
5
6
# 9. Performance Optimization Tips
# Queue Optimization
Map<String, Object> args = new HashMap<>();
// Queue length limit
args.put("x-max-length", 100000);
args.put("x-max-length-bytes", 1073741824); // 1GB
// Message TTL
args.put("x-message-ttl", 3600000); // 1 hour
// Lazy queue (reduce memory)
args.put("x-queue-mode", "lazy");
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# Client Optimization
// Connection pool + automatic recovery
factory.setAutomaticRecoveryEnabled(true);
factory.setNetworkRecoveryInterval(5000);
// Single connection with multiple channels
Connection connection = factory.newConnection();
for (int i = 0; i < 10; i++) {
Channel channel = connection.createChannel();
}
// QoS prefetch
channel.basicQos(100);
// Batch acknowledgment
channel.basicAck(deliveryTag, true);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Monitoring Metrics
| Metric | Description |
|---|---|
| rabbitmq_connections | Number of connections |
| rabbitmq_queue_messages | Total message count |
| rabbitmq_node_mem_used | Memory usage |
| rabbitmq_node_disk_free | Available disk space |
# 10. Operations Best Practices
- Regular Checks: Establish routine inspection mechanisms
- Monitoring and Alerts: Configure a comprehensive monitoring and alerting system
- Backup Strategy: Regularly back up configurations and data
- Capacity Planning: Evaluate and scale up in advance
- Security Updates: Apply security patches in a timely manner
- Least Privilege: Assign minimum necessary permissions to business users
- Disaster Drills: Conduct regular failure recovery drills
Technical Support:
- Website: www.apusic.com
- Phone: 400-855-5800
- Email: support@apusic.com
编辑页面 (opens new window)